Skip to content

Commit 086ae38

Browse files
authored
Merge pull request #11 from UrosPurtic/master
Add additional params to check if more data in response is needed
2 parents 32763f5 + 1a76816 commit 086ae38

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/Profiler.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class Profiler
3030
*/
3131
private $logLevel;
3232

33+
/**
34+
* @var int
35+
*/
36+
private $threshold;
37+
3338
public function __construct()
3439
{
3540
$this->profilers = [];
@@ -59,12 +64,18 @@ public function setLogLevel($logLevel)
5964
return $this;
6065
}
6166

67+
public function setThreshold($threshold)
68+
{
69+
$this->threshold = (int) $threshold;
70+
return $this;
71+
}
72+
6273
/**
6374
* @return array
6475
*/
65-
public function getProfilerOutput($httpCode, $dbProfiler = 0)
76+
public function getProfilerOutput($httpCode, $dbProfiler = 0, $responseElapsedTime = 0)
6677
{
67-
return $this->hasProfilers() && $this->shouldLogProfiler($httpCode)
78+
return $this->hasProfilers() && $this->shouldLogProfiler($httpCode, $responseElapsedTime)
6879
? $this->getFormatted($dbProfiler)
6980
: [];
7081
}
@@ -74,17 +85,27 @@ public function getProfilerSummary()
7485
return (new ProfilerSummary($this->profilers))->getSummary();
7586
}
7687

77-
private function shouldLogProfiler($httpCode)
88+
private function shouldLogProfiler($httpCode, $responseElapsedTime)
7889
{
7990
if ($this->logLevel === self::LOG_OFF) {
8091
return false;
8192
}
8293
if ($this->logLevel === self::LOG_ALWAYS) {
8394
return true;
8495
}
96+
97+
if($this->threshold && $responseElapsedTime > $this->threshold){
98+
return true;
99+
}
100+
85101
return self::LOG_ERRORS_ONLY && substr($httpCode, 0, 1) != 2;
86102
}
87103

104+
public function shouldLogProfilerOutput($responseElapsedTimeInMs)
105+
{
106+
return $responseElapsedTimeInMs > $this->threshold;
107+
}
108+
88109
/**
89110
* @return array
90111
*/

src/RunnerAbstract.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ public function setProfilerLogLevel($profilerLogLevel)
123123
return $this;
124124
}
125125

126+
public function setProfilerLogThreshold($threshold)
127+
{
128+
$this->profiler->setThreshold($threshold);
129+
return $this;
130+
}
131+
126132
/**
127133
* @return Profiler
128134
*/

0 commit comments

Comments
 (0)