From a3235c49dab880ebcc04772d62ca55f0a9ff1c49 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 17 Sep 2023 23:06:01 +0200 Subject: [PATCH] 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. --- lib/xhprof/xhprof_html/callgraph.php | 1 + lib/xhprof/xhprof_html/index.php | 6 ++++++ lib/xhprof/xhprof_moodle.php | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/lib/xhprof/xhprof_html/callgraph.php b/lib/xhprof/xhprof_html/callgraph.php index 5076eab9ef5..a1415341974 100644 --- a/lib/xhprof/xhprof_html/callgraph.php +++ b/lib/xhprof/xhprof_html/callgraph.php @@ -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)) { diff --git a/lib/xhprof/xhprof_html/index.php b/lib/xhprof/xhprof_html/index.php index 80e7821fe92..4d29234ee7f 100644 --- a/lib/xhprof/xhprof_html/index.php +++ b/lib/xhprof/xhprof_html/index.php @@ -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, diff --git a/lib/xhprof/xhprof_moodle.php b/lib/xhprof/xhprof_moodle.php index 5e5bc124d05..86c63a6d526 100644 --- a/lib/xhprof/xhprof_moodle.php +++ b/lib/xhprof/xhprof_moodle.php @@ -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) {