asan_stats.h 2.1 KB

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