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 V8_HEAP_CPPGC_HEAP_STATISTICS_COLLECTOR_H_ 6 #define V8_HEAP_CPPGC_HEAP_STATISTICS_COLLECTOR_H_ 7 8 #include <unordered_map> 9 10 #include "include/cppgc/heap-statistics.h" 11 #include "src/heap/cppgc/heap-visitor.h" 12 13 namespace cppgc { 14 namespace internal { 15 16 class HeapStatisticsCollector : private HeapVisitor<HeapStatisticsCollector> { 17 friend class HeapVisitor<HeapStatisticsCollector>; 18 19 public: 20 HeapStatistics CollectDetailedStatistics(HeapBase*); 21 22 private: 23 bool VisitNormalPageSpace(NormalPageSpace&); 24 bool VisitLargePageSpace(LargePageSpace&); 25 bool VisitNormalPage(NormalPage&); 26 bool VisitLargePage(LargePage&); 27 bool VisitHeapObjectHeader(HeapObjectHeader&); 28 29 HeapStatistics* current_stats_; 30 HeapStatistics::SpaceStatistics* current_space_stats_ = nullptr; 31 HeapStatistics::PageStatistics* current_page_stats_ = nullptr; 32 // Index from type name to final index in `HeapStats::type_names`. 33 // Canonicalizing based on `const void*` assuming stable addresses. If the 34 // implementation of `NameProvider` decides to return different type name 35 // c-strings, the final outcome is less compact. 36 std::unordered_map<const void*, size_t> type_name_to_index_map_; 37 }; 38 39 } // namespace internal 40 } // namespace cppgc 41 42 #endif // V8_HEAP_CPPGC_HEAP_STATISTICS_COLLECTOR_H_ 43