From bdca62ac6dc4e39c955d4cf77442f6ae47ee10f0 Mon Sep 17 00:00:00 2001 From: Russell Smith Date: Thu, 21 Jul 2016 09:57:18 +1000 Subject: [PATCH] MDL-55292 performance: Allow Tideways profiler extension. PHP7 doesn't have any default XHProf support and all other investigated forks don't have stable PHP7. Tideways is under active development and is easy to install. The data format is compatible with XHProf so it is a drop-in replacement in that way. --- admin/settings/development.php | 2 +- admin/tool/profiling/settings.php | 5 +++-- lib/xhprof/readme_moodle.txt | 1 + lib/xhprof/xhprof_moodle.php | 16 ++++++++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/admin/settings/development.php b/admin/settings/development.php index 41427f0690a..d0a6531173f 100644 --- a/admin/settings/development.php +++ b/admin/settings/development.php @@ -32,7 +32,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $ADMIN->add('development', $temp); // "Profiling" settingpage (conditionally if the 'xhprof' extension is available only). - $xhprofenabled = extension_loaded('xhprof') && function_exists('xhprof_enable'); + $xhprofenabled = extension_loaded('xhprof') || extension_loaded('tideways'); $temp = new admin_settingpage('profiling', new lang_string('profiling', 'admin'), 'moodle/site:config', !$xhprofenabled); // Main profiling switch. $temp->add(new admin_setting_configcheckbox('profilingenabled', new lang_string('profilingenabled', 'admin'), new lang_string('profilingenabled_help', 'admin'), false)); diff --git a/admin/tool/profiling/settings.php b/admin/tool/profiling/settings.php index 70bd8d7d7f5..c04d32b0577 100644 --- a/admin/tool/profiling/settings.php +++ b/admin/tool/profiling/settings.php @@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die; // profiling tool, added to development -if (extension_loaded('xhprof') && function_exists('xhprof_enable') && (!empty($CFG->profilingenabled) || !empty($CFG->earlyprofilingenabled))) { - $ADMIN->add('development', new admin_externalpage('toolprofiling', get_string('pluginname', 'tool_profiling'), "$CFG->wwwroot/$CFG->admin/tool/profiling/index.php", 'moodle/site:config')); +if ((extension_loaded('xhprof') || extension_loaded('tideways')) && (!empty($CFG->profilingenabled) || !empty($CFG->earlyprofilingenabled))) { + $ADMIN->add('development', new admin_externalpage('toolprofiling', get_string('pluginname', 'tool_profiling'), + "$CFG->wwwroot/$CFG->admin/tool/profiling/index.php", 'moodle/site:config')); } diff --git a/lib/xhprof/readme_moodle.txt b/lib/xhprof/readme_moodle.txt index b227f0598d2..c9b85f09e81 100644 --- a/lib/xhprof/readme_moodle.txt +++ b/lib/xhprof/readme_moodle.txt @@ -36,3 +36,4 @@ TODO: 20101122 - MDL-24600 - Eloy Lafuente (stronk7): Original import of 0.9.2 release 20110318 - MDL-26891 - Eloy Lafuente (stronk7): Implemented earlier profiling runs 20130621 - MDL-39733 - Eloy Lafuente (stronk7): Export & import of profiling runs +20160721 - MDL-55292 - Russell Smith (mr-russ): Add support for tideways profiler collection for PHP7 diff --git a/lib/xhprof/xhprof_moodle.php b/lib/xhprof/xhprof_moodle.php index b2f16fc2502..fb0794a719f 100644 --- a/lib/xhprof/xhprof_moodle.php +++ b/lib/xhprof/xhprof_moodle.php @@ -69,7 +69,7 @@ function profiling_start() { global $CFG, $SESSION, $SCRIPT; // If profiling isn't available, nothing to start - if (!extension_loaded('xhprof') || !function_exists('xhprof_enable')) { + if (!extension_loaded('xhprof') && !extension_loaded('tideways')) { return false; } @@ -146,7 +146,11 @@ function profiling_start() { // Arrived here, the script is going to be profiled, let's do it $ignore = array('call_user_func', 'call_user_func_array'); - xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY, array('ignored_functions' => $ignore)); + if (extension_loaded('tideways')) { + tideways_enable(TIDEWAYS_FLAGS_CPU + TIDEWAYS_FLAGS_MEMORY, array('ignored_functions' => $ignore)); + } else { + xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY, array('ignored_functions' => $ignore)); + } profiling_is_running(true); // Started, return true @@ -160,7 +164,7 @@ function profiling_stop() { global $CFG, $DB, $SCRIPT; // If profiling isn't available, nothing to stop - if (!extension_loaded('xhprof') || !function_exists('xhprof_enable')) { + if (!extension_loaded('xhprof') && !extension_loaded('tideways')) { return false; } @@ -179,7 +183,11 @@ function profiling_stop() { // Arrived here, profiling is running, stop and save everything profiling_is_running(false); - $data = xhprof_disable(); + if (extension_loaded('tideways')) { + $data = tideways_disable(); + } else { + $data = xhprof_disable(); + } // We only save the run after ensuring the DB table exists // (this prevents problems with profiling runs enabled in -- 2.43.0