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