memprof_stats.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //===-- memprof_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 MemProfiler, a memory profiler.
  10. //
  11. // MemProf-private header for statistics.
  12. //===----------------------------------------------------------------------===//
  13. #ifndef MEMPROF_STATS_H
  14. #define MEMPROF_STATS_H
  15. #include "memprof_allocator.h"
  16. #include "memprof_internal.h"
  17. namespace __memprof {
  18. // MemprofStats struct is NOT thread-safe.
  19. // Each MemprofThread has its own MemprofStats, which are sometimes flushed
  20. // to the accumulated MemprofStats.
  21. struct MemprofStats {
  22. // MemprofStats must be a struct consisting of uptr fields only.
  23. // When merging two MemprofStats structs, we treat them as arrays of uptr.
  24. uptr mallocs;
  25. uptr malloced;
  26. uptr malloced_overhead;
  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 MemprofStats (accumulated stats for dead threads).
  40. explicit MemprofStats(LinkerInitialized) {}
  41. // Creates empty stats.
  42. MemprofStats();
  43. void Print(); // Prints formatted stats to stderr.
  44. void Clear();
  45. void MergeFrom(const MemprofStats *stats);
  46. };
  47. // Returns stats for GetCurrentThread(), or stats for fake "unknown thread"
  48. // if GetCurrentThread() returns 0.
  49. MemprofStats &GetCurrentThreadStats();
  50. // Flushes a given stats into accumulated stats of dead threads.
  51. void FlushToDeadThreadStats(MemprofStats *stats);
  52. } // namespace __memprof
  53. #endif // MEMPROF_STATS_H