v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
gc-tracer-inl.h
Go to the documentation of this file.
1// Copyright 2022 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_GC_TRACER_INL_H_
6#define V8_HEAP_GC_TRACER_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
11#include "src/base/logging.h"
14#include "src/heap/heap-inl.h"
15
16namespace v8 {
17namespace internal {
18
20 base::TimeDelta delta) {
21 steps++;
22 duration += delta;
23 if (delta > longest_step) {
24 longest_step = delta;
25 }
26 return *this;
27}
28
30 : tracer_(tracer),
31 scope_(scope),
32 thread_kind_(thread_kind),
33 start_time_(base::TimeTicks::Now()) {
36
37#ifdef V8_RUNTIME_CALL_STATS
38 if (V8_LIKELY(!TracingFlags::is_runtime_stats_enabled())) return;
40 runtime_stats_ = tracer_->heap_->isolate_->counters()->runtime_call_stats();
41 runtime_stats_->Enter(&timer_, GCTracer::RCSCounterFromScope(scope));
42 } else {
43 runtime_call_stats_scope_.emplace(
44 tracer->worker_thread_runtime_call_stats());
45 runtime_stats_ = runtime_call_stats_scope_->Get();
46 runtime_stats_->Enter(&timer_, GCTracer::RCSCounterFromScope(scope));
47 }
48#endif // defined(V8_RUNTIME_CALL_STATS)
49}
50
53 tracer_->AddScopeSample(scope_, duration);
54
55 if (thread_kind_ == ThreadKind::kMain) {
56 if (scope_ == ScopeId::MC_INCREMENTAL ||
57 scope_ == ScopeId::MC_INCREMENTAL_START) {
58 auto* long_task_stats =
59 tracer_->heap_->isolate_->GetCurrentLongTaskStats();
60 long_task_stats->gc_full_incremental_wall_clock_duration_us +=
61 duration.InMicroseconds();
62 }
63 }
64
65#ifdef V8_RUNTIME_CALL_STATS
66 if (V8_LIKELY(runtime_stats_ == nullptr)) return;
67 runtime_stats_->Leave(&timer_);
68#endif // defined(V8_RUNTIME_CALL_STATS)
69}
70
71constexpr const char* GCTracer::Scope::Name(ScopeId id) {
72#define CASE(scope) \
73 case Scope::scope: \
74 return "V8.GC_" #scope;
75 switch (id) {
78 default:
79 return nullptr;
80 }
81#undef CASE
82}
83
85#define CASE(scope) \
86 case Scope::scope: \
87 return true;
88 switch (id) {
90 default:
91 return false;
92 }
93#undef CASE
94}
95
97 DCHECK_LE(FIRST_INCREMENTAL_SCOPE, id);
98 DCHECK_GE(LAST_INCREMENTAL_SCOPE, id);
99 return id - FIRST_INCREMENTAL_SCOPE;
100}
101
103 DCHECK_NE(Type::START, type);
104 return type == Type::SCAVENGER || type == Type::MINOR_MARK_SWEEPER ||
105 type == Type::INCREMENTAL_MINOR_MARK_SWEEPER;
106}
107
111
113 DCHECK_GT(Scope::NUMBER_OF_SCOPES, id);
114 return current_.scopes[id].InMillisecondsF();
115}
116
121
126 } else if (Scope::FIRST_BACKGROUND_SCOPE <= id &&
129 background_scopes_[id] += duration;
130 } else {
131 DCHECK_GT(Scope::NUMBER_OF_SCOPES, id);
132 current_.scopes[id] += duration;
133 }
134}
135
136#ifdef V8_RUNTIME_CALL_STATS
137WorkerThreadRuntimeCallStats* GCTracer::worker_thread_runtime_call_stats() {
139}
140
141RuntimeCallCounterId GCTracer::RCSCounterFromScope(Scope::ScopeId id) {
142 static_assert(Scope::FIRST_SCOPE == Scope::MC_INCREMENTAL);
143 return static_cast<RuntimeCallCounterId>(
144 static_cast<int>(RuntimeCallCounterId::kGC_MC_INCREMENTAL) +
145 static_cast<int>(id));
146}
147#endif // defined(V8_RUNTIME_CALL_STATS)
148
149} // namespace internal
150} // namespace v8
151
152#endif // V8_HEAP_GC_TRACER_INL_H_
double InMillisecondsF() const
Definition time.cc:226
int64_t InMicroseconds() const
Definition time.cc:251
static TimeTicks Now()
Definition time.cc:736
WorkerThreadRuntimeCallStats * worker_thread_runtime_call_stats()
Definition counters.h:635
RuntimeCallStats * runtime_call_stats()
Definition counters.h:633
static V8_INLINE constexpr bool IsYoungGenerationEvent(Type type)
base::TimeDelta scopes[Scope::NUMBER_OF_SCOPES]
Definition gc-tracer.h:249
V8_INLINE Scope(GCTracer *tracer, ScopeId scope, ThreadKind thread_kind)
static constexpr bool NeedsYoungEpoch(ScopeId id)
const ThreadKind thread_kind_
Definition gc-tracer.h:150
static constexpr int IncrementalOffset(ScopeId id)
static constexpr const char * Name(ScopeId id)
base::TimeDelta background_scopes_[Scope::NUMBER_OF_SCOPES]
Definition gc-tracer.h:606
V8_INLINE void AddScopeSample(Scope::ScopeId id, base::TimeDelta duration)
V8_INLINE double current_scope(Scope::ScopeId id) const
V8_INLINE CollectionEpoch CurrentEpoch(Scope::ScopeId id) const
CollectionEpoch epoch_full_
Definition gc-tracer.h:525
V8_INLINE constexpr const IncrementalInfos & incremental_scope(Scope::ScopeId id) const
base::Mutex background_scopes_mutex_
Definition gc-tracer.h:605
CollectionEpoch epoch_young_
Definition gc-tracer.h:524
IncrementalInfos incremental_scopes_[Scope::NUMBER_OF_INCREMENTAL_SCOPES]
Definition gc-tracer.h:539
bool IsMainThread() const
Definition heap-inl.h:63
Isolate * isolate_
Definition heap.h:2077
Counters * counters()
Definition isolate.h:1180
DeclarationScope * scope_
#define TRACER_YOUNG_EPOCH_SCOPES(F)
#define TRACER_SCOPES(F)
#define TRACER_BACKGROUND_SCOPES(F)
base::ElapsedTimer timer_
base::TimeTicks start_time_
uint32_t CollectionEpoch
Definition gc-tracer.h:103
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK_NE(v1, v2)
Definition logging.h:486
#define DCHECK_GE(v1, v2)
Definition logging.h:488
#define DCHECK_GT(v1, v2)
Definition logging.h:487
constexpr V8_INLINE IncrementalInfos & operator+=(base::TimeDelta delta)
#define V8_LIKELY(condition)
Definition v8config.h:661