summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/cppgc/heap-statistics-collector.h
blob: c0b1fe7c6320ac1335e61bf3faf18baaeb5c0000 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_HEAP_CPPGC_HEAP_STATISTICS_COLLECTOR_H_
#define V8_HEAP_CPPGC_HEAP_STATISTICS_COLLECTOR_H_

#include <unordered_map>

#include "include/cppgc/heap-statistics.h"
#include "src/heap/cppgc/heap-visitor.h"

namespace cppgc {
namespace internal {

class HeapStatisticsCollector : private HeapVisitor<HeapStatisticsCollector> {
  friend class HeapVisitor<HeapStatisticsCollector>;

 public:
  HeapStatistics CollectDetailedStatistics(HeapBase*);

 private:
  bool VisitNormalPageSpace(NormalPageSpace&);
  bool VisitLargePageSpace(LargePageSpace&);
  bool VisitNormalPage(NormalPage&);
  bool VisitLargePage(LargePage&);
  bool VisitHeapObjectHeader(HeapObjectHeader&);

  HeapStatistics* current_stats_;
  HeapStatistics::SpaceStatistics* current_space_stats_ = nullptr;
  HeapStatistics::PageStatistics* current_page_stats_ = nullptr;
  // Index from type name to final index in `HeapStats::type_names`.
  // Canonicalizing based on `const char*` assuming stable addresses. If the
  // implementation of `NameProvider` decides to return different type name
  // c-strings, the final outcome is less compact.
  std::unordered_map<const char*, size_t> type_name_to_index_map_;
};

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_HEAP_STATISTICS_COLLECTOR_H_