From 10aaa568110a2b1036ad4204a9fd1e22e78f93de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20Pavlovi=C4=87?= Date: Thu, 24 Apr 2025 08:36:41 +0200 Subject: [PATCH] Add Tasker Profiler Output based on executionTime - introduced new Constant and modified getTaskerProfilerOutput --- src/Profiler.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Profiler.php b/src/Profiler.php index 96bac27..c423bcd 100644 --- a/src/Profiler.php +++ b/src/Profiler.php @@ -9,6 +9,7 @@ class Profiler const LOG_OFF = 0; const LOG_ERRORS_ONLY = 1; const LOG_ALWAYS = 2; + const LOG_ABOVE_THRESHOLD = 3; /** * @var array @@ -80,11 +81,15 @@ public function getProfilerOutput($httpCode, $dbProfiler = 0, $responseElapsedTi : []; } - public function getTaskerProfilerOutput($executionTime = 0, $dbProfiler = 2) + public function getTaskerProfilerOutput($taskStatus, $executionTime = 0) { - return $this->hasProfilers() && $this->shouldLogProfiler(200, $executionTime) - ? $this->getFormatted($dbProfiler, $executionTime) - : []; + if (!$this->hasProfilers()) { + return null; + } + if (!$this->shouldLogTaskerProfiler($taskStatus, $executionTime)) { + return null; + } + return $this->getFormatted(2, $executionTime); } public function getProfilerSummary() @@ -105,7 +110,6 @@ private function shouldLogProfiler($httpCode, $responseElapsedTime) if ($this->logLevel === self::LOG_ALWAYS) { return true; } - if ($this->isRequestTresholdExceded($responseElapsedTime)) { return true; } @@ -113,6 +117,23 @@ private function shouldLogProfiler($httpCode, $responseElapsedTime) return self::LOG_ERRORS_ONLY && substr($httpCode, 0, 1) != 2; } + private function shouldLogTaskerProfiler($taskStatus, $execTime) + { + if ($this->logLevel === self::LOG_OFF) { + return false; + } + if ($this->logLevel === self::LOG_ALWAYS) { + return true; + } + if ($this->logLevel === self::LOG_ABOVE_THRESHOLD + && $this->isRequestTresholdExceded($execTime) + ) { + return true; + } + + return self::LOG_ERRORS_ONLY && (int) $taskStatus != 2; + } + public function isRequestTresholdExceded($responseElapsedTime) { return $this->threshold && $responseElapsedTime > $this->threshold;