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