Skip to content

Commit

Permalink
Merge pull request #149 from t3n/bugfix/server-timing-missing
Browse files Browse the repository at this point in the history
BUGFIX: Measure server timing again
  • Loading branch information
johannessteu authored May 16, 2021
2 parents 5c58a4e + 79a068c commit 0b7292c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions Classes/Http/Middleware/AddServerTimingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
}

$serverTiming = '';
$this->debugService->setStartRequestAt($request->getAttribute(MeasureServerTimingMiddleware::TIMING_ATTRIBUTE));
$metrics = $this->debugService->getMetrics();
foreach ($metrics as $key => ['value' => $value, 'description' => $description]) {
$serverTiming .= ($serverTiming ? ', ' : '') . $key;
Expand Down
9 changes: 6 additions & 3 deletions Classes/Http/Middleware/MeasureServerTimingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

class MeasureServerTimingMiddleware implements MiddlewareInterface
{
public const TIMING_ATTRIBUTE = 't3nNeosDebugTimingStart';

/**
* @Flow\InjectConfiguration(path="serverTimingHeader.enabled")
*
Expand All @@ -39,10 +41,11 @@ class MeasureServerTimingMiddleware implements MiddlewareInterface

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);

if ($this->enabled) {
$this->debugService->startRequestTimer();
$timerStart = $this->debugService->startRequestTimer();
$response = $handler->handle($request->withAttribute(self::TIMING_ATTRIBUTE, $timerStart));
} else {
$response = $handler->handle($request);
}

return $response;
Expand Down
16 changes: 12 additions & 4 deletions Classes/Service/DebugService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
class DebugService
{
/**
* @var int
* @var float
*/
protected $startRequestAt;

/**
* @var int
* @var float
*/
protected $stopRequestAt;

Expand All @@ -39,9 +39,17 @@ class DebugService
/**
* Starts the timer for the request process
*/
public function startRequestTimer(): void
public function startRequestTimer(): float
{
$this->startRequestAt = microtime(true) * 1000;
return $this->startRequestAt = microtime(true) * 1000;
}

/**
* Sets the starttime of the request
*/
public function setStartRequestAt(float $startRequestAt): void
{
$this->startRequestAt = $startRequestAt;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ Neos:
http:
middlewares:
t3n.Neos.Debug:MeasureServerTiming:
position: 'start'
position: 'start 999'
middleware: 't3n\Neos\Debug\Http\Middleware\MeasureServerTimingMiddleware'
t3n.Neos.Debug:AddServerTimingHeader:
position: 'after dispatch'
position: 'before dispatch 999'
middleware: 't3n\Neos\Debug\Http\Middleware\AddServerTimingMiddleware'

reflection:
Expand Down

0 comments on commit 0b7292c

Please sign in to comment.