|
| 1 | +// Copyright 2021 the V8 project 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 | + |
| 5 | +#ifndef INCLUDE_CPPGC_HEAP_STATISTICS_H_ |
| 6 | +#define INCLUDE_CPPGC_HEAP_STATISTICS_H_ |
| 7 | + |
| 8 | +#include <memory> |
| 9 | +#include <string> |
| 10 | +#include <vector> |
| 11 | + |
| 12 | +namespace cppgc { |
| 13 | + |
| 14 | +/** |
| 15 | + * `HeapStatistics` contains memory consumption and utilization statistics for a |
| 16 | + * cppgc heap. |
| 17 | + */ |
| 18 | +struct HeapStatistics final { |
| 19 | + /** |
| 20 | + * Specifies the detail level of the heap statistics. Brief statistics contain |
| 21 | + * only the top-level allocated and used memory statistics for the entire |
| 22 | + * heap. Detailed statistics also contain a break down per space and page, as |
| 23 | + * well as freelist statistics and object type histograms. Note that used |
| 24 | + * memory reported by brief statistics and detailed statistics might differ |
| 25 | + * slightly. |
| 26 | + */ |
| 27 | + enum DetailLevel : uint8_t { |
| 28 | + kBrief, |
| 29 | + kDetailed, |
| 30 | + }; |
| 31 | + |
| 32 | + /** |
| 33 | + * Statistics of object types. For each type the statistics record its name, |
| 34 | + * how many objects of that type were allocated, and the overall size used by |
| 35 | + * these objects. |
| 36 | + */ |
| 37 | + struct ObjectStatistics { |
| 38 | + /** Number of distinct types in the heap. */ |
| 39 | + size_t num_types = 0; |
| 40 | + /** Name of each type in the heap. */ |
| 41 | + std::vector<std::string> type_name; |
| 42 | + /** Number of allocated objects per each type. */ |
| 43 | + std::vector<size_t> type_count; |
| 44 | + /** Overall size of allocated objects per each type. */ |
| 45 | + std::vector<size_t> type_bytes; |
| 46 | + }; |
| 47 | + |
| 48 | + /** |
| 49 | + * Page granularity statistics. For each page the statistics record the |
| 50 | + * allocated memory size and overall used memory size for the page. |
| 51 | + */ |
| 52 | + struct PageStatistics { |
| 53 | + /** Overall amount of memory allocated for the page. */ |
| 54 | + size_t allocated_size_bytes = 0; |
| 55 | + /** Amount of memory actually used on the page. */ |
| 56 | + size_t used_size_bytes = 0; |
| 57 | + }; |
| 58 | + |
| 59 | + /** |
| 60 | + * Stastistics of the freelist (used only in non-large object spaces). For |
| 61 | + * each bucket in the freelist the statistics record the bucket size, the |
| 62 | + * number of freelist entries in the bucket, and the overall allocated memory |
| 63 | + * consumed by these freelist entries. |
| 64 | + */ |
| 65 | + struct FreeListStatistics { |
| 66 | + /** bucket sizes in the freelist. */ |
| 67 | + std::vector<size_t> bucket_size; |
| 68 | + /** number of freelist entries per bucket. */ |
| 69 | + std::vector<size_t> free_count; |
| 70 | + /** memory size concumed by freelist entries per size. */ |
| 71 | + std::vector<size_t> free_size; |
| 72 | + }; |
| 73 | + |
| 74 | + /** |
| 75 | + * Space granularity statistics. For each space the statistics record the |
| 76 | + * space name, the amount of allocated memory and overall used memory for the |
| 77 | + * space. The statistics also contain statistics for each of the space's |
| 78 | + * pages, its freelist and the objects allocated on the space. |
| 79 | + */ |
| 80 | + struct SpaceStatistics { |
| 81 | + /** The space name */ |
| 82 | + std::string name; |
| 83 | + /** Overall amount of memory allocated for the space. */ |
| 84 | + size_t allocated_size_bytes = 0; |
| 85 | + /** Amount of memory actually used on the space. */ |
| 86 | + size_t used_size_bytes = 0; |
| 87 | + /** Statistics for each of the pages in the space. */ |
| 88 | + std::vector<PageStatistics> page_stats; |
| 89 | + /** Statistics for the freelist of the space. */ |
| 90 | + FreeListStatistics free_list_stats; |
| 91 | + /** Statistics for object allocated on the space. Filled only when |
| 92 | + * NameProvider::HideInternalNames() is false. */ |
| 93 | + ObjectStatistics object_stats; |
| 94 | + }; |
| 95 | + |
| 96 | + /** Overall amount of memory allocated for the heap. */ |
| 97 | + size_t allocated_size_bytes = 0; |
| 98 | + /** Amount of memory actually used on the heap. */ |
| 99 | + size_t used_size_bytes = 0; |
| 100 | + /** Detail level of this HeapStatistics. */ |
| 101 | + DetailLevel detail_level; |
| 102 | + |
| 103 | + /** Statistics for each of the spaces in the heap. Filled only when |
| 104 | + * detail_level is kDetailed. */ |
| 105 | + std::vector<SpaceStatistics> space_stats; |
| 106 | +}; |
| 107 | + |
| 108 | +} // namespace cppgc |
| 109 | + |
| 110 | +#endif // INCLUDE_CPPGC_HEAP_STATISTICS_H_ |
0 commit comments