diff --git a/admin/settings/development.php b/admin/settings/development.php index 80a804767df..acf681fc9a9 100644 --- a/admin/settings/development.php +++ b/admin/settings/development.php @@ -28,7 +28,9 @@ 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') || extension_loaded('tideways'); + $xhprofenabled = extension_loaded('tideways_xhprof'); + $xhprofenabled = $xhprofenabled || extension_loaded('tideways'); + $xhprofenabled = $xhprofenabled || extension_loaded('xhprof'); $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 c04d32b0577..2c9840bae6d 100644 --- a/admin/tool/profiling/settings.php +++ b/admin/tool/profiling/settings.php @@ -25,8 +25,12 @@ defined('MOODLE_INTERNAL') || die; -// profiling tool, added to development -if ((extension_loaded('xhprof') || extension_loaded('tideways')) && (!empty($CFG->profilingenabled) || !empty($CFG->earlyprofilingenabled))) { +// Profiling tool, added to development. +$hasextension = extension_loaded('tideways_xhprof'); +$hasextension = $hasextension || extension_loaded('tideways'); +$hasextension = $hasextension || extension_loaded('xhprof'); +$isenabled = !empty($CFG->profilingenabled) || !empty($CFG->earlyprofilingenabled); +if ($hasextension && $isenabled) { $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/xhprof_moodle.php b/lib/xhprof/xhprof_moodle.php index c930d4ff0e0..c0d82a8987c 100644 --- a/lib/xhprof/xhprof_moodle.php +++ b/lib/xhprof/xhprof_moodle.php @@ -63,6 +63,21 @@ function profiling_is_saved($value = null) { return $saved; } +/** + * Whether PHP profiling is available. + * + * This check ensures that one of the available PHP Profiling extensions is available. + * + * @return bool + */ +function profiling_available() { + $hasextension = extension_loaded('tideways_xhprof'); + $hasextension = $hasextension || extension_loaded('tideways'); + $hasextension = $hasextension || extension_loaded('xhprof'); + + return $hasextension; +} + /** * Start profiling observing all the configuration */ @@ -70,7 +85,7 @@ function profiling_start() { global $CFG, $SESSION, $SCRIPT; // If profiling isn't available, nothing to start - if (!extension_loaded('xhprof') && !extension_loaded('tideways')) { + if (!profiling_available()) { return false; } @@ -147,7 +162,9 @@ 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'); - if (extension_loaded('tideways')) { + if (extension_loaded('tideways_xhprof')) { + tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_CPU + TIDEWAYS_XHPROF_FLAGS_MEMORY); + } else 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)); @@ -165,7 +182,7 @@ function profiling_stop() { global $CFG, $DB, $SCRIPT; // If profiling isn't available, nothing to stop - if (!extension_loaded('xhprof') && !extension_loaded('tideways')) { + if (!profiling_available()) { return false; } @@ -184,7 +201,9 @@ function profiling_stop() { // Arrived here, profiling is running, stop and save everything profiling_is_running(false); - if (extension_loaded('tideways')) { + if (extension_loaded('tideways_xhprof')) { + $data = tideways_xhprof_disable(); + } else if (extension_loaded('tideways')) { $data = tideways_disable(); } else { $data = xhprof_disable();