2012-06-04 21:50:10 +08:00
|
|
|
//===-- asan_stats.cc -----------------------------------------------------===//
|
2011-11-30 09:07:02 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// Code related to statistics collected by AddressSanitizer.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "asan_interceptors.h"
|
|
|
|
#include "asan_internal.h"
|
|
|
|
#include "asan_stats.h"
|
|
|
|
#include "asan_thread_registry.h"
|
2012-08-29 10:27:54 +08:00
|
|
|
#include "sanitizer/asan_interface.h"
|
2012-12-26 14:30:02 +08:00
|
|
|
#include "sanitizer_common/sanitizer_stackdepot.h"
|
2011-11-30 09:07:02 +08:00
|
|
|
|
|
|
|
namespace __asan {
|
|
|
|
|
|
|
|
AsanStats::AsanStats() {
|
2012-05-31 22:35:53 +08:00
|
|
|
CHECK(REAL(memset) != 0);
|
2012-02-08 21:45:31 +08:00
|
|
|
REAL(memset)(this, 0, sizeof(AsanStats));
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintMallocStatsArray(const char *prefix,
|
2012-05-31 22:35:53 +08:00
|
|
|
uptr (&array)[kNumberOfSizeClasses]) {
|
2012-08-28 19:34:40 +08:00
|
|
|
Printf("%s", prefix);
|
2012-05-31 22:35:53 +08:00
|
|
|
for (uptr i = 0; i < kNumberOfSizeClasses; i++) {
|
2011-11-30 09:07:02 +08:00
|
|
|
if (!array[i]) continue;
|
2012-08-28 19:34:40 +08:00
|
|
|
Printf("%zu:%zu; ", i, array[i]);
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
2012-08-28 19:34:40 +08:00
|
|
|
Printf("\n");
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AsanStats::Print() {
|
2012-08-28 19:34:40 +08:00
|
|
|
Printf("Stats: %zuM malloced (%zuM for red zones) by %zu calls\n",
|
2012-06-06 21:11:29 +08:00
|
|
|
malloced>>20, malloced_redzones>>20, mallocs);
|
2012-08-28 19:34:40 +08:00
|
|
|
Printf("Stats: %zuM realloced by %zu calls\n", realloced>>20, reallocs);
|
|
|
|
Printf("Stats: %zuM freed by %zu calls\n", freed>>20, frees);
|
|
|
|
Printf("Stats: %zuM really freed by %zu calls\n",
|
2012-06-06 21:11:29 +08:00
|
|
|
really_freed>>20, real_frees);
|
2012-12-21 20:26:31 +08:00
|
|
|
Printf("Stats: %zuM (%zuM-%zuM) mmaped; %zu maps, %zu unmaps\n",
|
|
|
|
(mmaped-munmaped)>>20, mmaped>>20, munmaped>>20,
|
|
|
|
mmaps, munmaps);
|
2011-11-30 09:07:02 +08:00
|
|
|
|
|
|
|
PrintMallocStatsArray(" mmaps by size class: ", mmaped_by_size);
|
|
|
|
PrintMallocStatsArray(" mallocs by size class: ", malloced_by_size);
|
|
|
|
PrintMallocStatsArray(" frees by size class: ", freed_by_size);
|
|
|
|
PrintMallocStatsArray(" rfrees by size class: ", really_freed_by_size);
|
2012-08-28 19:34:40 +08:00
|
|
|
Printf("Stats: malloc large: %zu small slow: %zu\n",
|
2012-06-06 21:11:29 +08:00
|
|
|
malloc_large, malloc_small_slow);
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
|
|
|
|
2013-01-14 15:51:39 +08:00
|
|
|
static BlockingMutex print_lock(LINKER_INITIALIZED);
|
2011-12-03 10:23:25 +08:00
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
static void PrintAccumulatedStats() {
|
2012-11-19 18:25:17 +08:00
|
|
|
AsanStats stats;
|
|
|
|
asanThreadRegistry().GetAccumulatedStats(&stats);
|
2011-11-30 09:07:02 +08:00
|
|
|
// Use lock to keep reports from mixing up.
|
2013-01-14 15:51:39 +08:00
|
|
|
BlockingMutexLock lock(&print_lock);
|
2011-11-30 09:07:02 +08:00
|
|
|
stats.Print();
|
2012-12-26 14:30:02 +08:00
|
|
|
StackDepotStats *stack_depot_stats = StackDepotGetStats();
|
|
|
|
Printf("Stats: StackDepot: %zd ids; %zdM mapped\n",
|
|
|
|
stack_depot_stats->n_uniq_ids, stack_depot_stats->mapped >> 20);
|
2012-12-27 22:09:19 +08:00
|
|
|
PrintInternalAllocatorStats();
|
2011-11-30 09:07:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __asan
|
|
|
|
|
|
|
|
// ---------------------- Interface ---------------- {{{1
|
|
|
|
using namespace __asan; // NOLINT
|
|
|
|
|
2012-05-31 22:11:07 +08:00
|
|
|
uptr __asan_get_current_allocated_bytes() {
|
2011-11-30 09:07:02 +08:00
|
|
|
return asanThreadRegistry().GetCurrentAllocatedBytes();
|
|
|
|
}
|
|
|
|
|
2012-05-31 22:11:07 +08:00
|
|
|
uptr __asan_get_heap_size() {
|
2011-11-30 09:07:02 +08:00
|
|
|
return asanThreadRegistry().GetHeapSize();
|
|
|
|
}
|
|
|
|
|
2012-05-31 22:11:07 +08:00
|
|
|
uptr __asan_get_free_bytes() {
|
2011-11-30 09:07:02 +08:00
|
|
|
return asanThreadRegistry().GetFreeBytes();
|
|
|
|
}
|
|
|
|
|
2012-05-31 22:11:07 +08:00
|
|
|
uptr __asan_get_unmapped_bytes() {
|
2011-11-30 09:07:02 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __asan_print_accumulated_stats() {
|
|
|
|
PrintAccumulatedStats();
|
|
|
|
}
|