From 3c25ccdcd17aa74c5e8cd9f4cd4c17c6b2b1a330 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 24 Jun 2023 10:05:05 +0200 Subject: [PATCH] MDL-78552 core: tidy up MDL_PERF constants * all constans usable in ABORT_AFTER_CONFIG should be always defined * MDL_PERFDB and $PERF->logwrites not used after legacy log removal * MDL_PERF_TEST should be documented in codebase * deprecated warnings in shutdowb manager --- cache/classes/loaders.php | 4 ++-- config-dist.php | 3 --- install.php | 4 ++++ lib/classes/lock/lock_config.php | 2 +- lib/classes/shutdown_manager.php | 10 +++++----- lib/classes/task/logging_trait.php | 2 +- lib/classes/task/logmanager.php | 2 +- lib/moodlelib.php | 8 +------- lib/outputrenderers.php | 4 ++-- lib/setup.php | 28 ++++++++++++++++------------ lib/setuplib.php | 1 - 11 files changed, 33 insertions(+), 35 deletions(-) diff --git a/cache/classes/loaders.php b/cache/classes/loaders.php index a8ebef37503..f0a12df383b 100644 --- a/cache/classes/loaders.php +++ b/cache/classes/loaders.php @@ -1703,7 +1703,7 @@ class cache_application extends cache implements cache_loader_with_locking { $after = microtime(true); if ($lock) { $this->locks[$key] = $lock; - if ((defined('MDL_PERF') && MDL_PERF) || $this->perfdebug) { + if (MDL_PERF || $this->perfdebug) { \core\lock\timing_wrapper_lock_factory::record_lock_data($after, $before, $this->get_definition()->get_id(), $key, $lock, $this->get_identifier() . $key); } @@ -1748,7 +1748,7 @@ class cache_application extends cache implements cache_loader_with_locking { } if ($released && array_key_exists($key, $this->locks)) { unset($this->locks[$key]); - if ((defined('MDL_PERF') && MDL_PERF) || $this->perfdebug) { + if (MDL_PERF || $this->perfdebug) { \core\lock\timing_wrapper_lock_factory::record_lock_released_data($this->get_identifier() . $key); } } diff --git a/config-dist.php b/config-dist.php index 2cee359e9f1..4f7447efe0a 100644 --- a/config-dist.php +++ b/config-dist.php @@ -422,9 +422,6 @@ $CFG->admin = 'admin'; // 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); // diff --git a/install.php b/install.php index 82c5e350b86..76a2b568a1c 100644 --- a/install.php +++ b/install.php @@ -49,6 +49,10 @@ define('CACHE_DISABLE_ALL', true); // Disables caching.. just in case. define('PHPUNIT_TEST', false); define('IGNORE_COMPONENT_CACHE', true); define('MDL_PERF_TEST', false); +define('MDL_PERF', false); +define('MDL_PERFTOFOOT', false); +define('MDL_PERFTOLOG', false); +define('MDL_PERFINC', false); // Servers should define a default timezone in php.ini, but if they don't then make sure something is defined. if (!function_exists('date_default_timezone_set') or !function_exists('date_default_timezone_get')) { diff --git a/lib/classes/lock/lock_config.php b/lib/classes/lock/lock_config.php index 30178089009..d51d2a4f74e 100644 --- a/lib/classes/lock/lock_config.php +++ b/lib/classes/lock/lock_config.php @@ -93,7 +93,7 @@ class lock_config { } // If tracking performance, insert a timing wrapper to keep track of lock delays. - if ((defined('MDL_PERF') && MDL_PERF) || (!empty($CFG->perfdebug) && $CFG->perfdebug > 7)) { + if (MDL_PERF || (!empty($CFG->perfdebug) && $CFG->perfdebug > 7)) { $wrapper = new timing_wrapper_lock_factory($type, $lockfactory); $lockfactory = $wrapper; } diff --git a/lib/classes/shutdown_manager.php b/lib/classes/shutdown_manager.php index 5f0aec5dcf6..c610f637701 100644 --- a/lib/classes/shutdown_manager.php +++ b/lib/classes/shutdown_manager.php @@ -208,15 +208,15 @@ class core_shutdown_manager { } // Deal with perf logging. - if ((defined('MDL_PERF') && MDL_PERF) || (!empty($CFG->perfdebug) && $CFG->perfdebug > 7)) { + if (MDL_PERF || (!empty($CFG->perfdebug) && $CFG->perfdebug > 7)) { if ($apachereleasemem) { error_log('Mem usage over '.$apachereleasemem.': marking Apache child for reaping.'); } - if (defined('MDL_PERFTOLOG') && MDL_PERFTOLOG) { + if (MDL_PERFTOLOG) { $perf = get_performance_info(); error_log("PERF: " . $perf['txt']); } - if (defined('MDL_PERFINC') && MDL_PERFINC) { + if (MDL_PERFINC) { $inc = get_included_files(); $ts = 0; foreach ($inc as $f) { @@ -224,9 +224,9 @@ class core_shutdown_manager { $fs = filesize($f); $ts += $fs; $hfs = display_size($fs); - error_log(substr($f, strlen($CFG->dirroot)) . " size: $fs ($hfs)", null, null, 0); + error_log(substr($f, strlen($CFG->dirroot)) . " size: $fs ($hfs)"); } else { - error_log($f , null, null, 0); + error_log($f); } } if ($ts > 0 ) { diff --git a/lib/classes/task/logging_trait.php b/lib/classes/task/logging_trait.php index 8701c2a5ae2..ef22ba9ba28 100644 --- a/lib/classes/task/logging_trait.php +++ b/lib/classes/task/logging_trait.php @@ -79,7 +79,7 @@ trait logging_trait { protected function log_start($message, $depth = 0) { $this->log($message, $depth); - if (defined('MDL_PERFTOLOG') && MDL_PERFTOLOG) { + if (MDL_PERFTOLOG) { $this->tracestats->$depth = [ 'mem' => memory_get_usage(), 'time' => microtime(), diff --git a/lib/classes/task/logmanager.php b/lib/classes/task/logmanager.php index 819ec44a588..b0efd994e91 100644 --- a/lib/classes/task/logmanager.php +++ b/lib/classes/task/logmanager.php @@ -301,7 +301,7 @@ class logmanager { self::$logpath, $failed, $DB->perf_get_reads() - self::$taskloginfo->dbread, - $DB->perf_get_writes() - self::$taskloginfo->dbwrite - $PERF->logwrites, + $DB->perf_get_writes() - self::$taskloginfo->dbwrite, self::$taskloginfo->timestart, microtime(true) ); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 44300f978a2..c4648935b95 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -9642,13 +9642,7 @@ function get_performance_info() { } } - if (!empty($PERF->logwrites)) { - $info['logwrites'] = $PERF->logwrites; - $info['html'] .= '
  • Log DB writes '.$info['logwrites'].'
  • '; - $info['txt'] .= 'logwrites: '.$info['logwrites'].' '; - } - - $info['dbqueries'] = $DB->perf_get_reads().'/'.($DB->perf_get_writes() - $PERF->logwrites); + $info['dbqueries'] = $DB->perf_get_reads().'/'.$DB->perf_get_writes(); $info['html'] .= '
  • DB reads/writes: '.$info['dbqueries'].'
  • '; $info['txt'] .= 'db reads/writes: '.$info['dbqueries'].' '; diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 39526b4022d..52461964b15 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -1511,9 +1511,9 @@ class core_renderer extends renderer_base { // Provide some performance info if required $performanceinfo = ''; - if ((defined('MDL_PERF') && MDL_PERF) || (!empty($CFG->perfdebug) && $CFG->perfdebug > 7)) { + if (MDL_PERF || (!empty($CFG->perfdebug) && $CFG->perfdebug > 7)) { $perf = get_performance_info(); - if ((defined('MDL_PERFTOFOOT') && MDL_PERFTOFOOT) || debugging() || $CFG->perfdebug > 7) { + if (MDL_PERFTOFOOT || debugging() || (!empty($CFG->perfdebug) && $CFG->perfdebug > 7)) { $performanceinfo = $perf['html']; } } diff --git a/lib/setup.php b/lib/setup.php index cbdef537b7e..4ca7a5bc360 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -281,21 +281,25 @@ if (!defined('PHPUNIT_TEST')) { define('PHPUNIT_TEST', false); } -// Performance tests needs to always display performance info, even in redirections. +// Performance tests needs to always display performance info, even in redirections; +// MDL_PERF_TEST is used in https://github.com/moodlehq/moodle-performance-comparison scripts. if (!defined('MDL_PERF_TEST')) { define('MDL_PERF_TEST', false); -} else { - // We force the ones we need. - if (!defined('MDL_PERF')) { - define('MDL_PERF', true); - } - if (!defined('MDL_PERFDB')) { - define('MDL_PERFDB', true); - } - if (!defined('MDL_PERFTOFOOT')) { - define('MDL_PERFTOFOOT', true); - } } +// Make sure all MDL_PERF* constants are always defined. +if (!defined('MDL_PERF')) { + define('MDL_PERF', MDL_PERF_TEST); +} +if (!defined('MDL_PERFTOFOOT')) { + define('MDL_PERFTOFOOT', MDL_PERF_TEST); +} +if (!defined('MDL_PERFTOLOG')) { + define('MDL_PERFTOLOG', false); +} +if (!defined('MDL_PERFINC')) { + define('MDL_PERFINC', false); +} +// Note that PHPUnit and Behat tests should pass with both MDL_PERF true and false. // When set to true MUC (Moodle caching) will be disabled as much as possible. // A special cache factory will be used to handle this situation and will use special "disabled" equivalents objects. diff --git a/lib/setuplib.php b/lib/setuplib.php index d87dc9dd457..8417df62d36 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -1195,7 +1195,6 @@ function init_performance_info() { global $PERF, $CFG, $USER; $PERF = new stdClass(); - $PERF->logwrites = 0; if (function_exists('microtime')) { $PERF->starttime = microtime(); }