metric-recorder.h 1.82 KB
Newer Older
Omer Katz's avatar
Omer Katz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// 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_METRIC_RECORDER_H_
#define V8_HEAP_CPPGC_METRIC_RECORDER_H_

#include <cstdint>

namespace cppgc {
namespace internal {

class StatsCollector;

/**
 * Base class used for reporting GC statistics histograms. Embedders interested
17
 * in collecting histograms should implement the virtual AddMainThreadEvent
Omer Katz's avatar
Omer Katz committed
18 19 20 21 22
 * methods below and pass an instance of the implementation during Heap
 * creation.
 */
class MetricRecorder {
 public:
23 24
  struct GCCycle {
    enum class Type { kMinor, kMajor };
25
    struct IncrementalPhases {
26 27
      int64_t mark_duration_us = -1;
      int64_t sweep_duration_us = -1;
28 29
    };
    struct Phases : public IncrementalPhases {
30 31
      int64_t weak_duration_us = -1;
      int64_t compact_duration_us = -1;
32 33
    };
    struct Sizes {
34 35 36
      int64_t before_bytes = -1;
      int64_t after_bytes = -1;
      int64_t freed_bytes = -1;
37 38
    };

39
    Type type = Type::kMajor;
40 41 42 43 44 45 46 47 48
    Phases total;
    Phases main_thread;
    Phases main_thread_atomic;
    IncrementalPhases main_thread_incremental;
    Sizes objects;
    Sizes memory;
    double collection_rate_in_percent;
    double efficiency_in_bytes_per_us;
    double main_thread_efficiency_in_bytes_per_us;
Omer Katz's avatar
Omer Katz committed
49 50
  };

51 52
  struct MainThreadIncrementalMark {
    int64_t duration_us = -1;
Omer Katz's avatar
Omer Katz committed
53 54
  };

55 56
  struct MainThreadIncrementalSweep {
    int64_t duration_us = -1;
Omer Katz's avatar
Omer Katz committed
57 58 59 60
  };

  virtual ~MetricRecorder() = default;

61
  virtual void AddMainThreadEvent(const GCCycle& event) {}
62 63
  virtual void AddMainThreadEvent(const MainThreadIncrementalMark& event) {}
  virtual void AddMainThreadEvent(const MainThreadIncrementalSweep& event) {}
Omer Katz's avatar
Omer Katz committed
64 65 66 67 68 69
};

}  // namespace internal
}  // namespace cppgc

#endif  // V8_HEAP_CPPGC_METRIC_RECORDER_H_