overwrite profiling methods to get a more accurate profiling
Cette révision appartient à :
Parent
55e5c6941d
révision
cef92d05b2
@ -16,9 +16,9 @@ declare(strict_types=1);
|
||||
namespace D3\DebugBar\Application\Component;
|
||||
|
||||
use D3\DebugBar\Application\Models\Collectors\SmartyCollector;
|
||||
use D3\DebugBar\Application\Models\TimeDataCollectorHandler;
|
||||
use DebugBar\Bridge\DoctrineCollector;
|
||||
use DebugBar\Bridge\MonologCollector;
|
||||
use DebugBar\DataCollector\TimeDataCollector;
|
||||
use DebugBar\DebugBarException;
|
||||
use DebugBar\JavascriptRenderer;
|
||||
use DebugBar\StandardDebugBar;
|
||||
@ -26,7 +26,6 @@ use Doctrine\DBAL\Logging\DebugStack;
|
||||
use OxidEsales\Eshop\Core\Controller\BaseController;
|
||||
use OxidEsales\Eshop\Core\DatabaseProvider;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
|
||||
use OxidEsales\Eshop\Core\Exception\StandardException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
@ -34,9 +33,9 @@ use ReflectionException;
|
||||
class DebugBarComponent extends BaseController
|
||||
{
|
||||
/** @var StandardDebugBar */
|
||||
protected $debugBar;
|
||||
public $debugBar;
|
||||
/** @var JavascriptRenderer */
|
||||
protected $debugBarRenderer;
|
||||
public $debugBarRenderer;
|
||||
|
||||
/**
|
||||
* Marking object as component
|
||||
@ -137,22 +136,17 @@ class DebugBarComponent extends BaseController
|
||||
$debugbar->addCollector($this->getSmartyCollector());
|
||||
}
|
||||
|
||||
public function addTimelineMessures()
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function addTimelineMessures(): void
|
||||
{
|
||||
/** @var TimeDataCollector $tCollector */
|
||||
$tCollector = $this->debugBar['time'];
|
||||
$collectors = $this->debugBar->getCollectors();
|
||||
$collectors['time'] = TimeDataCollectorHandler::getInstance();
|
||||
|
||||
global $aStartTimes;
|
||||
global $aProfileTimes;
|
||||
global $executionCounts;
|
||||
foreach ($aProfileTimes as $label => $recordedTime) {
|
||||
for ($i = 0; $i < $executionCounts[$label]; $i++) {
|
||||
$tCollector->addMeasure(
|
||||
$label,
|
||||
$aStartTimes[$label],
|
||||
$aStartTimes[$label] + $aProfileTimes[$label] / $executionCounts[$label]
|
||||
);
|
||||
}
|
||||
}
|
||||
$reflection = new ReflectionClass($this->debugBar);
|
||||
$property = $reflection->getProperty('collectors');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($this->debugBar, $collectors);
|
||||
}
|
||||
}
|
35
Application/Models/TimeDataCollectorHandler.php
Fichier normal
35
Application/Models/TimeDataCollectorHandler.php
Fichier normal
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\DebugBar\Application\Models;
|
||||
|
||||
use DebugBar\DataCollector\TimeDataCollector;
|
||||
|
||||
class TimeDataCollectorHandler
|
||||
{
|
||||
/** @var TimeDataCollector */
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* @return TimeDataCollector
|
||||
*/
|
||||
public static function getInstance(): TimeDataCollector
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new TimeDataCollector();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
[{$smarty.block.parent}]
|
||||
|
||||
[{$debugBarRenderer->renderHead()}]
|
||||
[{$debugBarComponent->addTimelineMessures()}]
|
||||
[{$debugBarRenderer->render()}]
|
@ -20,17 +20,11 @@ use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
class ShopControl_DebugBar extends ShopControl_DebugBar_parent
|
||||
{
|
||||
/**
|
||||
* @param null $controllerKey
|
||||
* @param null $function
|
||||
* @param null $parameters
|
||||
* @param null $viewsChain
|
||||
*/
|
||||
public function start ($controllerKey = null, $function = null, $parameters = null, $viewsChain = null)
|
||||
public function __construct()
|
||||
{
|
||||
$this->_d3AddDebugBarComponent();
|
||||
|
||||
parent::start( $controllerKey, $function, $parameters, $viewsChain);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,4 +45,15 @@ class ShopControl_DebugBar extends ShopControl_DebugBar_parent
|
||||
Registry::getConfig()->setConfigParam('aUserComponentNames', $userComponentNames);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if (!isAdmin()) {
|
||||
/** @var DebugBarComponent $debugBarComponent */
|
||||
$debugBarComponent = Registry::getConfig()->getActiveView()->getComponent(DebugBarComponent::class);
|
||||
echo $debugBarComponent->debugBarRenderer->renderHead();
|
||||
$debugBarComponent->addTimelineMessures();
|
||||
echo $debugBarComponent->debugBarRenderer->render();
|
||||
}
|
||||
}
|
||||
}
|
57
Modules/functions.php
Fichier normal
57
Modules/functions.php
Fichier normal
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
function startProfile($sProfileName)
|
||||
{
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
$trace[0] = $sProfileName;
|
||||
$hash = md5(serialize($trace)).'-'.$sProfileName;
|
||||
|
||||
$timeDataCollector = \D3\DebugBar\Application\Models\TimeDataCollectorHandler::getInstance();
|
||||
$timeDataCollector->startMeasure($hash, $sProfileName);
|
||||
|
||||
global $aStartTimes;
|
||||
global $executionCounts;
|
||||
if (!isset($executionCounts[$sProfileName])) {
|
||||
$executionCounts[$sProfileName] = 0;
|
||||
}
|
||||
if (!isset($aStartTimes[$sProfileName])) {
|
||||
$aStartTimes[$sProfileName] = 0;
|
||||
}
|
||||
$executionCounts[$sProfileName]++;
|
||||
$aStartTimes[$sProfileName] = microtime(true);
|
||||
}
|
||||
|
||||
function stopProfile($sProfileName)
|
||||
{
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
$trace[0] = $sProfileName;
|
||||
$hash = md5(serialize($trace)).'-'.$sProfileName;
|
||||
|
||||
$timeDataCollector = \D3\DebugBar\Application\Models\TimeDataCollectorHandler::getInstance();
|
||||
$timeDataCollector->stopMeasure($hash);
|
||||
|
||||
|
||||
global $aStartTimes;
|
||||
global $executionCounts;
|
||||
if (!isset($executionCounts[$sProfileName])) {
|
||||
$executionCounts[$sProfileName] = 0;
|
||||
}
|
||||
if (!isset($aStartTimes[$sProfileName])) {
|
||||
$aStartTimes[$sProfileName] = 0;
|
||||
}
|
||||
$executionCounts[$sProfileName]++;
|
||||
$aStartTimes[$sProfileName] = microtime(true);
|
||||
}
|
@ -38,6 +38,10 @@ php composer require d3/modulename:^2.0
|
||||
|
||||
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".
|
||||
|
||||
```
|
||||
include './modules/d3/debugbar/Modules/functions.php';
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
Siehe [CHANGELOG](CHANGELOG.md) für weitere Informationen.
|
||||
|
@ -42,11 +42,5 @@ $aModule = [
|
||||
'events' => [],
|
||||
'templates' => [],
|
||||
'settings' => [],
|
||||
'blocks' => [
|
||||
[
|
||||
'template' => 'layout/footer.tpl',
|
||||
'block' => 'footer_main',
|
||||
'file' => 'Application/views/blocks/layout/footer_main_debugbar.tpl'
|
||||
]
|
||||
],
|
||||
'blocks' => [],
|
||||
];
|
||||
|
Chargement…
Référencer dans un nouveau ticket
Block a user