Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions src/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Profiler
*/
private $logLevel;

/**
* @var int
*/
private $threshold;

public function __construct()
{
$this->profilers = [];
Expand Down Expand Up @@ -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)
: [];
}
Expand All @@ -74,17 +85,27 @@ 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;
}
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if you don't set a threshold value?

}

/**
* @return array
*/
Expand Down
6 changes: 6 additions & 0 deletions src/RunnerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public function setProfilerLogLevel($profilerLogLevel)
return $this;
}

public function setProfilerLogThreshold($threshold)
{
$this->profiler->setThreshold($threshold);
return $this;
}

/**
* @return Profiler
*/
Expand Down