diff --git a/lib/xhprof/readme_moodle.txt b/lib/xhprof/readme_moodle.txt index 58c61f70a0e..058609b2145 100644 --- a/lib/xhprof/readme_moodle.txt +++ b/lib/xhprof/readme_moodle.txt @@ -41,4 +41,5 @@ TODO: 20171002 - MDL-60313 - Marina Glancy (marinaglancy): Upgrade to 0.9.4 release; patched for PHP7.2 20190314 - MDL-64543 - Brendan Heywood (brendanheywood): Add support for conditional slow profiling 20191016 - MDL-65349 - Brendan Heywood (brendanheywood): Improved url matching behaviour +20201012 - MDL-67081 - Brendan Heywood (brendanheywood): Support selective profiles from CLI diff --git a/lib/xhprof/xhprof_moodle.php b/lib/xhprof/xhprof_moodle.php index 9a3c6a2455c..cdfba73fc5a 100644 --- a/lib/xhprof/xhprof_moodle.php +++ b/lib/xhprof/xhprof_moodle.php @@ -103,18 +103,10 @@ function profiling_start() { $script = !empty($SCRIPT) ? $SCRIPT : profiling_get_script(); // Get PGC variables - $check = 'PROFILEME'; - $profileme = isset($_POST[$check]) || isset($_GET[$check]) || isset($_COOKIE[$check]) ? true : false; - $profileme = $profileme && !empty($CFG->profilingallowme); - $check = 'DONTPROFILEME'; - $dontprofileme = isset($_POST[$check]) || isset($_GET[$check]) || isset($_COOKIE[$check]) ? true : false; - $dontprofileme = $dontprofileme && !empty($CFG->profilingallowme); - $check = 'PROFILEALL'; - $profileall = isset($_POST[$check]) || isset($_GET[$check]) || isset($_COOKIE[$check]) ? true : false; - $profileall = $profileall && !empty($CFG->profilingallowall); - $check = 'PROFILEALLSTOP'; - $profileallstop = isset($_POST[$check]) || isset($_GET[$check]) || isset($_COOKIE[$check]) ? true : false; - $profileallstop = $profileallstop && !empty($CFG->profilingallowall); + $profileme = profiling_get_flag('PROFILEME') && !empty($CFG->profilingallowme); + $dontprofileme = profiling_get_flag('DONTPROFILEME') && !empty($CFG->profilingallowme); + $profileall = profiling_get_flag('PROFILEALL') && !empty($CFG->profilingallowall); + $profileallstop = profiling_get_flag('PROFILEALLSTOP') && !empty($CFG->profilingallowall); // DONTPROFILEME detected, nothing to start if ($dontprofileme) { @@ -189,6 +181,18 @@ function profiling_start() { return true; } +/** + * Check for profiling flags in all possible places + * @param string $flag name + * @return boolean + */ +function profiling_get_flag($flag) { + return !empty(getenv($flag)) || + isset($_COOKIE[$flag]) || + isset($_POST[$flag]) || + isset($_GET[$flag]); +} + /** * Stop profiling, gathering results and storing them */