perf: Log excessive memory usage on normal requests

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2024-12-18 12:31:09 +01:00
parent 407ac7f739
commit 14aab1f2ae
No known key found for this signature in database
GPG key ID: F72FA5B49FFA96B0
2 changed files with 14 additions and 0 deletions

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
*/
require_once __DIR__ . '/lib/versioncheck.php';
$memoryBefore = memory_get_usage();
use OC\ServiceUnavailableException;
use OC\User\LoginException;
@ -104,4 +105,10 @@ try {
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);
}
}

View file

@ -9,6 +9,7 @@ declare(strict_types=1);
*/
require_once __DIR__ . '/../lib/versioncheck.php';
$memoryBefore = memory_get_usage();
require_once __DIR__ . '/../lib/base.php';
use OC\OCS\ApiHelper;
@ -70,4 +71,10 @@ try {
// 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);
}
}