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 GCCycle { 24 enum class Type { kMinor, kMajor }; 25 struct IncrementalPhases { 26 int64_t mark_duration_us = -1; 27 int64_t sweep_duration_us = -1; 28 }; 29 struct Phases : public IncrementalPhases { 30 int64_t weak_duration_us = -1; 31 int64_t compact_duration_us = -1; 32 }; 33 struct Sizes { 34 int64_t before_bytes = -1; 35 int64_t after_bytes = -1; 36 int64_t freed_bytes = -1; 37 }; 38 39 Type type = Type::kMajor; 40 Phases total; 41 Phases main_thread; 42 Phases main_thread_atomic; 43 IncrementalPhases main_thread_incremental; 44 Sizes objects; 45 Sizes memory; 46 double collection_rate_in_percent; 47 double efficiency_in_bytes_per_us; 48 double main_thread_efficiency_in_bytes_per_us; 49 }; 50 51 struct MainThreadIncrementalMark { 52 int64_t duration_us = -1; 53 }; 54 55 struct MainThreadIncrementalSweep { 56 int64_t duration_us = -1; 57 }; 58 59 virtual ~MetricRecorder() = default; 60 AddMainThreadEvent(const GCCycle & event)61 virtual void AddMainThreadEvent(const GCCycle& event) {} AddMainThreadEvent(const MainThreadIncrementalMark & event)62 virtual void AddMainThreadEvent(const MainThreadIncrementalMark& event) {} AddMainThreadEvent(const MainThreadIncrementalSweep & event)63 virtual void AddMainThreadEvent(const MainThreadIncrementalSweep& event) {} 64 }; 65 66 } // namespace internal 67 } // namespace cppgc 68 69 #endif // V8_HEAP_CPPGC_METRIC_RECORDER_H_ 70