]> source.dussan.org Git - nextcloud-server.git/commitdiff
perf: Log requests using high amount of memory as warning perf/log-high-memory-requests 48738/head
authorJulius Knorr <jus@bitgrid.net>
Wed, 16 Oct 2024 16:12:05 +0000 (18:12 +0200)
committerJulius Knorr <jus@bitgrid.net>
Wed, 16 Oct 2024 16:12:05 +0000 (18:12 +0200)
Signed-off-by: Julius Knorr <jus@bitgrid.net>
lib/base.php

index 5bab5d9f3f699af17272a7d0fb31bd8a2a698a8b..6240a7043aca85c718489ec3adca7d50f6aac0fb 100644 (file)
@@ -18,6 +18,7 @@ use OCP\Security\Bruteforce\IThrottler;
 use OCP\Server;
 use OCP\Share;
 use OCP\User\Events\UserChangedEvent;
+use OCP\Util;
 use Psr\Log\LoggerInterface;
 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 use function OCP\Log\logger;
@@ -820,6 +821,15 @@ class OC {
                register_shutdown_function(function () use ($eventLogger) {
                        $eventLogger->end('request');
                });
+
+               register_shutdown_function(function () {
+                       $memoryPeak = memory_get_peak_usage();
+                       if ($memoryPeak > 300_000_000) {
+                               $message = 'Request used more than 300 MB of ram: ' . Util::humanFileSize($memoryPeak);
+                               $logger = \OCP\Server::get(LoggerInterface::class);
+                               $logger->warning($message, ['app' => 'core']);
+                       }
+               });
        }
 
        /**