Skip to content

Commit 7f240d4

Browse files
committed
ICL: Execution time, memory peak usage and separator added to the end of each iteration.
1 parent f642a71 commit 7f240d4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Log/ExceptionHandler.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
class ExceptionHandler extends Handler
99
{
10+
private $timeStarted;
11+
private $timeFinished;
1012
protected $reservedMemory;
1113

1214
public function __construct()
@@ -28,13 +30,20 @@ public function report(Exception $e)
2830

2931
private function registerShutdownFunction()
3032
{
33+
$this->timeStarted = microtime(true);
3134
$this->reservedMemory = str_repeat(' ', 20 * 1024);
3235

3336
register_shutdown_function(function () {
3437
$this->reservedMemory = null;
3538

36-
$this->log->info('Execution time: trash.');
37-
$this->log->info('Memory peak usage: trash.');
39+
$this->timeFinished = microtime(true);
40+
$executionTime = round($this->timeFinished - $this->timeStarted, 3);
41+
$this->log->info("Execution time: {$executionTime} sec.");
42+
43+
$memoryPeak = round(memory_get_peak_usage(true) / (1024 * 1024));
44+
$this->log->info("Memory peak usage: {$memoryPeak}M.");
45+
46+
$this->log->info('%separator%');
3847

3948
$handlers = $this->log->getHandlers();
4049
foreach ($handlers as $handler) {

src/Log/Formatter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ public function __construct()
1313

1414
public function format(array $record)
1515
{
16+
if ($record['message'] == '%separator%') {
17+
return str_repeat("\n", 11);
18+
}
19+
1620
$output = parent::format($record);
1721
return rtrim($output) . "\n";
1822
}

0 commit comments

Comments
 (0)