2022-08-01 01:24:44 +02:00
|
|
|
<?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);
|
|
|
|
|
2022-08-03 00:32:09 +02:00
|
|
|
use D3\DebugBar\Application\Component\DebugBarComponent;
|
2022-08-02 12:07:26 +02:00
|
|
|
use D3\DebugBar\Application\Models\TimeDataCollectorHandler;
|
2022-08-03 00:32:09 +02:00
|
|
|
use DebugBar\DataCollector\MessagesCollector;
|
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
2022-08-02 12:07:26 +02:00
|
|
|
|
2022-08-01 01:24:44 +02:00
|
|
|
function startProfile($sProfileName)
|
|
|
|
{
|
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
|
|
|
$trace[0] = $sProfileName;
|
|
|
|
$hash = md5(serialize($trace)).'-'.$sProfileName;
|
|
|
|
|
2022-08-02 12:07:26 +02:00
|
|
|
$timeDataCollector = TimeDataCollectorHandler::getInstance();
|
2022-08-01 01:24:44 +02:00
|
|
|
$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;
|
|
|
|
|
2022-08-02 12:07:26 +02:00
|
|
|
$timeDataCollector = TimeDataCollectorHandler::getInstance();
|
2022-08-01 01:24:44 +02:00
|
|
|
$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);
|
2022-08-03 00:32:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function debugVar($mVar, $blToFile = false)
|
|
|
|
{
|
|
|
|
if ($blToFile) {
|
|
|
|
$out = var_export($mVar, true);
|
|
|
|
$f = fopen(Registry::getConfig()->getConfigParam('sCompileDir') . "/vardump.txt", "a");
|
|
|
|
fwrite($f, $out);
|
|
|
|
fclose($f);
|
|
|
|
} else {
|
|
|
|
if (!isAdmin()) {
|
|
|
|
$activeView = Registry::getConfig()->getTopActiveView();
|
|
|
|
/** @var DebugBarComponent $debugBarComponent */
|
|
|
|
$debugBarComponent = $activeView->getComponent(DebugBarComponent::class);
|
|
|
|
/** @var MessagesCollector $messages */
|
|
|
|
$messages = $debugBarComponent->getDebugBar()->getCollector('messages');
|
|
|
|
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
|
|
|
//$location = $trace[1]['class'] . '::' . $trace[1]['function']. '(' . $trace[0]['line'] . ')';
|
|
|
|
$location = $trace[1]['class'] . '::' . $trace[1]['function'];
|
|
|
|
$messages->addMessage($mVar, $location);
|
|
|
|
} else {
|
|
|
|
dumpVar($mVar, $blToFile);
|
|
|
|
}
|
|
|
|
}
|
2022-08-01 01:24:44 +02:00
|
|
|
}
|