Merge branch 'MDL-67081-profile-cli' of https://github.com/brendanheywood/moodle

This commit is contained in:
Jake Dallimore 2020-11-19 11:41:31 +08:00
commit 6603ee4853
2 changed files with 17 additions and 12 deletions

View File

@ -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

View File

@ -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
*/