1 //===-- asan_stats.h --------------------------------------------*- C++ -*-===// 2 // 3 // This file is distributed under the University of Illinois Open Source 4 // License. See LICENSE.TXT for details. 5 // 6 //===----------------------------------------------------------------------===// 7 // 8 // This file is a part of AddressSanitizer, an address sanity checker. 9 // 10 // ASan-private header for statistics. 11 //===----------------------------------------------------------------------===// 12 #ifndef ASAN_STATS_H 13 #define ASAN_STATS_H 14 15 #include "asan_allocator.h" 16 #include "asan_internal.h" 17 18 namespace __asan { 19 20 // AsanStats struct is NOT thread-safe. 21 // Each AsanThread has its own AsanStats, which are sometimes flushed 22 // to the accumulated AsanStats. 23 struct AsanStats { 24 // AsanStats must be a struct consisting of uptr fields only. 25 // When merging two AsanStats structs, we treat them as arrays of uptr. 26 uptr mallocs; 27 uptr malloced; 28 uptr malloced_redzones; 29 uptr frees; 30 uptr freed; 31 uptr real_frees; 32 uptr really_freed; 33 uptr reallocs; 34 uptr realloced; 35 uptr mmaps; 36 uptr mmaped; 37 uptr munmaps; 38 uptr munmaped; 39 uptr malloc_large; 40 uptr malloced_by_size[kNumberOfSizeClasses]; 41 42 // Ctor for global AsanStats (accumulated stats for dead threads). AsanStatsAsanStats43 explicit AsanStats(LinkerInitialized) { } 44 // Creates empty stats. 45 AsanStats(); 46 47 void Print(); // Prints formatted stats to stderr. 48 void Clear(); 49 void MergeFrom(const AsanStats *stats); 50 }; 51 52 // Returns stats for GetCurrentThread(), or stats for fake "unknown thread" 53 // if GetCurrentThread() returns 0. 54 AsanStats &GetCurrentThreadStats(); 55 // Flushes a given stats into accumulated stats of dead threads. 56 void FlushToDeadThreadStats(AsanStats *stats); 57 58 // A cross-platform equivalent of malloc_statistics_t on Mac OS. 59 struct AsanMallocStats { 60 uptr blocks_in_use; 61 uptr size_in_use; 62 uptr max_size_in_use; 63 uptr size_allocated; 64 }; 65 66 void FillMallocStatistics(AsanMallocStats *malloc_stats); 67 68 } // namespace __asan 69 70 #endif // ASAN_STATS_H 71