Last active
September 28, 2020 08:08
-
-
Save hissy/2bd944a4a9797ce902853a33f61687a7 to your computer and use it in GitHub Desktop.
#concrete5 Visualize rendering time of each blocks with DebugBar
This file contains hidden or 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
<?php | |
/** | |
* First, install the debug bar package. @link: https://github.com/concrete5cojp/concrete5_debugbar | |
* Then, add these code in your application/bootstrap/app.php | |
*/ | |
if ($app->isInstalled()) { | |
$director = $app->make(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class); | |
$debugBar = $app->make(\Concrete\Core\Package\PackageService::class)->getByHandle('concrete5_debugbar'); | |
if (is_object($debugBar) && $debugBar->isPackageInstalled()) { | |
$director->addListener('on_block_load', static function ($event) use ($app) { | |
$bID = $event->getArgument('bID'); | |
$btHandle = $event->getArgument('btHandle'); | |
$app->make('debugbar/time')->startMeasure(sprintf('block_%d', $bID), sprintf('Rendering %s block (bID: %d)', $btHandle, $bID)); | |
}); | |
$director->addListener('on_block_output', static function ($event) use ($app) { | |
/** @var \Concrete\Core\Block\Block $b */ | |
$b = $event->getBlock(); | |
$bID = $b->getBlockID(); | |
$app->make('debugbar/time')->stopMeasure(sprintf('block_%d', $bID), [ | |
'arHandle' => $b->getAreaHandle(), | |
'cacheBlockOutput' => $b->cacheBlockOutput(), | |
]); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment