diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h index 4573f56f7ee6f..06076fdd0aa55 100644 --- a/compiler-rt/lib/scudo/standalone/secondary.h +++ b/compiler-rt/lib/scudo/standalone/secondary.h @@ -155,10 +155,22 @@ template class MapAllocatorCache { void getStats(ScopedString *Str) { ScopedLock L(Mutex); + u32 Integral = 0; + u32 Fractional = 0; + if (CallsToRetrieve != 0) { + Integral = SuccessfulRetrieves * 100 / CallsToRetrieve; + Fractional = (((SuccessfulRetrieves * 100) % CallsToRetrieve) * 100 + + CallsToRetrieve / 2) / + CallsToRetrieve; + } Str->append("Stats: MapAllocatorCache: EntriesCount: %d, " "MaxEntriesCount: %u, MaxEntrySize: %zu\n", EntriesCount, atomic_load_relaxed(&MaxEntriesCount), atomic_load_relaxed(&MaxEntrySize)); + Str->append("Stats: CacheRetrievalStats: SuccessRate: %u/%u " + "(%u.%02u%%)\n", + SuccessfulRetrieves, CallsToRetrieve, + Integral, Fractional); for (CachedBlock Entry : Entries) { if (!Entry.isValid()) continue; @@ -272,6 +284,7 @@ template class MapAllocatorCache { uptr HeaderPos = 0; { ScopedLock L(Mutex); + CallsToRetrieve++; if (EntriesCount == 0) return false; for (u32 I = 0; I < MaxCount; I++) { @@ -292,6 +305,7 @@ template class MapAllocatorCache { Entry = Entries[I]; Entries[I].invalidate(); EntriesCount--; + SuccessfulRetrieves++; break; } } @@ -428,6 +442,8 @@ template class MapAllocatorCache { u64 OldestTime GUARDED_BY(Mutex) = 0; u32 IsFullEvents GUARDED_BY(Mutex) = 0; atomic_s32 ReleaseToOsIntervalMs = {}; + u32 CallsToRetrieve GUARDED_BY(Mutex) = 0; + u32 SuccessfulRetrieves GUARDED_BY(Mutex) = 0; CachedBlock Entries[CacheConfig::EntriesArraySize] GUARDED_BY(Mutex) = {}; NonZeroLengthArray