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