Line data Source code
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 :
5 : #include "src/tracing/tracing-category-observer.h"
6 :
7 : #include "src/base/atomic-utils.h"
8 : #include "src/counters.h"
9 : #include "src/tracing/trace-event.h"
10 : #include "src/v8.h"
11 :
12 : namespace v8 {
13 : namespace tracing {
14 :
15 : TracingCategoryObserver* TracingCategoryObserver::instance_ = nullptr;
16 :
17 60098 : void TracingCategoryObserver::SetUp() {
18 120196 : TracingCategoryObserver::instance_ = new TracingCategoryObserver();
19 120196 : i::V8::GetCurrentPlatform()->GetTracingController()->AddTraceStateObserver(
20 120196 : TracingCategoryObserver::instance_);
21 60098 : }
22 :
23 58953 : void TracingCategoryObserver::TearDown() {
24 117906 : i::V8::GetCurrentPlatform()->GetTracingController()->RemoveTraceStateObserver(
25 117906 : TracingCategoryObserver::instance_);
26 58953 : delete TracingCategoryObserver::instance_;
27 58953 : }
28 :
29 6 : void TracingCategoryObserver::OnTraceEnabled() {
30 : bool enabled = false;
31 12 : TRACE_EVENT_CATEGORY_GROUP_ENABLED(
32 : TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"), &enabled);
33 6 : if (enabled) {
34 : i::TracingFlags::runtime_stats.fetch_or(ENABLED_BY_TRACING,
35 : std::memory_order_relaxed);
36 : }
37 12 : TRACE_EVENT_CATEGORY_GROUP_ENABLED(
38 : TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats_sampling"), &enabled);
39 6 : if (enabled) {
40 : i::TracingFlags::runtime_stats.fetch_or(ENABLED_BY_SAMPLING,
41 : std::memory_order_relaxed);
42 : }
43 12 : TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("v8.gc_stats"),
44 : &enabled);
45 6 : if (enabled) {
46 : i::TracingFlags::gc_stats.fetch_or(ENABLED_BY_TRACING,
47 : std::memory_order_relaxed);
48 : }
49 12 : TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("v8.ic_stats"),
50 : &enabled);
51 6 : if (enabled) {
52 : i::TracingFlags::ic_stats.fetch_or(ENABLED_BY_TRACING,
53 : std::memory_order_relaxed);
54 : }
55 6 : }
56 :
57 5 : void TracingCategoryObserver::OnTraceDisabled() {
58 : i::TracingFlags::runtime_stats.fetch_and(
59 : ~(ENABLED_BY_TRACING | ENABLED_BY_SAMPLING), std::memory_order_relaxed);
60 :
61 : i::TracingFlags::gc_stats.fetch_and(~ENABLED_BY_TRACING,
62 : std::memory_order_relaxed);
63 :
64 : i::TracingFlags::ic_stats.fetch_and(~ENABLED_BY_TRACING,
65 : std::memory_order_relaxed);
66 5 : }
67 :
68 : } // namespace tracing
69 120216 : } // namespace v8
|