Skip to content

Commit 8aa28ec

Browse files
juliusknorrAndyScherzinger
authored andcommitted
perf: Log requests using high amount of memory as warning
Signed-off-by: Julius Knorr <[email protected]>
1 parent 6b6401f commit 8aa28ec

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/base.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\Server;
1919
use OCP\Share;
2020
use OCP\User\Events\UserChangedEvent;
21+
use OCP\Util;
2122
use Psr\Log\LoggerInterface;
2223
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
2324
use function OCP\Log\logger;
@@ -828,6 +829,15 @@ public static function init(): void {
828829
register_shutdown_function(function () use ($eventLogger) {
829830
$eventLogger->end('request');
830831
});
832+
833+
register_shutdown_function(function () {
834+
$memoryPeak = memory_get_peak_usage();
835+
if ($memoryPeak > 300_000_000) {
836+
$message = 'Request used more than 300 MB of ram: ' . Util::humanFileSize($memoryPeak);
837+
$logger = \OCP\Server::get(LoggerInterface::class);
838+
$logger->warning($message, ['app' => 'core']);
839+
}
840+
});
831841
}
832842

833843
/**

0 commit comments

Comments
 (0)