Skip to content

Commit d8bb029

Browse files
kjkclaude
andcommitted
Log temp allocator lifetime stats on exit
Add LogTempAllocatorLifetimeStats(), called during shutdown before logging is torn down, to log the temp allocator's lifetime allocation count and peak bytes (comma-grouped + human-readable). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent da89cae commit d8bb029

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/SumatraStartup.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,18 @@ static void ResetTempAllocatorWithLogging() {
711711
ResetTempAllocator();
712712
}
713713

714+
// Logs the temp allocator's lifetime allocation count and peak bytes. Call on
715+
// exit, before logging is torn down.
716+
static void LogTempAllocatorLifetimeStats() {
717+
Arena* a = GetTempAllocator();
718+
u64 nAllocs = a->nAllocsLifetime;
719+
u64 peakBytes = a->peakBytesLifetime;
720+
char human[32];
721+
FormatSizeHumanIntoBuf(peakBytes, Str(human, (int)sizeof(human)));
722+
logf("temp allocator lifetime: %s allocations, peak %s bytes (%s)\n",
723+
str::FormatNumWithThousandSepTemp((i64)nAllocs), str::FormatNumWithThousandSepTemp((i64)peakBytes), human);
724+
}
725+
714726
static int RunMessageLoop() {
715727
MSG msg;
716728

@@ -2219,6 +2231,7 @@ int APIENTRY WinMain(_In_ HINSTANCE /*hInstance*/, _In_opt_ HINSTANCE, _In_ LPST
22192231
UninstallCrashHandler();
22202232
}
22212233
DeleteAppTools();
2234+
LogTempAllocatorLifetimeStats();
22222235
DestroyLogging();
22232236
DestroyTempAllocator();
22242237

0 commit comments

Comments
 (0)