From 02c653fc0580fab56c711d4836bb119a42f055b0 Mon Sep 17 00:00:00 2001 From: Sebastian Kurfuerst Date: Thu, 2 Feb 2017 10:17:19 +0100 Subject: [PATCH] FEATURE: allow to fetch number of DB queries --- .../PhpProfiler/Domain/Model/ProfilingRun.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Classes/Sandstorm/PhpProfiler/Domain/Model/ProfilingRun.php b/Classes/Sandstorm/PhpProfiler/Domain/Model/ProfilingRun.php index 9d74e12..c2591e0 100755 --- a/Classes/Sandstorm/PhpProfiler/Domain/Model/ProfilingRun.php +++ b/Classes/Sandstorm/PhpProfiler/Domain/Model/ProfilingRun.php @@ -469,6 +469,40 @@ public function getMemory() return $output; } + /** + * Get DB Queries. Returned is a sorted-by-time array + * where each array element is again an array with the following structure: + * + * 'time' => (float) Current time in seconds, with microtime precision; relative to $this->startTime + * 'dbQueryCount' => (int) Number of DB queries done so far. + * + * @return array + */ + public function getDbQueryCount() + { + $output = array(); + foreach ($this->timestamps as $t) { + $output[] = array( + 'time' => $t['time'], + 'dbQueryCount' => $t['dbQueryCount'] + ); + } + foreach ($this->timers as $tmp) { + foreach ($tmp as $t) { + $output[] = array( + 'time' => $t['time'], + 'dbQueryCount' => $t['dbQueryCount'] + ); + } + } + + // now, sort events by start time + usort($output, function ($a, $b) { + return (int)(1000 * $a['time'] - 1000 * $b['time']); + }); + return $output; + } + /** * Get the full XHProf Trace array *