Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

learning from my own pr #45804 is to not encode the threshold in the log message as it makes grepping harder 😬
How about we log Excessive memory used or similar and put the threshold into the context object of the log?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then we don't see it right away in lnav or any other tool. Since it's at the end you can already grep for Used memory was more than 400 MB: ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah fair enough

\OCP\Server::get(LoggerInterface::class)->warning($message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use the OCP\Log\logger function because it includes error handling when the loggerinterface can't be resolved

}
}
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);
}
}
Loading