Skip to content

Commit 12a22ec

Browse files
FernandoChiaHungDuan
Fernando
authored andcommitted
[scudo] Dump MapAllocatorCache::retrieve() data
Keeps track of CallsToRetrieve, how many SuccessfulRetrieves, from cached block allocations. Dumps this data in the MapAllocatorCache::getStats() function Reviewed By: cferris, Chia-hungDuan Differential Revision: https://reviews.llvm.org/D157154
1 parent 5bc4b34 commit 12a22ec

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compiler-rt/lib/scudo/standalone/secondary.h

+16
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,22 @@ template <typename Config> class MapAllocatorCache {
155155

156156
void getStats(ScopedString *Str) {
157157
ScopedLock L(Mutex);
158+
u32 Integral = 0;
159+
u32 Fractional = 0;
160+
if (CallsToRetrieve != 0) {
161+
Integral = SuccessfulRetrieves * 100 / CallsToRetrieve;
162+
Fractional = (((SuccessfulRetrieves * 100) % CallsToRetrieve) * 100 +
163+
CallsToRetrieve / 2) /
164+
CallsToRetrieve;
165+
}
158166
Str->append("Stats: MapAllocatorCache: EntriesCount: %d, "
159167
"MaxEntriesCount: %u, MaxEntrySize: %zu\n",
160168
EntriesCount, atomic_load_relaxed(&MaxEntriesCount),
161169
atomic_load_relaxed(&MaxEntrySize));
170+
Str->append("Stats: CacheRetrievalStats: SuccessRate: %u/%u "
171+
"(%u.%02u%%)\n",
172+
SuccessfulRetrieves, CallsToRetrieve,
173+
Integral, Fractional);
162174
for (CachedBlock Entry : Entries) {
163175
if (!Entry.isValid())
164176
continue;
@@ -272,6 +284,7 @@ template <typename Config> class MapAllocatorCache {
272284
uptr HeaderPos = 0;
273285
{
274286
ScopedLock L(Mutex);
287+
CallsToRetrieve++;
275288
if (EntriesCount == 0)
276289
return false;
277290
for (u32 I = 0; I < MaxCount; I++) {
@@ -292,6 +305,7 @@ template <typename Config> class MapAllocatorCache {
292305
Entry = Entries[I];
293306
Entries[I].invalidate();
294307
EntriesCount--;
308+
SuccessfulRetrieves++;
295309
break;
296310
}
297311
}
@@ -428,6 +442,8 @@ template <typename Config> class MapAllocatorCache {
428442
u64 OldestTime GUARDED_BY(Mutex) = 0;
429443
u32 IsFullEvents GUARDED_BY(Mutex) = 0;
430444
atomic_s32 ReleaseToOsIntervalMs = {};
445+
u32 CallsToRetrieve GUARDED_BY(Mutex) = 0;
446+
u32 SuccessfulRetrieves GUARDED_BY(Mutex) = 0;
431447

432448
CachedBlock Entries[CacheConfig::EntriesArraySize] GUARDED_BY(Mutex) = {};
433449
NonZeroLengthArray<CachedBlock, CacheConfig::QuarantineSize>

0 commit comments

Comments
 (0)