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