[asan] asan_allocator2: add mmap/munmap stats
authorKostya Serebryany <kcc@google.com>
Wed, 19 Dec 2012 14:56:38 +0000 (14:56 +0000)
committerKostya Serebryany <kcc@google.com>
Wed, 19 Dec 2012 14:56:38 +0000 (14:56 +0000)
llvm-svn: 170548

compiler-rt/lib/asan/asan_allocator2.cc
compiler-rt/lib/asan/asan_stats.h
compiler-rt/lib/asan/asan_thread_registry.cc

index 5dac665..bc91ad7 100644 (file)
@@ -32,9 +32,18 @@ namespace __asan {
 struct AsanMapUnmapCallback {
   void OnMap(uptr p, uptr size) const {
     PoisonShadow(p, size, kAsanHeapLeftRedzoneMagic);
+    // Statistics.
+    AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
+    thread_stats.mmaps++;
+    thread_stats.mmaped += size;
+    // thread_stats.mmaped_by_size[size_class] += n_chunks;
   }
   void OnUnmap(uptr p, uptr size) const {
     PoisonShadow(p, size, 0);
+    // Statistics.
+    AsanStats &thread_stats = asanThreadRegistry().GetCurrentThreadStats();
+    thread_stats.munmaps++;
+    thread_stats.munmaped += size;
   }
 };
 
@@ -187,6 +196,9 @@ class Quarantine: public AsanChunkFifoList {
     PushList(q);
     PopAndDeallocateLoop(ms);
   }
+  void SwallowThreadLocalCache(AllocatorCache *cache) {
+    // FIXME.
+  }
   void BypassThreadLocalQuarantine(AsanChunk *m) {
     SpinMutexLock l(&mutex_);
     Push(m);
@@ -420,6 +432,7 @@ AsanChunkView FindHeapChunkByAddress(uptr addr) {
 
 void AsanThreadLocalMallocStorage::CommitBack() {
   quarantine.SwallowThreadLocalQuarantine(this);
+  quarantine.SwallowThreadLocalCache(GetAllocatorCache(this));
 }
 
 SANITIZER_INTERFACE_ATTRIBUTE
index 0c02b3a..37846bc 100644 (file)
@@ -37,6 +37,8 @@ struct AsanStats {
   uptr realloced;
   uptr mmaps;
   uptr mmaped;
+  uptr munmaps;
+  uptr munmaped;
   uptr mmaped_by_size[kNumberOfSizeClasses];
   uptr malloced_by_size[kNumberOfSizeClasses];
   uptr freed_by_size[kNumberOfSizeClasses];
index 0e07e19..801b0b2 100644 (file)
@@ -123,7 +123,7 @@ uptr AsanThreadRegistry::GetCurrentAllocatedBytes() {
 uptr AsanThreadRegistry::GetHeapSize() {
   ScopedLock lock(&mu_);
   UpdateAccumulatedStatsUnlocked();
-  return accumulated_stats_.mmaped;
+  return accumulated_stats_.mmaped - accumulated_stats_.munmaped;
 }
 
 uptr AsanThreadRegistry::GetFreeBytes() {