* configure.ac: Change target-libasan to target-libsanitizer.
[official-gcc.git] / libsanitizer / asan / asan_stats.cc
blobfa4adcb7f9aaabce1ee326ef0c5c404875c0fa78
1 //===-- asan_stats.cc -----------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of AddressSanitizer, an address sanity checker.
9 //
10 // Code related to statistics collected by AddressSanitizer.
11 //===----------------------------------------------------------------------===//
12 #include "asan_interceptors.h"
13 #include "asan_internal.h"
14 #include "asan_lock.h"
15 #include "asan_stats.h"
16 #include "asan_thread_registry.h"
17 #include "sanitizer/asan_interface.h"
19 namespace __asan {
21 AsanStats::AsanStats() {
22 CHECK(REAL(memset) != 0);
23 REAL(memset)(this, 0, sizeof(AsanStats));
26 static void PrintMallocStatsArray(const char *prefix,
27 uptr (&array)[kNumberOfSizeClasses]) {
28 Printf("%s", prefix);
29 for (uptr i = 0; i < kNumberOfSizeClasses; i++) {
30 if (!array[i]) continue;
31 Printf("%zu:%zu; ", i, array[i]);
33 Printf("\n");
36 void AsanStats::Print() {
37 Printf("Stats: %zuM malloced (%zuM for red zones) by %zu calls\n",
38 malloced>>20, malloced_redzones>>20, mallocs);
39 Printf("Stats: %zuM realloced by %zu calls\n", realloced>>20, reallocs);
40 Printf("Stats: %zuM freed by %zu calls\n", freed>>20, frees);
41 Printf("Stats: %zuM really freed by %zu calls\n",
42 really_freed>>20, real_frees);
43 Printf("Stats: %zuM (%zu full pages) mmaped in %zu calls\n",
44 mmaped>>20, mmaped / kPageSize, mmaps);
46 PrintMallocStatsArray(" mmaps by size class: ", mmaped_by_size);
47 PrintMallocStatsArray(" mallocs by size class: ", malloced_by_size);
48 PrintMallocStatsArray(" frees by size class: ", freed_by_size);
49 PrintMallocStatsArray(" rfrees by size class: ", really_freed_by_size);
50 Printf("Stats: malloc large: %zu small slow: %zu\n",
51 malloc_large, malloc_small_slow);
54 static AsanLock print_lock(LINKER_INITIALIZED);
56 static void PrintAccumulatedStats() {
57 AsanStats stats = asanThreadRegistry().GetAccumulatedStats();
58 // Use lock to keep reports from mixing up.
59 ScopedLock lock(&print_lock);
60 stats.Print();
63 } // namespace __asan
65 // ---------------------- Interface ---------------- {{{1
66 using namespace __asan; // NOLINT
68 uptr __asan_get_current_allocated_bytes() {
69 return asanThreadRegistry().GetCurrentAllocatedBytes();
72 uptr __asan_get_heap_size() {
73 return asanThreadRegistry().GetHeapSize();
76 uptr __asan_get_free_bytes() {
77 return asanThreadRegistry().GetFreeBytes();
80 uptr __asan_get_unmapped_bytes() {
81 return 0;
84 void __asan_print_accumulated_stats() {
85 PrintAccumulatedStats();