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