From 05f6ed003400522b189fb1f4766cd9fcc9cd2fd5 Mon Sep 17 00:00:00 2001 From: Paul Greidanus Date: Thu, 2 Aug 2018 13:12:00 -0600 Subject: [PATCH] MDL-63031 administration: Allow plugins to define trace storage This will allow the use of other storage systems implemented in plugins. It also allows for disabling the built in DB based profiling, which will be useful when using an external target to not waste DB storage. --- config-dist.php | 6 ++++++ lib/xhprof/xhprof_moodle.php | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/config-dist.php b/config-dist.php index afb9c1c57e3..fa43382a2ca 100644 --- a/config-dist.php +++ b/config-dist.php @@ -380,6 +380,12 @@ $CFG->admin = 'admin'; // profilingallowme, profilingallowall, profilinglifetime // $CFG->earlyprofilingenabled = true; // +// Disable database storage for profile data. +// When using an exernal plugin to store profiling data it is often +// desirable to not store the data in the database. +// +// $CFG->disableprofilingtodatabase = true; +// // Force displayed usernames // A little hack to anonymise user names for all students. If you set these // then all non-teachers will always see these for every person. diff --git a/lib/xhprof/xhprof_moodle.php b/lib/xhprof/xhprof_moodle.php index c0d82a8987c..82a1d1a1af7 100644 --- a/lib/xhprof/xhprof_moodle.php +++ b/lib/xhprof/xhprof_moodle.php @@ -882,14 +882,29 @@ class moodle_xhprofrun implements iXHProfRuns { $rec = new stdClass(); $rec->runid = $this->runid; $rec->url = $this->url; - $rec->data = base64_encode(gzcompress(serialize($xhprof_data), 9)); $rec->totalexecutiontime = $this->totalexecutiontime; $rec->totalcputime = $this->totalcputime; $rec->totalcalls = $this->totalcalls; $rec->totalmemory = $this->totalmemory; $rec->timecreated = $this->timecreated; - $DB->insert_record('profiling', $rec); + // Send to database with compressed and endoded data. + if (empty($CFG->disableprofilingtodatabase)) { + $rec->data = base64_encode(gzcompress(serialize($xhprof_data), 9)); + $DB->insert_record('profiling', $rec); + } + + // Send raw data to plugins. + $rec->data = $xhprof_data; + + // Allow a plugin to take the trace data and process it. + if ($pluginsfunction = get_plugins_with_function('store_profiling_data')) { + foreach ($pluginsfunction as $plugintype => $plugins) { + foreach ($plugins as $pluginfunction) { + $pluginfunction($rec); + } + } + } if (PHPUNIT_TEST) { // Calculate export variables.