Skip to content

Commit

Permalink
perf: Log excessive memory usage on normal requests
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Dec 18, 2024
1 parent 407ac7f commit 14aab1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

require_once __DIR__ . '/lib/versioncheck.php';
$memoryBefore = memory_get_usage();

use OC\ServiceUnavailableException;
use OC\User\LoginException;
Expand Down Expand Up @@ -104,4 +105,10 @@
throw $ex;
}
OC_Template::printExceptionErrorPage($ex, 500);
} finally {
$memoryAfter = memory_get_usage();
if ($memoryAfter - $memoryBefore > 400_000_000) {
$message = 'Used memory was more than 400 MB: ' . \OCP\Util::humanFileSize($memoryAfter - $memoryBefore);
\OCP\Server::get(LoggerInterface::class)->warning($message);
}
}
7 changes: 7 additions & 0 deletions ocs/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

require_once __DIR__ . '/../lib/versioncheck.php';
$memoryBefore = memory_get_usage();
require_once __DIR__ . '/../lib/base.php';

use OC\OCS\ApiHelper;
Expand Down Expand Up @@ -70,4 +71,10 @@
// Just to be save
}
ApiHelper::respond(OCSController::RESPOND_SERVER_ERROR, $txt);
} finally {
$memoryAfter = memory_get_usage();
if ($memoryAfter - $memoryBefore > 400_000_000) {
$message = 'Used memory was more than 400 MB: ' . \OCP\Util::humanFileSize($memoryAfter - $memoryBefore);
\OCP\Server::get(LoggerInterface::class)->warning($message);
}
}

0 comments on commit 14aab1f

Please sign in to comment.