blob: 4605135e166f5f31f3ea306afb662c68534a2e08 [file] [log] [blame]
Kostya Serebryany1e172b42011-11-30 01:07:02 +00001//===-- 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
20namespace __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.
25struct AsanStats {
Kostya Serebryany3f4c3872012-05-31 14:35:53 +000026 // 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;
Kostya Serebryany3f4c3872012-05-31 14:35:53 +000035 uptr reallocs;
36 uptr realloced;
37 uptr mmaps;
38 uptr mmaped;
Kostya Serebryanye3091192012-12-19 14:56:38 +000039 uptr munmaps;
40 uptr munmaped;
Kostya Serebryany3f4c3872012-05-31 14:35:53 +000041 uptr malloc_large;
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080042 uptr malloced_by_size[kNumberOfSizeClasses];
Kostya Serebryany1e172b42011-11-30 01:07:02 +000043
Stephen Hines2d1fdb22014-05-28 23:58:16 -070044 // Ctor for global AsanStats (accumulated stats for dead threads).
Kostya Serebryany1e172b42011-11-30 01:07:02 +000045 explicit AsanStats(LinkerInitialized) { }
Stephen Hines2d1fdb22014-05-28 23:58:16 -070046 // Creates empty stats.
Kostya Serebryany1e172b42011-11-30 01:07:02 +000047 AsanStats();
48
Alexey Samsonov717ece52013-09-02 08:39:07 +000049 void Print(); // Prints formatted stats to stderr.
50 void Clear();
51 void MergeFrom(const AsanStats *stats);
Kostya Serebryany1e172b42011-11-30 01:07:02 +000052};
53
Alexey Samsonovc25e62b2013-03-20 10:11:24 +000054// Returns stats for GetCurrentThread(), or stats for fake "unknown thread"
55// if GetCurrentThread() returns 0.
56AsanStats &GetCurrentThreadStats();
Alexey Samsonov717ece52013-09-02 08:39:07 +000057// Flushes a given stats into accumulated stats of dead threads.
58void FlushToDeadThreadStats(AsanStats *stats);
Alexey Samsonovc25e62b2013-03-20 10:11:24 +000059
Alexander Potapenkoca2cdd92012-09-12 15:29:50 +000060// A cross-platform equivalent of malloc_statistics_t on Mac OS.
61struct AsanMallocStats {
62 uptr blocks_in_use;
63 uptr size_in_use;
64 uptr max_size_in_use;
65 uptr size_allocated;
66};
67
Alexey Samsonovc25e62b2013-03-20 10:11:24 +000068void FillMallocStatistics(AsanMallocStats *malloc_stats);
69
Kostya Serebryany1e172b42011-11-30 01:07:02 +000070} // namespace __asan
71
72#endif // ASAN_STATS_H