Skip to content
Permalink
Browse files

MDL-62280 xhprof: Support tideways_xhprof

  • Loading branch information...
andrewnicols committed May 1, 2018
1 parent cbbdd37 commit 9e3700abc3600c72c4afbf4dec873d3ed6a224d5
Showing with 32 additions and 7 deletions.
  1. +3 −1 admin/settings/development.php
  2. +6 −2 admin/tool/profiling/settings.php
  3. +23 −4 lib/xhprof/xhprof_moodle.php
@@ -28,7 +28,9 @@
$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));
@@ -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'));
}
@@ -63,14 +63,29 @@ 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
*/
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();

0 comments on commit 9e3700a

Please sign in to comment.
You can’t perform that action at this time.