From 36aa48719aa767b83cb4280adbf1d1f92edcd0c1 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 3 Feb 2011 16:14:09 +0100 Subject: [PATCH] MDL-26254 $CFG->perfdebug converted to boolean-like flag $CFG->perfdebug used values 15 (enabled) and 7 (disabled) since very early commits back in 2005. However, the value has always been considered as on/off switcher. The theoretical usage as a bitmask or level describing integer was never applied. While working on performance, I found a bug in filter manager. The code intuitively checks !empty($CFG->perfdebug) there. But this was actually buggy as it alway returned true even with perfdebug disabled. Such bugs are very likely so it was decided to convert perfdebug to nice boolean like flag. The patch fixes all places where $CFG->perfdebug is checked and includes one database update step. If users have the value defined in config.php, a warning is displayed so they know they are supposed to review their setting. AMOS BEGIN MOV [configperfdebug,core_admin],[perfdebug_desc,core_admin] AMOS END --- admin/settings/development.php | 2 +- lang/en/admin.php | 2 +- lib/db/upgrade.php | 19 +++++++++++++++++++ lib/moodlelib.php | 2 +- lib/outputrenderers.php | 4 ++-- lib/setuplib.php | 2 +- lib/weblib.php | 2 +- version.php | 2 +- 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/admin/settings/development.php b/admin/settings/development.php index 7de0346..1ab6aca 100644 --- a/admin/settings/development.php +++ b/admin/settings/development.php @@ -29,7 +29,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $temp->add(new admin_setting_configcheckbox('debugdisplay', get_string('debugdisplay', 'admin'), get_string('configdebugdisplay', 'admin'), ini_get_bool('display_errors'))); $temp->add(new admin_setting_configcheckbox('xmlstrictheaders', get_string('xmlstrictheaders', 'admin'), get_string('configxmlstrictheaders', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('debugsmtp', get_string('debugsmtp', 'admin'), get_string('configdebugsmtp', 'admin'), 0)); - $temp->add(new admin_setting_configcheckbox('perfdebug', get_string('perfdebug', 'admin'), get_string('configperfdebug', 'admin'), '7', '15', '7')); + $temp->add(new admin_setting_configcheckbox('perfdebug', get_string('perfdebug', 'admin'), get_string('perfdebug_desc', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('debugstringids', get_string('debugstringids', 'admin'), get_string('configdebugstringids', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('debugvalidators', get_string('debugvalidators', 'admin'), get_string('configdebugvalidators', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('debugpageinfo', get_string('debugpageinfo', 'admin'), get_string('configdebugpageinfo', 'admin'), 0)); diff --git a/lang/en/admin.php b/lang/en/admin.php index ce096ce..f97ea59 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -287,7 +287,6 @@ $string['configoverride'] = 'Defined in config.php'; $string['configpasswordpolicy'] = 'Turning this on will make Moodle check user passwords against a valid password policy. Use the settings below to specify your policy (they will be ignored if you set this to \'No\').'; $string['configpathtoclam'] = 'Path to clam AV. Probably something like /usr/bin/clamscan or /usr/bin/clamdscan. You need this in order for clam AV to run.'; $string['configpathtodu'] = 'Path to du. Probably something like /usr/bin/du. If you enter this, pages that display directory contents will run much faster for directories with a lot of files.'; -$string['configperfdebug'] = 'If you turn this on, performance info will be printed in the footer of the standard theme'; $string['configprofileroles'] = 'List of roles that are visible on user profiles and participation page.'; $string['configprofilesforenrolledusersonly'] = 'To prevent misuse by spammers, profile descriptions of users who are not yet enrolled in any course are hidden. New users must enrol in at least one course before they can add a profile description.'; $string['configprotectusernames'] = 'By default forget_password.php does not display any hints that would allow guessing of usernames or email addresses.'; @@ -779,6 +778,7 @@ $string['pathtopsqlinvalid'] = 'Invalid path to psql - either wrong path or not $string['pathtounzip'] = 'Path to unzip'; $string['pathtozip'] = 'Path to zip'; $string['perfdebug'] = 'Performance info'; +$string['perfdebug_desc'] = 'If you turn this on, performance info will be captured and printed in the footer of the page.'; $string['performance'] = 'Performance'; $string['pgcluster'] = 'PostgreSQL Cluster'; $string['pgclusterdescription'] = 'PostgreSQL version/cluster parameter for command line operations. If you only have one postgresql on your system or you are not sure what this is, leave this blank.'; diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 1be183d..ba778fb 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6005,6 +6005,25 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint(true, 2011012501); } + if ($oldversion < 2011020300) { + // fix the value of $CFG->perfdebug. It used 15 for enabled and 7 for disabled. + // converting to common boolean-like flag + + if (!empty($CFG->config_php_settings) and array_key_exists('perfdebug', $CFG->config_php_settings)) { + echo $OUTPUT->notification('You seem to have $CFG->perfdebug defined in your config.php. + Note that now valid values are either 1 (enabled) or 0 (disabled), + replacing legacy 15 (enabled) or 7 (disabled).', 'notifyproblem'); + } + + if (get_config('core', 'perfdebug') > 7) { + set_config('perfdebug', 1); + } else { + set_config('perfdebug', 0); + } + + upgrade_main_savepoint(true, 2011020300); + } + return true; } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index c59449a..a62a151 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -9001,7 +9001,7 @@ function moodle_request_shutdown() { } // deal with perf logging - if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { + if (defined('MDL_PERF') || !empty($CFG->perfdebug)) { if ($apachereleasemem) { error_log('Mem usage over '.$apachereleasemem.': marking Apache child for reaping.'); } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index bbcad53..5d6cd6e 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -667,12 +667,12 @@ class core_renderer extends renderer_base { // Provide some performance info if required $performanceinfo = ''; - if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { + if (defined('MDL_PERF') || !empty($CFG->perfdebug)) { $perf = get_performance_info(); if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { error_log("PERF: " . $perf['txt']); } - if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) { + if (defined('MDL_PERFTOFOOT') || debugging() || !empty($CFG->perfdebug)) { $performanceinfo = $perf['html']; } } diff --git a/lib/setuplib.php b/lib/setuplib.php index 46028a7..0915b8b 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -803,7 +803,7 @@ function init_performance_info() { } if (function_exists('apd_set_pprof_trace')) { // APD profiling - if ($USER->id > 0 && $CFG->perfdebug >= 15) { + if ($USER->id > 0 && !empty($CFG->perfdebug)) { $tempdir = $CFG->dataroot . '/temp/profile/' . $USER->id; mkdir($tempdir); apd_set_pprof_trace($tempdir); diff --git a/lib/weblib.php b/lib/weblib.php index 69b13a4..99a672a 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -2445,7 +2445,7 @@ function redirect($url, $message='', $delay=-1) { } } - if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) { + if (defined('MDL_PERF') || !empty($CFG->perfdebug)) { if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); diff --git a/version.php b/version.php index c355740..a838c85 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011020200; // YYYYMMDD = date of the last version bump +$version = 2011020300; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0.1+ (Build: 20110202)'; // Human-friendly version name -- 1.7.3.4