Commit 91fac199 authored by Penny Leach's avatar Penny Leach
Browse files

differentiate between db reads and db writes, fixed a few small bugs

in perf
parent 5bebdc73
......@@ -31,6 +31,8 @@ $string['timeused'] = 'Execution time';
$string['seconds'] = 'seconds';
$string['included'] = 'Included files';
$string['dbqueries'] = 'DB queries';
$string['reads'] = 'reads';
$string['writes'] = 'writes';
$string['ticks'] = 'ticks';
$string['sys'] = 'sys';
$string['user'] = 'user';
......
......@@ -51,7 +51,13 @@ function execute_sql($command) {
try {
$result = $db->Execute($command);
increment_perf_db();
// searching for these rather than just select as subqueries may have select in them.
if (preg_match('/(update|insert|delete|alter|create)/i', $command)) {
increment_perf_db_writes();
}
else {
increment_perf_db_reads();
}
}
catch (ADODB_Exception $e) {
log_debug($e->getMessage() . "Command was: $command");
......@@ -366,10 +372,10 @@ function get_recordset_sql($sql, $values=null, $limitfrom=null, $limitnum=null)
if (!empty($values) && is_array($values) && count($values) > 0) {
$stmt = $db->Prepare($sql);
$rs = $db->Execute($stmt, $values);
increment_perf_db();
increment_perf_db_reads();
} else {
$rs = $db->Execute($sql);
increment_perf_db();
increment_perf_db_reads();
}
}
}
......@@ -775,7 +781,7 @@ function set_field_select($table, $newfield, $newvalue, $select, $values) {
$sql = 'UPDATE '. get_config('dbprefix') . $table .' SET '. $newfield .' = ? ' . $select;
try {
$stmt = $db->Prepare($sql);
increment_perf_db();
increment_perf_db_writes();
return $db->Execute($stmt, $values);
}
catch (ADODB_Exception $e) {
......@@ -811,7 +817,7 @@ function delete_records($table, $field1=null, $value1=null, $field2=null, $value
$sql = 'DELETE FROM '. get_config('dbprefix') . $table . ' ' . $select;
try {
$stmt = $db->Prepare($sql);
increment_perf_db();
increment_perf_db_writes();
return $db->Execute($stmt,$values);
}
catch (ADODB_Exception $e) {
......@@ -842,10 +848,10 @@ function delete_records_sql($sql, $values=null) {
$result = false;
if (!empty($values) && is_array($values) && count($values) > 0) {
$stmt = $db->Prepare($sql);
increment_perf_db();
increment_perf_db_writes();
$result = $db->Execute($stmt, $values);
} else {
increment_perf_db();
increment_perf_db_writes();
$result = $db->Execute($sql);
}
}
......@@ -925,7 +931,7 @@ function insert_record($table, $dataobject, $primarykey=false, $returnpk=false)
// Run the SQL statement
try {
$stmt = $db->Prepare($insertSQL);
increment_perf_db();
increment_perf_db_writes();
$rs = $db->Execute($stmt,$ddd);
}
catch (ADODB_Exception $e) {
......@@ -952,7 +958,7 @@ function insert_record($table, $dataobject, $primarykey=false, $returnpk=false)
// try to get the primary key based on id
try {
$oidsql = 'SELECT '. $primarykey .' FROM '. get_config('dbprefix') . $table .' WHERE oid = '. $id;
increment_perf_db();
increment_perf_db_reads();
$rs = $db->Execute($oidsql);
if ($rs->RecordCount() == 1) {
return (integer)$rs->fields[0];
......@@ -1081,7 +1087,7 @@ function update_record($table, $dataobject, $where=null) {
$sql = 'UPDATE '. get_config('dbprefix') . $table .' SET '. $update .' WHERE ' . $whereclause;
try {
$stmt = $db->Prepare($sql);
increment_perf_db();
increment_perf_db_writes();
$rs = $db->Execute($stmt,array_merge($values, $wherevalues));
return true;
}
......@@ -1178,7 +1184,7 @@ function where_values_prepared($value1=null, $value2=null, $value3=null, $value4
function column_type($table, $column) {
global $db;
increment_perf_db();
increment_perf_db_reads();
if(!$rs = $db->Execute('SELECT ' . $column.' FROM ' . get_config('dbprefix') . $table . ' WHERE 1=2')) {
return false;
}
......@@ -1280,7 +1286,7 @@ function db_format_tsfield($field, $as = null) {
function configure_dbconnection() {
global $db;
increment_perf_db();
increment_perf_db_writes();
$db->Execute("SET NAMES 'utf8'");
// more later..
......@@ -1370,12 +1376,19 @@ function create_sql_exception_message($e, $sql, $values) {
return $message;
}
function increment_perf_db() {
function increment_perf_db_reads() {
if (!get_config('perftolog') && !get_config('perftofoot')) {
return true;
}
global $PERF;
$PERF->dbqueries++;
$PERF->dbreads++;
}
function increment_perf_db_writes() {
if (!get_config('perftolog') && !get_config('perftofoot')) {
return true;
}
global $PERF;
$PERF->dbwrites++;
}
?>
......@@ -1476,8 +1476,13 @@ function get_performance_info() {
$inc = get_included_files();
$info['includecount'] = count($inc);
if (!empty($PERF->dbqueries)) {
$info['dbqueries'] = $PERF->dbqueries;
if (!empty($PERF->dbreads)) {
$info['dbreads'] = $PERF->dbreads;
}
if (!empty($PERF->dbwrites)) {
$info['dbwrites'] = $PERF->dbwrites;
}
if (function_exists('posix_times')) {
......
......@@ -8,12 +8,12 @@
{if $perf_includecount}
<span class="included">{str tag="included" section="performance"}: {$perf_includecount}</span><br />
{/if}
{if $perf_dbqueries}
<span class="dbqueries">{str tag="dbqueries" section="performance"}: {$perf_dbqueries}</span><br />
{if $perf_dbreads || $perf_dbwrites}
<span class="dbqueries">{str tag="dbqueries" section="performance"}: {$perf_dbreads} {str tag='reads' section='performance'}, {$perf_dbwrites} {str tag='writes' section='performance'}</span><br />
{/if}
{if $perf_ticks}
<span class="posixtimes">{str tag="ticks" section="performance"}: {$perf_ticks} {str tag="user" section="performance"}: {$perf_user}
{str tag="sys" section="performance"}: {$perf_sys} {str tag="cuser" section="performance"}: {$perf_cutime}
<span class="posixtimes">{str tag="ticks" section="performance"}: {$perf_ticks} {str tag="user" section="performance"}: {$perf_utime}
{str tag="sys" section="performance"}: {$perf_stime} {str tag="cuser" section="performance"}: {$perf_cutime}
{str tag="csys" section="performance"}: {$perf_cstime}</span><br />
{/if}
{if $perf_serverload}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment