v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
tracing-category-observer.cc
Go to the documentation of this file.
1// Copyright 2016 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
6
8#include "src/init/v8.h"
12
13namespace v8 {
14namespace tracing {
15
16TracingCategoryObserver* TracingCategoryObserver::instance_ = nullptr;
17
20#if defined(V8_USE_PERFETTO)
21 TrackEvent::AddSessionObserver(instance_);
22 // Fire the observer if tracing is already in progress.
23 if (TrackEvent::IsEnabled()) instance_->OnStart({});
24#else
25 i::V8::GetCurrentPlatform()->GetTracingController()->AddTraceStateObserver(
27#endif
28}
29
31#if defined(V8_USE_PERFETTO)
32 TrackEvent::RemoveSessionObserver(TracingCategoryObserver::instance_);
33#else
34 i::V8::GetCurrentPlatform()->GetTracingController()->RemoveTraceStateObserver(
36#endif
38}
39
40#if defined(V8_USE_PERFETTO)
41void TracingCategoryObserver::OnStart(
42 const perfetto::DataSourceBase::StartArgs&) {
43#else
45#endif
46 bool enabled = false;
48 TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"), &enabled);
49 if (enabled) {
50 i::TracingFlags::runtime_stats.fetch_or(ENABLED_BY_TRACING,
51 std::memory_order_relaxed);
52 }
54 TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats_sampling"), &enabled);
55 if (enabled) {
56 i::TracingFlags::runtime_stats.fetch_or(ENABLED_BY_SAMPLING,
57 std::memory_order_relaxed);
58 }
60 &enabled);
61 if (enabled) {
62 i::TracingFlags::gc.fetch_or(ENABLED_BY_TRACING, std::memory_order_relaxed);
63 }
65 &enabled);
66 if (enabled) {
67 i::TracingFlags::gc_stats.fetch_or(ENABLED_BY_TRACING,
68 std::memory_order_relaxed);
69 }
71 &enabled);
72 if (enabled) {
73 i::TracingFlags::ic_stats.fetch_or(ENABLED_BY_TRACING,
74 std::memory_order_relaxed);
75 }
76
78 &enabled);
79 if (enabled) {
80 i::TracingFlags::zone_stats.fetch_or(ENABLED_BY_TRACING,
81 std::memory_order_relaxed);
82 }
83}
84
85#if defined(V8_USE_PERFETTO)
86void TracingCategoryObserver::OnStop(
87 const perfetto::DataSourceBase::StopArgs&) {
88#else
90#endif
91 i::TracingFlags::runtime_stats.fetch_and(
92 ~(ENABLED_BY_TRACING | ENABLED_BY_SAMPLING), std::memory_order_relaxed);
93
94 i::TracingFlags::gc.fetch_and(~ENABLED_BY_TRACING, std::memory_order_relaxed);
95
96 i::TracingFlags::gc_stats.fetch_and(~ENABLED_BY_TRACING,
97 std::memory_order_relaxed);
98
99 i::TracingFlags::ic_stats.fetch_and(~ENABLED_BY_TRACING,
100 std::memory_order_relaxed);
101}
102
103} // namespace tracing
104} // namespace v8
static TracingCategoryObserver * instance_
#define TRACE_DISABLED_BY_DEFAULT(name)
#define TRACE_EVENT_CATEGORY_GROUP_ENABLED(category_group, ret)