1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PARTITION_ALLOC_ADDRESS_SPACE_STATS_H_
6 #define PARTITION_ALLOC_ADDRESS_SPACE_STATS_H_
7 
8 #include <cstddef>
9 
10 #include "partition_alloc/partition_alloc_base/component_export.h"
11 #include "partition_alloc/partition_alloc_buildflags.h"
12 
13 namespace partition_alloc {
14 
15 // All members are measured in super pages.
16 struct PoolStats {
17   size_t usage = 0;
18 
19   // On 32-bit, pools are mainly logical entities, intermingled with
20   // allocations not managed by PartitionAlloc. The "largest available
21   // reservation" is not possible to measure in that case.
22 #if BUILDFLAG(HAS_64_BIT_POINTERS)
23   size_t largest_available_reservation = 0;
24 #endif
25 };
26 
27 struct AddressSpaceStats {
28   PoolStats regular_pool_stats;
29 #if BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT)
30   PoolStats brp_pool_stats;
31 #endif  // BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT)
32 #if BUILDFLAG(HAS_64_BIT_POINTERS)
33   PoolStats configurable_pool_stats;
34 #else
35 #if BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT)
36   size_t blocklist_size;  // measured in super pages
37   size_t blocklist_hit_count;
38 #endif  // BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT)
39 #endif  // BUILDFLAG(HAS_64_BIT_POINTERS)
40 #if BUILDFLAG(ENABLE_THREAD_ISOLATION)
41   PoolStats thread_isolated_pool_stats;
42 #endif
43 };
44 
45 // Interface passed to `AddressPoolManager::DumpStats()` to mediate
46 // for `AddressSpaceDumpProvider`.
PA_COMPONENT_EXPORT(PARTITION_ALLOC)47 class PA_COMPONENT_EXPORT(PARTITION_ALLOC) AddressSpaceStatsDumper {
48  public:
49   virtual void DumpStats(const AddressSpaceStats* address_space_stats) = 0;
50   virtual ~AddressSpaceStatsDumper() = default;
51 };
52 
53 }  // namespace partition_alloc
54 
55 #endif  // PARTITION_ALLOC_ADDRESS_SPACE_STATS_H_
56