Beispiel #1
0
/**
 * LeonardoCA\Tools\ProcessMonitor::saves time interval shortcut.
 *
 * @param string $msg  message
 * @param mixed  $data - var, object to be dumped
 * @return void
 */
function pme($msg, $data = null)
{
    $backupMaxLength = Debugger::$maxLen;
    Debugger::$maxLen = 500;
    $backupMode = ProcessMonitor::$reportMode;
    ProcessMonitor::$reportMode = ProcessMonitor::SHOW_DETAIL;
    ProcessMonitor::addSummary($msg, $data);
    ProcessMonitor::$reportMode = $backupMode;
    Debugger::$maxLen = $backupMaxLength;
}
Beispiel #2
0
}
function storeData($fileInfo, &$memoryLeakData)
{
    // pm is shortcut for ProcessMonitor::dump()
    pm('some debug msg');
    usleep($fileInfo['time'] * 1000000 / 3);
    consumeMemory($fileInfo['size'] / 10, $memoryLeakData);
}
// end of fake demo specific code
// processMonitor extends Tracy\Debugger and mostly respects it's configuration
// therefore configure Debugger first
Debugger::detectDebugMode();
Debugger::enable();
Debugger::$maxDepth = 1;
// initialize ProcessMonitor
ProcessMonitor::$reportMode = ProcessMonitor::SHOW_DETAIL;
// ProcessMonitor::start is intended to be run only once
ProcessMonitor::start('some API import (this is only fake demo)');
$count = 0;
// this is how typical processing loop looks like
foreach ($filesList as $fileInfo) {
    // while debugging scripts which repeat some actions multiple times
    // reset process monitor timers in each loop
    pmr('some api call to import ' . $fileInfo['name']);
    // 1. step some api call
    runApiCallToGetXMLFile($fileInfo, $memoryLeakData);
    // pms is shortcut for ProcessMonitor::addSummary()
    // when processing can be split in several steps as in this case
    // it is very useful to track time and memory usage for each step separately
    // track api call time + download response time
    pms("get file {$fileInfo['name']} xml: " . ProcessMonitor::formatSize($fileInfo['size'] * 1000, ProcessMonitor::SIZE_AUTO) . " <a href='/examples/processMonitor.php?file={$fileInfo['name']}'>Run again &gt;&gt; </a>" . " <br/> see imported xml: <a href='/some_url/{$fileInfo['name']}' target='_blank'>" . $fileInfo['name'] . "</a>", null, 'time_api_call');