diff --git a/src/Profiler.php b/src/Profiler.php index cea49ac..04e6dbb 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,12 +64,18 @@ public function setLogLevel($logLevel) return $this; } + public function setThreshold($threshold) + { + $this->threshold = (int) $threshold; + return $this; + } + /** * @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) : []; } @@ -74,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; @@ -82,9 +93,19 @@ 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; } + 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 */