Skip to content

Commit 12bae2d

Browse files
authored
Display memory usage
Since the Laravel documentation does not provide how to check for memory leaks, many developers will opt in to use the Laravel debug bar but i found out that the debug bar it has a memory leak, so displaying the memory usage as well as the duration will help to easy spot, memory leaks without external tools.
1 parent b39021d commit 12bae2d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Commands/Concerns/InteractsWithIO.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ public function requestInfo($request, $verbosity = null)
9595

9696
$url = parse_url($request['url'], PHP_URL_PATH) ?: '/';
9797

98+
$memory = number_format(round(memory_get_usage()/1024/1204, 2), 2, '.', '');
99+
98100
$duration = number_format(round($request['duration'], 2), 2, '.', '');
99101

100102
['method' => $method, 'statusCode' => $statusCode] = $request;
101103

102-
$dots = str_repeat('.', max($terminalWidth - strlen($method.$url.$duration) - 16, 0));
104+
$dots = str_repeat('.', max($terminalWidth - strlen($method.$url.$duration.$memory ) - 19, 0));
103105

104106
if (empty($dots) && ! $this->output->isVerbose()) {
105107
$url = substr($url, 0, $terminalWidth - strlen($method.$duration) - 15 - 3).'...';
@@ -108,7 +110,7 @@ public function requestInfo($request, $verbosity = null)
108110
}
109111

110112
$this->output->writeln(sprintf(
111-
' <fg=%s;options=bold>%s </> <fg=cyan;options=bold>%s</> <options=bold>%s</><fg=#6C7280> %s%s ms</>',
113+
' <fg=%s;options=bold>%s </> <fg=cyan;options=bold>%s</> <options=bold>%s</><fg=#6C7280> %s%s mb %s ms</>',
112114
match (true) {
113115
$statusCode >= 500 => 'red',
114116
$statusCode >= 400 => 'yellow',
@@ -120,6 +122,7 @@ public function requestInfo($request, $verbosity = null)
120122
$method,
121123
$url,
122124
$dots,
125+
$memory,
123126
$duration,
124127
), $this->parseVerbosity($verbosity));
125128
}

0 commit comments

Comments
 (0)