-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Show render metrics for cached elements
This change will add the rendertime and sql querycount to the details when inspecting fusion object with a caching configuration.
- Loading branch information
Showing
4 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace t3n\Neos\Debug\Aspect; | ||
|
||
/** | ||
* This file is part of the t3n.Neos.Debugger package. | ||
* | ||
* (c) 2019 yeebase media GmbH | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Aop\JoinPointInterface; | ||
use t3n\Neos\Debug\Service\RenderTimer; | ||
|
||
/** | ||
* @Flow\Aspect | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class RuntimeTracingAspect | ||
{ | ||
/** | ||
* @Flow\Inject | ||
* | ||
* @var RenderTimer | ||
*/ | ||
protected $renderTimer; | ||
|
||
/** | ||
* @Flow\Pointcut("setting(t3n.Neos.Debug.enabled)") | ||
*/ | ||
public function debuggingActive(): void | ||
{ | ||
} | ||
|
||
/** | ||
* @Flow\Before("method(Neos\Fusion\Core\Cache\RuntimeContentCache->enter()) && t3n\Neos\Debug\Aspect\RuntimeTracingAspect->debuggingActive") | ||
*/ | ||
public function onEnter(JoinPointInterface $joinPoint): void | ||
{ | ||
$configuration = $joinPoint->getMethodArgument('configuration'); | ||
$fusionPath = $joinPoint->getMethodArgument('fusionPath'); | ||
|
||
$cacheMode = $configuration['mode'] ?? null; | ||
|
||
if (! $cacheMode) { | ||
return; | ||
} | ||
|
||
$this->renderTimer->start($fusionPath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace t3n\Neos\Debug\Service; | ||
|
||
/** | ||
* This file is part of the t3n.Neos.Debugger package. | ||
* | ||
* (c) 2019 yeebase media GmbH | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Neos\Flow\Annotations as Flow; | ||
use t3n\Neos\Debug\Logging\DebugStack; | ||
|
||
/** | ||
* @Flow\Scope("singleton") | ||
*/ | ||
class RenderTimer | ||
{ | ||
/** | ||
* @Flow\Inject() | ||
* | ||
* @var EntityManagerInterface | ||
*/ | ||
protected $entityManager; | ||
|
||
/** | ||
* @var mixed[] | ||
*/ | ||
protected $renderMetrics = []; | ||
|
||
/** | ||
* Starts a render timer for a certain fusion path | ||
*/ | ||
public function start(string $fusionPath): void | ||
{ | ||
$sqlLoggingStack = $this->entityManager->getConfiguration()->getSQLLogger(); | ||
$queryCount = $sqlLoggingStack instanceof DebugStack ? $sqlLoggingStack->queryCount : 0; | ||
|
||
$this->renderMetrics[$fusionPath] = [ | ||
'startRenderAt' => $this->ts(), | ||
'sqlQueryCount' => $queryCount, | ||
]; | ||
} | ||
|
||
/** | ||
* Return current microtime in ms | ||
*/ | ||
private function ts(): float | ||
{ | ||
return microtime(true) * 1000; | ||
} | ||
|
||
/** | ||
* Stops the timer and returns the computed values | ||
* | ||
* @return mixed[]|null | ||
*/ | ||
public function stop(string $fusionPath): ?array | ||
{ | ||
if (! array_key_exists($fusionPath, $this->renderMetrics)) { | ||
return null; | ||
} | ||
|
||
$metrics = $this->renderMetrics[$fusionPath]; | ||
$sqlLoggingStack = $this->entityManager->getConfiguration()->getSQLLogger(); | ||
$queryCount = $sqlLoggingStack instanceof DebugStack ? $sqlLoggingStack->queryCount : 0; | ||
|
||
return [ | ||
'renderTime' => round($this->ts() - $metrics['startRenderAt'], 2) . ' ms', | ||
'sqlQueryCount' => $queryCount - $metrics['sqlQueryCount'], | ||
]; | ||
} | ||
} |