[sanitizer] better statistics for the large allocator

llvm-svn: 172069
This commit is contained in:
Kostya Serebryany 2013-01-10 13:38:38 +00:00
parent e1be48fe64
commit fdcfbda750
2 changed files with 11 additions and 3 deletions

View File

@ -103,7 +103,6 @@ static void MsanAtExit(void) {
void InstallAtExitHandler() { void InstallAtExitHandler() {
atexit(MsanAtExit); atexit(MsanAtExit);
} }
} }
#endif // __linux__ #endif // __linux__

View File

@ -747,6 +747,8 @@ class LargeMmapAllocator {
h->size = size; h->size = size;
h->map_beg = map_beg; h->map_beg = map_beg;
h->map_size = map_size; h->map_size = map_size;
uptr size_log = SANITIZER_WORDSIZE - __builtin_clzl(map_size) - 1;
CHECK_LT(size_log, ARRAY_SIZE(stats.by_size_log));
{ {
SpinMutexLock l(&mutex_); SpinMutexLock l(&mutex_);
uptr idx = n_chunks_++; uptr idx = n_chunks_++;
@ -756,6 +758,7 @@ class LargeMmapAllocator {
stats.n_allocs++; stats.n_allocs++;
stats.currently_allocated += map_size; stats.currently_allocated += map_size;
stats.max_allocated = Max(stats.max_allocated, stats.currently_allocated); stats.max_allocated = Max(stats.max_allocated, stats.currently_allocated);
stats.by_size_log[size_log]++;
} }
return reinterpret_cast<void*>(res); return reinterpret_cast<void*>(res);
} }
@ -827,9 +830,15 @@ class LargeMmapAllocator {
void PrintStats() { void PrintStats() {
Printf("Stats: LargeMmapAllocator: allocated %zd times, " Printf("Stats: LargeMmapAllocator: allocated %zd times, "
"remains %zd (%zd K) max %zd M\n", "remains %zd (%zd K) max %zd M; by size logs: ",
stats.n_allocs, stats.n_allocs - stats.n_frees, stats.n_allocs, stats.n_allocs - stats.n_frees,
stats.currently_allocated >> 10, stats.max_allocated >> 20); stats.currently_allocated >> 10, stats.max_allocated >> 20);
for (uptr i = 0; i < ARRAY_SIZE(stats.by_size_log); i++) {
uptr c = stats.by_size_log[i];
if (!c) continue;
Printf("%zd:%zd; ", i, c);
}
Printf("\n");
} }
private: private:
@ -860,7 +869,7 @@ class LargeMmapAllocator {
Header *chunks_[kMaxNumChunks]; Header *chunks_[kMaxNumChunks];
uptr n_chunks_; uptr n_chunks_;
struct Stats { struct Stats {
uptr n_allocs, n_frees, currently_allocated, max_allocated; uptr n_allocs, n_frees, currently_allocated, max_allocated, by_size_log[64];
} stats; } stats;
SpinMutex mutex_; SpinMutex mutex_;
}; };