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