MDL-79285 xhprof: Add support for optional "reducedata" parameter

This new parameter / property will decide if we want to reduce
the run data before processing it:
- By default it will be disabled in table mode.
- By default it will be enabled in graph mode.
- The defaults can be changed by adding reducedata=[0|1] in the URLs
- Once data reduction is enabled, it stays enabled while
  navigating within the xhprof reports.
This commit is contained in:
Eloy Lafuente (stronk7) 2023-09-17 23:06:01 +02:00
parent c841064432
commit 68a2dd57ef
No known key found for this signature in database
GPG Key ID: 53487A05E6228820
3 changed files with 23 additions and 0 deletions

View File

@ -90,6 +90,7 @@ if (!array_key_exists($type, $xhprof_legal_image_types)) {
// Start moodle modification: use own XHProfRuns implementation.
// $xhprof_runs_impl = new XHProfRuns_Default();
$xhprof_runs_impl = new moodle_xhprofrun();
$xhprof_runs_impl->set_reducedata(xhprof_get_bool_param('reducedata', 1)); // Reduce data by default.
// End moodle modification.
if (!empty($run)) {

View File

@ -92,6 +92,12 @@ $vgbar = ' class="vgbar"';
// Start moodle modification: use own XHProfRuns implementation.
// $xhprof_runs_impl = new XHProfRuns_Default();
$xhprof_runs_impl = new moodle_xhprofrun();
$reducedata = xhprof_get_bool_param('reducedata', 0); // Don't reduce data by default.
$xhprof_runs_impl->set_reducedata($reducedata);
if ($reducedata) {
// We need to inject it, so we continue in "reduced data mode" all the time.
$params['reducedata'] = $reducedata;
}
// End moodle modification.
displayXHProfReport($xhprof_runs_impl, $params, $source, $run, $wts,

View File

@ -859,6 +859,9 @@ class moodle_xhprofrun implements iXHProfRuns {
protected $totalmemory = 0;
protected $timecreated = 0;
/** @var bool Decide if we want to reduce profiling data or no */
protected bool $reducedata = false;
public function __construct() {
$this->timecreated = time();
}
@ -889,6 +892,10 @@ class moodle_xhprofrun implements iXHProfRuns {
return unserialize(base64_decode($rec->data));
} else {
$info = unserialize(gzuncompress(base64_decode($rec->data)));
if (!$this->reducedata) {
// We want to return the full data.
return $info;
}
// We want to apply some transformations here, in order to reduce
// the information for some complex (too many levels) cases.
@ -967,6 +974,15 @@ class moodle_xhprofrun implements iXHProfRuns {
$this->url = $url;
}
/**
* Enable or disable reducing profiling data.
*
* @param bool $reducedata Decide if we want to reduce profiling data (true) or no (false).
*/
public function set_reducedata(bool $reducedata): void {
$this->reducedata = $reducedata;
}
// Private API starts here.
protected function sum_calls($sum, $data) {