Skip to content

Commit 71bc684

Browse files
committed
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.
1 parent 8ef2974 commit 71bc684

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/xhprof/xhprof_html/callgraph.php

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
// Start moodle modification: use own XHProfRuns implementation.
9191
// $xhprof_runs_impl = new XHProfRuns_Default();
9292
$xhprof_runs_impl = new moodle_xhprofrun();
93+
$xhprof_runs_impl->set_reducedata(xhprof_get_bool_param('reducedata', 1)); // Reduce data by default.
9394
// End moodle modification.
9495

9596
if (!empty($run)) {

lib/xhprof/xhprof_html/index.php

+6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@
9292
// Start moodle modification: use own XHProfRuns implementation.
9393
// $xhprof_runs_impl = new XHProfRuns_Default();
9494
$xhprof_runs_impl = new moodle_xhprofrun();
95+
$reducedata = xhprof_get_bool_param('reducedata', 0); // Don't reduce data by default.
96+
$xhprof_runs_impl->set_reducedata($reducedata);
97+
if ($reducedata) {
98+
// We need to inject it, so we continue in "reduced data mode" all the time.
99+
$params['reducedata'] = $reducedata;
100+
}
95101
// End moodle modification.
96102

97103
displayXHProfReport($xhprof_runs_impl, $params, $source, $run, $wts,

lib/xhprof/xhprof_moodle.php

+16
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,9 @@ class moodle_xhprofrun implements iXHProfRuns {
859859
protected $totalmemory = 0;
860860
protected $timecreated = 0;
861861

862+
/** @var bool Decide if we want to reduce profiling data or no */
863+
protected bool $reducedata = false;
864+
862865
public function __construct() {
863866
$this->timecreated = time();
864867
}
@@ -889,6 +892,10 @@ public function get_run($run_id, $type, &$run_desc) {
889892
return unserialize(base64_decode($rec->data));
890893
} else {
891894
$info = unserialize(gzuncompress(base64_decode($rec->data)));
895+
if (!$this->reducedata) {
896+
// We want to return the full data.
897+
return $info;
898+
}
892899

893900
// We want to apply some transformations here, in order to reduce
894901
// the information for some complex (too many levels) cases.
@@ -967,6 +974,15 @@ public function prepare_run($url) {
967974
$this->url = $url;
968975
}
969976

977+
/**
978+
* Enable or disable reducing profiling data.
979+
*
980+
* @param bool $reducedata Decide if we want to reduce profiling data (true) or no (false).
981+
*/
982+
public function set_reducedata(bool $reducedata): void {
983+
$this->reducedata = $reducedata;
984+
}
985+
970986
// Private API starts here.
971987

972988
protected function sum_calls($sum, $data) {

0 commit comments

Comments
 (0)