diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h --- a/compiler-rt/lib/scudo/standalone/secondary.h +++ b/compiler-rt/lib/scudo/standalone/secondary.h @@ -93,6 +93,10 @@ // Not supported by the Secondary Cache, but not an error either. return true; } + + void getStats(UNUSED ScopedString *Str) { + Str->append("Secondary Cache Disabled\n"); + } }; static const uptr MaxUnusedCachePages = 4U; @@ -131,6 +135,21 @@ template class MapAllocatorCache { public: using CacheConfig = typename Config::Secondary::Cache; + + void getStats(ScopedString *Str) { + ScopedLock L(Mutex); + Str->append("Stats: MapAllocatorCache: EntriesCount: %d, " + "MaxEntriesCount: %u, MaxEntrySize: %zu\n", + EntriesCount, atomic_load_relaxed(&MaxEntriesCount), + atomic_load_relaxed(&MaxEntrySize)); + for (CachedBlock Entry : Entries) { + Str->append("StartBlockAddress: 0x%zx, EndBlockAddress: 0x%zx, " + "BlockSize: %zu\n", + Entry.CommitBase, (Entry.CommitBase + Entry.CommitSize), + Entry.CommitSize); + } + } + // Ensure the default maximum specified fits the array. static_assert(CacheConfig::DefaultMaxEntriesCount <= CacheConfig::EntriesArraySize, @@ -433,8 +452,6 @@ return getBlockEnd(Ptr) - reinterpret_cast(Ptr); } - void getStats(ScopedString *Str); - void disable() NO_THREAD_SAFETY_ANALYSIS { Mutex.lock(); Cache.disable(); @@ -466,6 +483,8 @@ void unmapTestOnly() { Cache.unmapTestOnly(); } + void getStats(ScopedString *Str); + private: typename Config::Secondary::template CacheT Cache; @@ -621,6 +640,7 @@ NumberOfAllocs, AllocatedBytes >> 10, NumberOfFrees, FreedBytes >> 10, NumberOfAllocs - NumberOfFrees, (AllocatedBytes - FreedBytes) >> 10, LargestSize >> 20); + Cache.getStats(Str); } } // namespace scudo