forked from OSchip/llvm-project
[asan] asan_allocator2: better memory stats
llvm-svn: 170888
This commit is contained in:
parent
0ca819410d
commit
3cc719fdf9
|
@ -50,12 +50,14 @@ struct AsanMapUnmapCallback {
|
|||
#if SANITIZER_WORDSIZE == 64
|
||||
const uptr kAllocatorSpace = 0x600000000000ULL;
|
||||
const uptr kAllocatorSize = 0x10000000000ULL; // 1T.
|
||||
typedef DefaultSizeClassMap SizeClassMap;
|
||||
typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, 0 /*metadata*/,
|
||||
DefaultSizeClassMap, AsanMapUnmapCallback> PrimaryAllocator;
|
||||
SizeClassMap, AsanMapUnmapCallback> PrimaryAllocator;
|
||||
#elif SANITIZER_WORDSIZE == 32
|
||||
static const u64 kAddressSpaceSize = 1ULL << 32;
|
||||
typedef CompactSizeClassMap SizeClassMap;
|
||||
typedef SizeClassAllocator32<0, kAddressSpaceSize, 16,
|
||||
CompactSizeClassMap, AsanMapUnmapCallback> PrimaryAllocator;
|
||||
SizeClassMap, AsanMapUnmapCallback> PrimaryAllocator;
|
||||
#endif
|
||||
|
||||
typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
|
||||
|
@ -339,6 +341,11 @@ static void *Allocate(uptr size, uptr alignment, StackTrace *stack,
|
|||
AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
|
||||
thread_stats.mallocs++;
|
||||
thread_stats.malloced += size;
|
||||
thread_stats.malloced_redzones += needed_size - size;
|
||||
uptr class_id = Min(kNumberOfSizeClasses, SizeClassMap::ClassID(needed_size));
|
||||
thread_stats.malloced_by_size[class_id]++;
|
||||
if (needed_size > SizeClassMap::kMaxSize)
|
||||
thread_stats.malloc_large++;
|
||||
|
||||
void *res = reinterpret_cast<void *>(user_beg);
|
||||
ASAN_MALLOC_HOOK(res, size);
|
||||
|
@ -400,6 +407,10 @@ static void *Reallocate(void *old_ptr, uptr new_size, StackTrace *stack) {
|
|||
uptr chunk_beg = p - kChunkHeaderSize;
|
||||
AsanChunk *m = reinterpret_cast<AsanChunk *>(chunk_beg);
|
||||
|
||||
AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
|
||||
thread_stats.reallocs++;
|
||||
thread_stats.realloced += new_size;
|
||||
|
||||
CHECK(m->chunk_state == CHUNK_ALLOCATED);
|
||||
uptr old_size = m->UsedSize();
|
||||
uptr memcpy_size = Min(new_size, old_size);
|
||||
|
|
|
@ -42,8 +42,9 @@ void AsanStats::Print() {
|
|||
Printf("Stats: %zuM freed by %zu calls\n", freed>>20, frees);
|
||||
Printf("Stats: %zuM really freed by %zu calls\n",
|
||||
really_freed>>20, real_frees);
|
||||
Printf("Stats: %zuM (%zu full pages) mmaped in %zu calls\n",
|
||||
mmaped>>20, mmaped / GetPageSizeCached(), mmaps);
|
||||
Printf("Stats: %zuM (%zuM-%zuM) mmaped; %zu maps, %zu unmaps\n",
|
||||
(mmaped-munmaped)>>20, mmaped>>20, munmaped>>20,
|
||||
mmaps, munmaps);
|
||||
|
||||
PrintMallocStatsArray(" mmaps by size class: ", mmaped_by_size);
|
||||
PrintMallocStatsArray(" mallocs by size class: ", malloced_by_size);
|
||||
|
|
Loading…
Reference in New Issue