Commit 853df85e authored by martinlanghoff's avatar martinlanghoff
Browse files

Performance/footprint profiling patch complete -- is enabled by CFG->default>7...

Performance/footprint profiling patch complete -- is enabled by CFG->default>7 or by a few defines in your config.php.
parent a1e3bcf1
......@@ -214,6 +214,26 @@ $CFG->admin = 'admin';
// Enabling this will make most text-based filters only match the first time
// a phrase occurs in a given page. Otherwise all are matched.
// $CFG->filtermatchoneperpage = true;
//
// Performance profiling
//
// If you set Debug to "Yes" in the Configuration->Variables page some
// performance profiling data will show up on your footer (in default theme).
// With these settings you get more granular control over the capture
// and printout of the data
//
// Capture performance profiling data
// define('MDL_PERF' , true);
//
// Capture additional data from DB
// define('MDL_PERFDB' , true);
//
// Print to log (for passive profiling of production servers)
// define('MDL_PERFTOLOG' , true);
//
// Print to footer (works with the default theme)
// define('MDL_PERFTOFOOT', true);
//
//=========================================================================
// ALL DONE! To continue installation, visit your main page with a browser
......
......@@ -49,6 +49,8 @@ function execute_sql($command, $feedback=true) {
if (!$feedback) {
$db->debug = false;
}
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
$result = $db->Execute($command);
......@@ -372,6 +374,8 @@ function table_column($table, $oldfield, $field, $type='integer', $size='10',
function column_type($table, $column) {
global $CFG, $db;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
if(!$rs = $db->Execute('SELECT '.$column.' FROM '.$CFG->prefix.$table.' LIMIT 0')) {
return false;
}
......@@ -430,6 +434,8 @@ function record_exists_sql($sql) {
global $CFG, $db;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
if (!$rs = $db->Execute($sql)) {
if (isset($CFG->debug) and $CFG->debug > 7) {
notify($db->ErrorMsg().'<br /><br />'.$sql);
......@@ -510,6 +516,8 @@ function count_records_sql($sql) {
global $CFG, $db;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
$rs = $db->Execute($sql);
if (!$rs) {
if (isset($CFG->debug) and $CFG->debug > 7) {
......@@ -577,6 +585,8 @@ function get_record_sql($sql) {
$limit = ' LIMIT 1'; // Workaround - limit to one record
}
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
if (!$rs = $db->Execute($sql . $limit)) {
if (isset($CFG->debug) and $CFG->debug > 7) { // Debugging mode - print checks
notify( $db->ErrorMsg() . '<br /><br />'. $sql . $limit );
......@@ -759,6 +769,8 @@ function get_records_sql($sql) {
global $CFG, $db;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
if (!$rs = $db->Execute($sql)) {
if (isset($CFG->debug) and $CFG->debug > 7) {
notify($db->ErrorMsg() .'<br /><br />'. $sql);
......@@ -863,6 +875,9 @@ function get_records_sql_menu($sql) {
global $CFG, $db;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
if (!$rs = $db->Execute($sql)) {
if (isset($CFG->debug) and $CFG->debug > 7) {
notify($db->ErrorMsg() .'<br /><br />'. $sql);
......@@ -910,6 +925,8 @@ function get_field($table, $return, $field1, $value1, $field2='', $value2='', $f
}
}
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
$rs = $db->Execute('SELECT '. $return .' FROM '. $CFG->prefix . $table .' '. $select);
if (!$rs) {
if (isset($CFG->debug) and $CFG->debug > 7) {
......@@ -939,6 +956,8 @@ function get_field_sql($sql) {
global $db, $CFG;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
$rs = $db->Execute($sql);
if (!$rs) {
if (isset($CFG->debug) and $CFG->debug > 7) {
......@@ -973,6 +992,8 @@ function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $
global $db, $CFG;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
$select = 'WHERE '. $field1 .' = \''. $value1 .'\'';
if ($field2) {
......@@ -1004,6 +1025,8 @@ function delete_records($table, $field1='', $value1='', $field2='', $value2='',
global $db, $CFG;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
if ($field1) {
$select = 'WHERE '. $field1 .' = \''. $value1 .'\'';
if ($field2) {
......@@ -1033,6 +1056,8 @@ function delete_records_select($table, $select='') {
global $CFG, $db;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
if ($select) {
$select = 'WHERE '.$select;
}
......@@ -1057,6 +1082,8 @@ function insert_record($table, $dataobject, $returnid=true, $primarykey='id') {
global $db, $CFG;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
/// Execute a dummy query to get an empty recordset
if (!$rs = $db->Execute('SELECT * FROM '. $CFG->prefix . $table .' WHERE '. $primarykey .' = \'-1\'')) {
return false;
......@@ -1153,6 +1180,8 @@ function update_record($table, $dataobject) {
}
$data = (array)$dataobject;
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
// Pull out data matching these fields
foreach ($columns as $column) {
if ($column->name <> 'id' and isset($data[$column->name]) ) {
......@@ -2648,6 +2677,9 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user
$info = addslashes($info);
$url = html_entity_decode($url); // for php < 4.3.0 this is defined in moodlelib.php
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; $PERF->logwrites++;};
$result = $db->Execute('INSERT INTO '. $CFG->prefix .'log (time, userid, course, ip, module, cmid, action, url, info)
VALUES (' . "'$timenow', '$userid', '$courseid', '$REMOTE_ADDR', '$module', '$cm', '$action', '$url', '$info')");
......@@ -2658,6 +2690,7 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user
$db->Execute('UPDATE '. $CFG->prefix .'user SET lastIP=\''. $REMOTE_ADDR .'\', lastaccess=\''. $timenow .'\'
WHERE id = \''. $userid .'\' ');
if ($courseid != SITEID && !empty($courseid)) { // logins etc dont't have a courseid and isteacher will break without it.
if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++;};
if (isstudent($courseid)) {
$db->Execute('UPDATE '. $CFG->prefix .'user_students SET timeaccess = \''. $timenow .'\' '.
'WHERE course = \''. $courseid .'\' AND userid = \''. $userid .'\'');
......
......@@ -5682,7 +5682,7 @@ function get_performance_info() {
if (!empty($PERF->dbqueries)) {
$info['dbqueries'] = $PERF->dbqueries;
$info['html'] .= '<span class="dbqueries">DB queries'.$info['dbqueries'].'</span> ';
$info['html'] .= '<span class="dbqueries">DB queries '.$info['dbqueries'].'</span> ';
$info['txt'] .= 'dbqueries: '.$info['dbqueries'].' ';
}
......
......@@ -1835,10 +1835,12 @@ function print_footer($course=NULL, $usercourse=NULL) {
/// Provide some performance info if required
$performanceinfo = '';
if (!empty($CFG->perfdebug)) {
if (defined('MDL_PERF') || $CFG->debug > 7) {
$perf = get_performance_info();
error_log("PERF: " . $perf['txt']);
if ($CFG->debug > 7) {
if (defined('MDL_PERFTOLOG')) {
error_log("PERF: " . $perf['txt']);
}
if (defined('MDL_PERFTOFOOT') || $CFG->debug > 7) {
$performanceinfo = $perf['html'];
}
}
......
Supports Markdown
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