Exemplo n.º 1
0
/**
 * LeonardoCA\Tools\ProcessMonitor::reset cleans internal summary and timers
 *
 * @param string $msg
 * @return void
 */
function pmr($msg = 'PM reset')
{
    ProcessMonitor::reset($msg);
}
Exemplo n.º 2
0
    // 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');
    // 2. step - parsing xml response
    parseXMLFile($fileInfo, $memoryLeakData);
    // track time to validate and parse xml
    pms('parsed ' . $fileInfo['name'], $fileInfo, 'time_parse');
    // 3. step - preparing and storing data to db, etc
    storeData($fileInfo, $memoryLeakData);
    // track time to process and store the data
    pms('processed ' . $fileInfo['name'], $fileInfo, 'time_processed');
    // intentionally condition for always true in this example
    if ($error = true) {
        // pme is shortcut to output error messages
        // you may include whatever data useful for debugging
        // for more variables to dump use array
        pme("Error description", ['some useful data']);
    }
    $count++;
}
pmr("XML files processed: {$count}");
pmr('Total run time: ' . ProcessMonitor::formatTime(ProcessMonitor::getTotalTime()));
// this code should be called on application shutdown event in nette:
// $this->application->onShutdown[] = addJsAfterTheScriptIsDone();
addJsAfterTheScriptIsDone();