From c3f490f8aa4f353d82587898372f46780d6ae50f Mon Sep 17 00:00:00 2001 From: Uros Purtic Date: Fri, 9 Feb 2024 13:48:43 +0100 Subject: [PATCH 1/2] Add additional params to check if more data in response is needed --- src/Profiler.php | 16 ++++++++++++++++ src/RunnerAbstract.php | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/Profiler.php b/src/Profiler.php index cea49ac..349586a 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -30,6 +30,11 @@ class Profiler */ private $logLevel; + /** + * @var int + */ + private $threshold; + public function __construct() { $this->profilers = []; @@ -59,6 +64,12 @@ public function setLogLevel($logLevel) return $this; } + public function setThreshold($threshold) + { + $this->threshold = (int) $threshold; + return $this; + } + /** * @return array */ @@ -85,6 +96,11 @@ private function shouldLogProfiler($httpCode) return self::LOG_ERRORS_ONLY && substr($httpCode, 0, 1) != 2; } + public function shouldLogProfilerOutput($responseElapsedTimeInMs) + { + return $responseElapsedTimeInMs > $this->threshold; + } + /** * @return array */ diff --git a/src/RunnerAbstract.php b/src/RunnerAbstract.php index 95a9285..0ebfc5a 100644 --- a/src/RunnerAbstract.php +++ b/src/RunnerAbstract.php @@ -123,6 +123,12 @@ public function setProfilerLogLevel($profilerLogLevel) return $this; } + public function setProfilerLogThreshold($threshold) + { + $this->profiler->setThreshold($threshold); + return $this; + } + /** * @return Profiler */ From 1a76816eee2b1ed94dd3843a07c726ebe23e8371 Mon Sep 17 00:00:00 2001 From: Uros Purtic Date: Tue, 20 Feb 2024 13:14:38 +0100 Subject: [PATCH 2/2] Add additional params to check if more data in response is needed --- src/Profiler.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Profiler.php b/src/Profiler.php index 349586a..04e6dbb 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -73,9 +73,9 @@ public function setThreshold($threshold) /** * @return array */ - public function getProfilerOutput($httpCode, $dbProfiler = 0) + public function getProfilerOutput($httpCode, $dbProfiler = 0, $responseElapsedTime = 0) { - return $this->hasProfilers() && $this->shouldLogProfiler($httpCode) + return $this->hasProfilers() && $this->shouldLogProfiler($httpCode, $responseElapsedTime) ? $this->getFormatted($dbProfiler) : []; } @@ -85,7 +85,7 @@ public function getProfilerSummary() return (new ProfilerSummary($this->profilers))->getSummary(); } - private function shouldLogProfiler($httpCode) + private function shouldLogProfiler($httpCode, $responseElapsedTime) { if ($this->logLevel === self::LOG_OFF) { return false; @@ -93,6 +93,11 @@ private function shouldLogProfiler($httpCode) if ($this->logLevel === self::LOG_ALWAYS) { return true; } + + if($this->threshold && $responseElapsedTime > $this->threshold){ + return true; + } + return self::LOG_ERRORS_ONLY && substr($httpCode, 0, 1) != 2; }