Skip to content
Merged
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
31 changes: 26 additions & 5 deletions src/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -105,14 +110,30 @@ private function shouldLogProfiler($httpCode, $responseElapsedTime)
if ($this->logLevel === self::LOG_ALWAYS) {
return true;
}

if ($this->isRequestTresholdExceded($responseElapsedTime)) {
return true;
}

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;
Expand Down