partition_stats.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_STATS_H_
  5. #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_STATS_H_
  6. #include <cstddef>
  7. #include <cstdint>
  8. #include "base/allocator/partition_allocator/partition_alloc_base/component_export.h"
  9. #include "base/allocator/partition_allocator/partition_alloc_config.h"
  10. #include "base/allocator/partition_allocator/partition_alloc_constants.h"
  11. namespace partition_alloc {
  12. // Most of these are not populated if PA_ENABLE_THREAD_CACHE_STATISTICS is not
  13. // defined.
  14. struct ThreadCacheStats {
  15. uint64_t alloc_count; // Total allocation requests.
  16. uint64_t alloc_hits; // Thread cache hits.
  17. uint64_t alloc_misses; // Thread cache misses.
  18. // Allocation failure details:
  19. uint64_t alloc_miss_empty;
  20. uint64_t alloc_miss_too_large;
  21. // Cache fill details:
  22. uint64_t cache_fill_count;
  23. uint64_t cache_fill_hits;
  24. uint64_t cache_fill_misses; // Object too large.
  25. uint64_t batch_fill_count; // Number of central allocator requests.
  26. // Memory cost:
  27. uint32_t bucket_total_memory;
  28. uint32_t metadata_overhead;
  29. #if defined(PA_THREAD_CACHE_ALLOC_STATS)
  30. uint64_t allocs_per_bucket_[internal::kNumBuckets + 1];
  31. #endif // defined(PA_THREAD_CACHE_ALLOC_STATS)
  32. };
  33. // Struct used to retrieve total memory usage of a partition. Used by
  34. // PartitionStatsDumper implementation.
  35. struct PartitionMemoryStats {
  36. size_t total_mmapped_bytes; // Total bytes mmap()-ed from the system.
  37. size_t total_committed_bytes; // Total size of committed pages.
  38. size_t max_committed_bytes; // Max size of committed pages.
  39. size_t total_allocated_bytes; // Total size of allcoations.
  40. size_t max_allocated_bytes; // Max size of allocations.
  41. size_t total_resident_bytes; // Total bytes provisioned by the partition.
  42. size_t total_active_bytes; // Total active bytes in the partition.
  43. size_t total_active_count; // Total count of active objects in the partition.
  44. size_t total_decommittable_bytes; // Total bytes that could be decommitted.
  45. size_t total_discardable_bytes; // Total bytes that could be discarded.
  46. #if BUILDFLAG(USE_BACKUP_REF_PTR)
  47. size_t
  48. total_brp_quarantined_bytes; // Total bytes that are quarantined by BRP.
  49. size_t total_brp_quarantined_count; // Total number of slots that are
  50. // quarantined by BRP.
  51. size_t cumulative_brp_quarantined_bytes; // Cumulative bytes that are
  52. // quarantined by BRP.
  53. size_t cumulative_brp_quarantined_count; // Cumulative number of slots that
  54. // are quarantined by BRP.
  55. #endif
  56. bool has_thread_cache;
  57. ThreadCacheStats current_thread_cache_stats;
  58. ThreadCacheStats all_thread_caches_stats;
  59. // Count and total duration of system calls made since process start. May not
  60. // be reported on all platforms.
  61. uint64_t syscall_count;
  62. uint64_t syscall_total_time_ns;
  63. };
  64. // Struct used to retrieve memory statistics about a partition bucket. Used by
  65. // PartitionStatsDumper implementation.
  66. struct PartitionBucketMemoryStats {
  67. bool is_valid; // Used to check if the stats is valid.
  68. bool is_direct_map; // True if this is a direct mapping; size will not be
  69. // unique.
  70. uint32_t bucket_slot_size; // The size of the slot in bytes.
  71. uint32_t allocated_slot_span_size; // Total size the slot span allocated
  72. // from the system (committed pages).
  73. uint32_t active_bytes; // Total active bytes used in the bucket.
  74. uint32_t active_count; // Total active objects allocated in the bucket.
  75. uint32_t resident_bytes; // Total bytes provisioned in the bucket.
  76. uint32_t decommittable_bytes; // Total bytes that could be decommitted.
  77. uint32_t discardable_bytes; // Total bytes that could be discarded.
  78. uint32_t num_full_slot_spans; // Number of slot spans with all slots
  79. // allocated.
  80. uint32_t num_active_slot_spans; // Number of slot spans that have at least
  81. // one provisioned slot.
  82. uint32_t num_empty_slot_spans; // Number of slot spans that are empty
  83. // but not decommitted.
  84. uint32_t num_decommitted_slot_spans; // Number of slot spans that are empty
  85. // and decommitted.
  86. };
  87. // Interface that is passed to PartitionDumpStats and
  88. // PartitionDumpStats for using the memory statistics.
  89. class PA_COMPONENT_EXPORT(PARTITION_ALLOC) PartitionStatsDumper {
  90. public:
  91. // Called to dump total memory used by partition, once per partition.
  92. virtual void PartitionDumpTotals(const char* partition_name,
  93. const PartitionMemoryStats*) = 0;
  94. // Called to dump stats about buckets, for each bucket.
  95. virtual void PartitionsDumpBucketStats(const char* partition_name,
  96. const PartitionBucketMemoryStats*) = 0;
  97. };
  98. // Simple version of PartitionStatsDumper, storing the returned stats in stats_.
  99. // Does not handle per-bucket stats.
  100. class PA_COMPONENT_EXPORT(PARTITION_ALLOC) SimplePartitionStatsDumper
  101. : public PartitionStatsDumper {
  102. public:
  103. SimplePartitionStatsDumper();
  104. void PartitionDumpTotals(const char* partition_name,
  105. const PartitionMemoryStats* memory_stats) override;
  106. void PartitionsDumpBucketStats(const char* partition_name,
  107. const PartitionBucketMemoryStats*) override {}
  108. const PartitionMemoryStats& stats() const { return stats_; }
  109. private:
  110. PartitionMemoryStats stats_;
  111. };
  112. } // namespace partition_alloc
  113. #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_STATS_H_