Skip to content

Commit

Permalink
Added memory usage to API debug response
Browse files Browse the repository at this point in the history
  • Loading branch information
promatik committed Mar 17, 2023
1 parent 23ac9e6 commit 5535ba2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/app/Helpers/CommonHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,17 @@ function json_response($data = null, $code = 0, $status = 200, $errors = null, $
];

if (debugMode()) {
$time = floatval(number_format((microtime(true) - LARAVEL_START), 6)) * 1e6;
$timeData = $time > 1e6 ? [$time / 1e6, 'seconds'] : (
$time > 1e3 ? [$time / 1e3, 'miliseconds'] : (
[$time, 'microseconds']
$time = (int) ((microtime(true) - LARAVEL_START) * 1e6);
$timeData = $time > 1e6 ? [$time / 1e6, 's'] : (
$time > 1e3 ? [$time / 1e3, 'ms'] : (
[$time, 'μs']
)
);

$memory = memory_get_peak_usage();
$memoryData = $memory > 1e6 ? [$memory / 1e6, 'mb'] : (
$memory > 1e3 ? [$memory / 1e3, 'kb'] : (
[$memory, 'b']
)
);

Expand All @@ -164,6 +171,10 @@ function json_response($data = null, $code = 0, $status = 200, $errors = null, $
'value' => $timeData[0],
'unit' => $timeData[1],
],
'memory' => [
'value' => $memoryData[0],
'unit' => $memoryData[1],
],
'exception' => $exception,
'queries' => DB::getQueryLog(),
'post' => request()->request->all(),
Expand Down

0 comments on commit 5535ba2

Please sign in to comment.