mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-15273 basic read/write perf counter in moodle_database
This commit is contained in:
parent
45d4986761
commit
ab130a0b5f
9 changed files with 90 additions and 27 deletions
|
@ -110,17 +110,15 @@
|
||||||
if (function_exists($cron_function)) {
|
if (function_exists($cron_function)) {
|
||||||
mtrace("Processing module function $cron_function ...", '');
|
mtrace("Processing module function $cron_function ...", '');
|
||||||
$pre_dbqueries = null;
|
$pre_dbqueries = null;
|
||||||
if (!empty($PERF->dbqueries)) {
|
$pre_dbqueries = $DB->perf_get_reads();
|
||||||
$pre_dbqueries = $PERF->dbqueries;
|
|
||||||
$pre_time = microtime(1);
|
$pre_time = microtime(1);
|
||||||
}
|
|
||||||
if ($cron_function()) {
|
if ($cron_function()) {
|
||||||
if (!$DB->set_field("modules", "lastcron", $timenow, array("id"=>$mod->id))) {
|
if (!$DB->set_field("modules", "lastcron", $timenow, array("id"=>$mod->id))) {
|
||||||
mtrace("Error: could not update timestamp for $mod->fullname");
|
mtrace("Error: could not update timestamp for $mod->fullname");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($pre_dbqueries)) {
|
if (isset($pre_dbqueries)) {
|
||||||
mtrace("... used " . ($PERF->dbqueries - $pre_dbqueries) . " dbqueries");
|
mtrace("... used " . ($DB->perf_get_reads() - $pre_dbqueries) . " dbqueries");
|
||||||
mtrace("... used " . (microtime(1) - $pre_time) . " seconds");
|
mtrace("... used " . (microtime(1) - $pre_time) . " seconds");
|
||||||
}
|
}
|
||||||
/// Reset possible changes by modules to time_limit. MDL-11597
|
/// Reset possible changes by modules to time_limit. MDL-11597
|
||||||
|
@ -173,13 +171,11 @@
|
||||||
$cronfunction = 'report_'.$report.'_cron';
|
$cronfunction = 'report_'.$report.'_cron';
|
||||||
mtrace('Processing cron function for '.$report.'...', '');
|
mtrace('Processing cron function for '.$report.'...', '');
|
||||||
$pre_dbqueries = null;
|
$pre_dbqueries = null;
|
||||||
if (!empty($PERF->dbqueries)) {
|
$pre_dbqueries = $DB->perf_get_reads();
|
||||||
$pre_dbqueries = $PERF->dbqueries;
|
|
||||||
$pre_time = microtime(true);
|
$pre_time = microtime(true);
|
||||||
}
|
|
||||||
$cronfunction();
|
$cronfunction();
|
||||||
if (isset($pre_dbqueries)) {
|
if (isset($pre_dbqueries)) {
|
||||||
mtrace("... used " . ($PERF->dbqueries - $pre_dbqueries) . " dbqueries");
|
mtrace("... used " . ($DB->perf_get_reads() - $pre_dbqueries) . " dbqueries");
|
||||||
mtrace("... used " . round(microtime(true) - $pre_time, 2) . " seconds");
|
mtrace("... used " . round(microtime(true) - $pre_time, 2) . " seconds");
|
||||||
}
|
}
|
||||||
mtrace('done.');
|
mtrace('done.');
|
||||||
|
|
|
@ -95,12 +95,12 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
parent::dispose();
|
parent::dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: make all dblibraries return this info in a structured way (new server_info class or so, like database_column_info class)
|
|
||||||
/**
|
/**
|
||||||
* Returns database server info array
|
* Returns database server info array
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_server_info() {
|
public function get_server_info() {
|
||||||
|
//TODO: make all dblibraries return this info in a structured way (new server_info class or so, like database_column_info class)
|
||||||
return $this->adodb->ServerInfo();
|
return $this->adodb->ServerInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
* @return array of arrays
|
* @return array of arrays
|
||||||
*/
|
*/
|
||||||
public function get_indexes($table) {
|
public function get_indexes($table) {
|
||||||
|
$this->reads++;
|
||||||
if (!$indexes = $this->adodb->MetaIndexes($this->prefix.$table)) {
|
if (!$indexes = $this->adodb->MetaIndexes($this->prefix.$table)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -145,6 +146,7 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
return $this->columns[$table];
|
return $this->columns[$table];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->reads++;
|
||||||
if (!$columns = $this->adodb->MetaColumns($this->prefix.$table)) {
|
if (!$columns = $this->adodb->MetaColumns($this->prefix.$table)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -203,6 +205,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
* @return bool success
|
* @return bool success
|
||||||
*/
|
*/
|
||||||
public function change_database_structure($sql) {
|
public function change_database_structure($sql) {
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
if ($rs = $this->adodb->Execute($sql)) {
|
if ($rs = $this->adodb->Execute($sql)) {
|
||||||
$result = true;
|
$result = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -222,7 +226,6 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
* @return bool success
|
* @return bool success
|
||||||
*/
|
*/
|
||||||
public function execute($sql, array $params=null) {
|
public function execute($sql, array $params=null) {
|
||||||
|
|
||||||
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
||||||
|
|
||||||
if (strpos($sql, ';') !== false) {
|
if (strpos($sql, ';') !== false) {
|
||||||
|
@ -230,6 +233,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
if ($rs = $this->adodb->Execute($sql, $params)) {
|
if ($rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$result = true;
|
$result = true;
|
||||||
$rs->Close();
|
$rs->Close();
|
||||||
|
@ -240,7 +245,6 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: do we want the *_raw() functions being public? I see the benefits but... won't that cause problems. To decide.
|
|
||||||
/**
|
/**
|
||||||
* Insert new record into database, as fast as possible, no safety checks, lobs not supported.
|
* Insert new record into database, as fast as possible, no safety checks, lobs not supported.
|
||||||
* @param string $table name
|
* @param string $table name
|
||||||
|
@ -250,6 +254,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
* @return mixed success or new id
|
* @return mixed success or new id
|
||||||
*/
|
*/
|
||||||
public function insert_record_raw($table, $params, $returnid=true, $bulk=false) {
|
public function insert_record_raw($table, $params, $returnid=true, $bulk=false) {
|
||||||
|
//TODO: do we want the *_raw() functions being public? I see the benefits but... won't that cause problems. To decide.
|
||||||
|
|
||||||
if (!is_array($params)) {
|
if (!is_array($params)) {
|
||||||
$params = (array)$params;
|
$params = (array)$params;
|
||||||
}
|
}
|
||||||
|
@ -259,6 +265,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
$fields = implode(',', array_keys($params));
|
$fields = implode(',', array_keys($params));
|
||||||
$qms = array_fill(0, count($params), '?');
|
$qms = array_fill(0, count($params), '?');
|
||||||
$qms = implode(',', $qms);
|
$qms = implode(',', $qms);
|
||||||
|
@ -299,6 +307,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
$sets = array();
|
$sets = array();
|
||||||
foreach ($params as $field=>$value) {
|
foreach ($params as $field=>$value) {
|
||||||
$sets[] = "$field = ?";
|
$sets[] = "$field = ?";
|
||||||
|
@ -332,6 +342,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
|
|
||||||
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
$result = false;
|
$result = false;
|
||||||
if ($rs = $this->adodb->Execute($sql, $params)) {
|
if ($rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$result = true;
|
$result = true;
|
||||||
|
@ -359,6 +371,8 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
public function get_recordset_sql($sql, array $params=null, $limitfrom=0, $limitnum=0) {
|
public function get_recordset_sql($sql, array $params=null, $limitfrom=0, $limitnum=0) {
|
||||||
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
||||||
|
|
||||||
|
$this->reads++;
|
||||||
|
|
||||||
if ($limitfrom || $limitnum) {
|
if ($limitfrom || $limitnum) {
|
||||||
///Special case, 0 must be -1 for ADOdb
|
///Special case, 0 must be -1 for ADOdb
|
||||||
$limitfrom = empty($limitfrom) ? -1 : $limitfrom;
|
$limitfrom = empty($limitfrom) ? -1 : $limitfrom;
|
||||||
|
@ -394,6 +408,9 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
*/
|
*/
|
||||||
public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0) {
|
public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnum=0) {
|
||||||
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
||||||
|
|
||||||
|
$this->reads++;
|
||||||
|
|
||||||
if ($limitfrom || $limitnum) {
|
if ($limitfrom || $limitnum) {
|
||||||
///Special case, 0 must be -1 for ADOdb
|
///Special case, 0 must be -1 for ADOdb
|
||||||
$limitfrom = empty($limitfrom) ? -1 : $limitfrom;
|
$limitfrom = empty($limitfrom) ? -1 : $limitfrom;
|
||||||
|
@ -420,6 +437,9 @@ abstract class adodb_moodle_database extends moodle_database {
|
||||||
*/
|
*/
|
||||||
public function get_fieldset_sql($sql, array $params=null) {
|
public function get_fieldset_sql($sql, array $params=null) {
|
||||||
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
|
||||||
|
|
||||||
|
$this->reads++;
|
||||||
|
|
||||||
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$this->report_error($sql, $params);
|
$this->report_error($sql, $params);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -48,7 +48,16 @@ abstract class moodle_database {
|
||||||
*/
|
*/
|
||||||
protected $dboptions;
|
protected $dboptions;
|
||||||
|
|
||||||
// TODO: perf stuff goes here
|
/**
|
||||||
|
* The database reads (performance counter).
|
||||||
|
*/
|
||||||
|
protected $reads = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The database writes (performance counter).
|
||||||
|
*/
|
||||||
|
protected $writes = 0;
|
||||||
|
|
||||||
// TODO: do we really need record caching??
|
// TODO: do we really need record caching??
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1393,4 +1402,12 @@ abstract class moodle_database {
|
||||||
public function rollback_sql() {
|
public function rollback_sql() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function perf_get_reads() {
|
||||||
|
return $this->reads;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function perf_get_writes() {
|
||||||
|
return $this->writes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,6 +192,7 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($blobs as $key=>$value) {
|
foreach ($blobs as $key=>$value) {
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
|
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -223,6 +224,7 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
|
||||||
if ($column->meta_type == 'B') { /// If the column is a BLOB (IMAGE)
|
if ($column->meta_type == 'B') { /// If the column is a BLOB (IMAGE)
|
||||||
/// Update BLOB column and return
|
/// Update BLOB column and return
|
||||||
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
|
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
|
||||||
|
$this->writes++;
|
||||||
return $this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select);
|
return $this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,6 +245,8 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
$sql = "UPDATE {$this->prefix}$table SET $newfield WHERE $select";
|
$sql = "UPDATE {$this->prefix}$table SET $newfield WHERE $select";
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$this->report_error($sql, $params);
|
$this->report_error($sql, $params);
|
||||||
return false;
|
return false;
|
||||||
|
@ -309,6 +313,7 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
|
||||||
|
|
||||||
|
|
||||||
foreach ($blobs as $key=>$value) {
|
foreach ($blobs as $key=>$value) {
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id")) {
|
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
|
||||||
* @return bool true if db in unicode mode
|
* @return bool true if db in unicode mode
|
||||||
*/
|
*/
|
||||||
function setup_is_unicodedb() {
|
function setup_is_unicodedb() {
|
||||||
|
$this->reads++;
|
||||||
$rs = $this->adodb->Execute("SHOW LOCAL VARIABLES LIKE 'character_set_database'");
|
$rs = $this->adodb->Execute("SHOW LOCAL VARIABLES LIKE 'character_set_database'");
|
||||||
if ($rs && !$rs->EOF) {
|
if ($rs && !$rs->EOF) {
|
||||||
$records = $rs->GetAssoc(true);
|
$records = $rs->GetAssoc(true);
|
||||||
|
@ -111,8 +112,10 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
|
||||||
*/
|
*/
|
||||||
public function change_db_encoding() {
|
public function change_db_encoding() {
|
||||||
// try forcing utf8 collation, if mysql db and no tables present
|
// try forcing utf8 collation, if mysql db and no tables present
|
||||||
|
$this->reads++;
|
||||||
if (!$this->adodb->Metatables()) {
|
if (!$this->adodb->Metatables()) {
|
||||||
$SQL = 'ALTER DATABASE '.$this->dbname.' CHARACTER SET utf8';
|
$SQL = 'ALTER DATABASE '.$this->dbname.' CHARACTER SET utf8';
|
||||||
|
$this->writes++;
|
||||||
$this->adodb->Execute($SQL);
|
$this->adodb->Execute($SQL);
|
||||||
if ($this->setup_is_unicodedb()) {
|
if ($this->setup_is_unicodedb()) {
|
||||||
$this->configure_dbconnection();
|
$this->configure_dbconnection();
|
||||||
|
@ -242,6 +245,8 @@ class mysqli_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
$sql = "UPDATE {$this->prefix}$table SET $newfield $select";
|
$sql = "UPDATE {$this->prefix}$table SET $newfield $select";
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$this->report_error($sql, $params);
|
$this->report_error($sql, $params);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -107,6 +107,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
* @return bool true if db in unicode mode
|
* @return bool true if db in unicode mode
|
||||||
*/
|
*/
|
||||||
function setup_is_unicodedb() {
|
function setup_is_unicodedb() {
|
||||||
|
$this->reads++;
|
||||||
$rs = $this->adodb->Execute("SELECT parameter, value FROM nls_database_parameters where parameter = 'NLS_CHARACTERSET'");
|
$rs = $this->adodb->Execute("SELECT parameter, value FROM nls_database_parameters where parameter = 'NLS_CHARACTERSET'");
|
||||||
if ($rs && !$rs->EOF) {
|
if ($rs && !$rs->EOF) {
|
||||||
$encoding = $rs->fields['value'];
|
$encoding = $rs->fields['value'];
|
||||||
|
@ -182,7 +183,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
return " $fieldname IS NULL "; /// empties in nullable fields are stored as
|
return " $fieldname IS NULL "; /// empties in nullable fields are stored as
|
||||||
} else { /// NULLs
|
} else { /// NULLs
|
||||||
if ($textfield) {
|
if ($textfield) {
|
||||||
return " ".sql_compare_text($fieldname)." = ' ' "; /// oracle_dirty_hack inserts 1-whitespace
|
return " ".$this->sql_compare_text($fieldname)." = ' ' "; /// oracle_dirty_hack inserts 1-whitespace
|
||||||
} else { /// in NOT NULL varchar and text columns so
|
} else { /// in NOT NULL varchar and text columns so
|
||||||
return " $fieldname = ' ' "; /// we need to look for that in any situation
|
return " $fieldname = ' ' "; /// we need to look for that in any situation
|
||||||
}
|
}
|
||||||
|
@ -267,12 +268,14 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($blobs as $key=>$value) {
|
foreach ($blobs as $key=>$value) {
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
|
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($clobs as $key=>$value) {
|
foreach ($clobs as $key=>$value) {
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateClob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
|
if (!$this->adodb->UpdateClob($this->prefix.$table, $key, $value, "id = {$dataobject->id}")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -350,12 +353,14 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($blobs as $key=>$value) {
|
foreach ($blobs as $key=>$value) {
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id")) {
|
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($clobs as $key=>$value) {
|
foreach ($clobs as $key=>$value) {
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateClob($this->prefix.$table, $key, $value, "id = $id")) {
|
if (!$this->adodb->UpdateClob($this->prefix.$table, $key, $value, "id = $id")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -391,12 +396,14 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
if ($column->meta_type == 'B') { /// If the column is a BLOB
|
if ($column->meta_type == 'B') { /// If the column is a BLOB
|
||||||
/// Update BLOB column and return
|
/// Update BLOB column and return
|
||||||
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
|
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
|
||||||
|
$this->writes++;
|
||||||
return $this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select);
|
return $this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($column->meta_type == 'X' && strlen($newvalue) > 4000) { /// If the column is a CLOB with lenght > 4000
|
if ($column->meta_type == 'X' && strlen($newvalue) > 4000) { /// If the column is a CLOB with lenght > 4000
|
||||||
/// Update BLOB column and return
|
/// Update BLOB column and return
|
||||||
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
|
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
|
||||||
|
$this->writes++;
|
||||||
return $this->adodb->UpdateClob($this->prefix.$table, $newfield, $newvalue, $select);
|
return $this->adodb->UpdateClob($this->prefix.$table, $newfield, $newvalue, $select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,6 +424,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
$sql = "UPDATE {$this->prefix}$table SET $newfield WHERE $select";
|
$sql = "UPDATE {$this->prefix}$table SET $newfield WHERE $select";
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$this->report_error($sql, $params);
|
$this->report_error($sql, $params);
|
||||||
return false;
|
return false;
|
||||||
|
@ -442,6 +450,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
if ($returnid) {
|
if ($returnid) {
|
||||||
$dbman = $this->get_manager();
|
$dbman = $this->get_manager();
|
||||||
$xmldb_table = new xmldb_table($table);
|
$xmldb_table = new xmldb_table($table);
|
||||||
|
$this->reads++;
|
||||||
$seqname = $dbman->find_sequence_name($xmldb_table);
|
$seqname = $dbman->find_sequence_name($xmldb_table);
|
||||||
if (!$seqname) {
|
if (!$seqname) {
|
||||||
/// Fallback, seqname not found, something is wrong. Inform and use the alternative getNameForObject() method
|
/// Fallback, seqname not found, something is wrong. Inform and use the alternative getNameForObject() method
|
||||||
|
@ -449,6 +458,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
$generator->setPrefix($this->getPrefix());
|
$generator->setPrefix($this->getPrefix());
|
||||||
$seqname = $generator->getNameForObject($table, 'id', 'seq');
|
$seqname = $generator->getNameForObject($table, 'id', 'seq');
|
||||||
}
|
}
|
||||||
|
$this->reads++;
|
||||||
if ($nextval = $this->adodb->GenID($seqname)) {
|
if ($nextval = $this->adodb->GenID($seqname)) {
|
||||||
$params['id'] = (int)$nextval;
|
$params['id'] = (int)$nextval;
|
||||||
}
|
}
|
||||||
|
@ -478,6 +488,7 @@ class oci8po_adodb_moodle_database extends adodb_moodle_database {
|
||||||
|
|
||||||
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($qms)";
|
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($qms)";
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$this->report_error($sql, $params);
|
$this->report_error($sql, $params);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -105,6 +105,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
return $this->columns[$table];
|
return $this->columns[$table];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->reads++;
|
||||||
if (!$columns = $this->adodb->MetaColumns($this->prefix.$table)) {
|
if (!$columns = $this->adodb->MetaColumns($this->prefix.$table)) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
@ -139,6 +140,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
*/
|
*/
|
||||||
function setup_is_unicodedb() {
|
function setup_is_unicodedb() {
|
||||||
/// Get PostgreSQL server_encoding value
|
/// Get PostgreSQL server_encoding value
|
||||||
|
$this->reads++;
|
||||||
$rs = $this->adodb->Execute("SHOW server_encoding");
|
$rs = $this->adodb->Execute("SHOW server_encoding");
|
||||||
if ($rs && !$rs->EOF) {
|
if ($rs && !$rs->EOF) {
|
||||||
$encoding = $rs->fields['server_encoding'];
|
$encoding = $rs->fields['server_encoding'];
|
||||||
|
@ -170,6 +172,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
unset($params['id']);
|
unset($params['id']);
|
||||||
if ($returnid) {
|
if ($returnid) {
|
||||||
|
$this->reads++;
|
||||||
$seqname = "{$this->prefix}{$table}_id_seq";
|
$seqname = "{$this->prefix}{$table}_id_seq";
|
||||||
if ($nextval = $this->adodb->GenID($seqname)) {
|
if ($nextval = $this->adodb->GenID($seqname)) {
|
||||||
$params['id'] = (int)$nextval;
|
$params['id'] = (int)$nextval;
|
||||||
|
@ -186,6 +189,8 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
|
|
||||||
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($qms)";
|
$sql = "INSERT INTO {$this->prefix}$table ($fields) VALUES($qms)";
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$this->report_error($sql, $params);
|
$this->report_error($sql, $params);
|
||||||
return false;
|
return false;
|
||||||
|
@ -199,6 +204,8 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
|
|
||||||
$oid = $this->adodb->Insert_ID();
|
$oid = $this->adodb->Insert_ID();
|
||||||
|
|
||||||
|
$this->reads++;
|
||||||
|
|
||||||
// try to get the primary key based on id
|
// try to get the primary key based on id
|
||||||
$sql = "SELECT id FROM {$this->prefix}$table WHERE oid = $oid";
|
$sql = "SELECT id FROM {$this->prefix}$table WHERE oid = $oid";
|
||||||
if ( ($rs = $this->adodb->Execute($sql))
|
if ( ($rs = $this->adodb->Execute($sql))
|
||||||
|
@ -271,6 +278,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($blobs as $key=>$value) {
|
foreach ($blobs as $key=>$value) {
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id", 'BLOB')) { // adodb does not use bound parameters for blob updates :-(
|
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id", 'BLOB')) { // adodb does not use bound parameters for blob updates :-(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -340,6 +348,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($blobs as $key=>$value) {
|
foreach ($blobs as $key=>$value) {
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id", 'BLOB')) { // adodb does not use bound parameters for blob updates :-(
|
if (!$this->adodb->UpdateBlob($this->prefix.$table, $key, $value, "id = $id", 'BLOB')) { // adodb does not use bound parameters for blob updates :-(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -368,6 +377,7 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
if ($column->meta_type == 'B') {
|
if ($column->meta_type == 'B') {
|
||||||
/// update blobs and return
|
/// update blobs and return
|
||||||
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
|
$select = $this->emulate_bound_params($select, $params); // adodb does not use bound parameters for blob updates :-(
|
||||||
|
$this->writes++;
|
||||||
if (!$this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select, 'BLOB')) {
|
if (!$this->adodb->UpdateBlob($this->prefix.$table, $newfield, $newvalue, $select, 'BLOB')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -395,6 +405,8 @@ class postgres7_adodb_moodle_database extends adodb_moodle_database {
|
||||||
}
|
}
|
||||||
$sql = "UPDATE {$this->prefix}$table SET $newfield $select";
|
$sql = "UPDATE {$this->prefix}$table SET $newfield $select";
|
||||||
|
|
||||||
|
$this->writes++;
|
||||||
|
|
||||||
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
if (!$rs = $this->adodb->Execute($sql, $params)) {
|
||||||
$this->report_error($sql, $params);
|
$this->report_error($sql, $params);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -7539,7 +7539,7 @@ function array_is_nested($array) {
|
||||||
***
|
***
|
||||||
**/
|
**/
|
||||||
function get_performance_info() {
|
function get_performance_info() {
|
||||||
global $CFG, $PERF;
|
global $CFG, $PERF, $DB;
|
||||||
|
|
||||||
$info = array();
|
$info = array();
|
||||||
$info['html'] = ''; // holds userfriendly HTML representation
|
$info['html'] = ''; // holds userfriendly HTML representation
|
||||||
|
@ -7569,18 +7569,16 @@ function get_performance_info() {
|
||||||
$info['html'] .= '<span class="included">Included '.$info['includecount'].' files</span> ';
|
$info['html'] .= '<span class="included">Included '.$info['includecount'].' files</span> ';
|
||||||
$info['txt'] .= 'includecount: '.$info['includecount'].' ';
|
$info['txt'] .= 'includecount: '.$info['includecount'].' ';
|
||||||
|
|
||||||
if (!empty($PERF->dbqueries)) {
|
|
||||||
$info['dbqueries'] = $PERF->dbqueries;
|
|
||||||
$info['html'] .= '<span class="dbqueries">DB queries '.$info['dbqueries'].'</span> ';
|
|
||||||
$info['txt'] .= 'dbqueries: '.$info['dbqueries'].' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($PERF->logwrites)) {
|
if (!empty($PERF->logwrites)) {
|
||||||
$info['logwrites'] = $PERF->logwrites;
|
$info['logwrites'] = $PERF->logwrites;
|
||||||
$info['html'] .= '<span class="logwrites">Log writes '.$info['logwrites'].'</span> ';
|
$info['html'] .= '<span class="logwrites">Log DB writes '.$info['logwrites'].'</span> ';
|
||||||
$info['txt'] .= 'logwrites: '.$info['logwrites'].' ';
|
$info['txt'] .= 'logwrites: '.$info['logwrites'].' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$info['dbqueries'] = $DB->perf_get_reads().'/'.($DB->perf_get_writes() - $PERF->logwrites);
|
||||||
|
$info['html'] .= '<span class="dbqueries">DB reads/writes: '.$info['dbqueries'].'</span> ';
|
||||||
|
$info['txt'] .= 'db reads/writes: '.$info['dbqueries'].' ';
|
||||||
|
|
||||||
if (!empty($PERF->profiling) && $PERF->profiling) {
|
if (!empty($PERF->profiling) && $PERF->profiling) {
|
||||||
require_once($CFG->dirroot .'/lib/profilerlib.php');
|
require_once($CFG->dirroot .'/lib/profilerlib.php');
|
||||||
$info['html'] .= '<span class="profilinginfo">'.Profiler::get_profiling(array('-R')).'</span>';
|
$info['html'] .= '<span class="profilinginfo">'.Profiler::get_profiling(array('-R')).'</span>';
|
||||||
|
|
|
@ -69,8 +69,7 @@ function init_performance_info() {
|
||||||
|
|
||||||
global $PERF, $CFG, $USER;
|
global $PERF, $CFG, $USER;
|
||||||
|
|
||||||
$PERF = new Object;
|
$PERF = new object();
|
||||||
$PERF->dbqueries = 0;
|
|
||||||
$PERF->logwrites = 0;
|
$PERF->logwrites = 0;
|
||||||
if (function_exists('microtime')) {
|
if (function_exists('microtime')) {
|
||||||
$PERF->starttime = microtime();
|
$PERF->starttime = microtime();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue