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_METRIC_RECORDER_H_
6 #define V8_HEAP_CPPGC_METRIC_RECORDER_H_
7 
8 #include <cstdint>
9 
10 namespace cppgc {
11 namespace internal {
12 
13 class StatsCollector;
14 
15 /**
16  * Base class used for reporting GC statistics histograms. Embedders interested
17  * in collecting histograms should implement the virtual AddMainThreadEvent
18  * methods below and pass an instance of the implementation during Heap
19  * creation.
20  */
21 class MetricRecorder {
22  public:
23   struct FullCycle {
24     struct IncrementalPhases {
25       int64_t mark_duration_us = -1;
26       int64_t sweep_duration_us = -1;
27     };
28     struct Phases : public IncrementalPhases {
29       int64_t weak_duration_us = -1;
30       int64_t compact_duration_us = -1;
31     };
32     struct Sizes {
33       int64_t before_bytes = -1;
34       int64_t after_bytes = -1;
35       int64_t freed_bytes = -1;
36     };
37 
38     Phases total;
39     Phases main_thread;
40     Phases main_thread_atomic;
41     IncrementalPhases main_thread_incremental;
42     Sizes objects;
43     Sizes memory;
44     double collection_rate_in_percent;
45     double efficiency_in_bytes_per_us;
46     double main_thread_efficiency_in_bytes_per_us;
47   };
48 
49   struct MainThreadIncrementalMark {
50     int64_t duration_us = -1;
51   };
52 
53   struct MainThreadIncrementalSweep {
54     int64_t duration_us = -1;
55   };
56 
57   virtual ~MetricRecorder() = default;
58 
AddMainThreadEvent(const FullCycle & event)59   virtual void AddMainThreadEvent(const FullCycle& event) {}
AddMainThreadEvent(const MainThreadIncrementalMark & event)60   virtual void AddMainThreadEvent(const MainThreadIncrementalMark& event) {}
AddMainThreadEvent(const MainThreadIncrementalSweep & event)61   virtual void AddMainThreadEvent(const MainThreadIncrementalSweep& event) {}
62 };
63 
64 }  // namespace internal
65 }  // namespace cppgc
66 
67 #endif  // V8_HEAP_CPPGC_METRIC_RECORDER_H_
68