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/flags.h" 8 #include "src/tracing/trace-event.h" 9 #include "src/v8.h" 10 11 namespace v8 { 12 namespace tracing { 13 14 TracingCategoryObserver* TracingCategoryObserver::instance_ = nullptr; 15 16 void TracingCategoryObserver::SetUp() { 17 TracingCategoryObserver::instance_ = new TracingCategoryObserver(); 18 v8::internal::V8::GetCurrentPlatform()->AddTraceStateObserver( 19 TracingCategoryObserver::instance_); 20 TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats")); 21 TRACE_EVENT_WARMUP_CATEGORY( 22 TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats_sampling")); 23 TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.gc_stats")); 24 TRACE_EVENT_WARMUP_CATEGORY(TRACE_DISABLED_BY_DEFAULT("v8.ic_stats")); 25 } 26 27 void TracingCategoryObserver::TearDown() { 28 v8::internal::V8::GetCurrentPlatform()->RemoveTraceStateObserver( 29 TracingCategoryObserver::instance_); 30 delete TracingCategoryObserver::instance_; 31 } 32 33 void TracingCategoryObserver::OnTraceEnabled() { 34 bool enabled = false; 35 TRACE_EVENT_CATEGORY_GROUP_ENABLED( 36 TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"), &enabled); 37 if (enabled) { 38 v8::internal::FLAG_runtime_stats |= ENABLED_BY_TRACING; 39 } 40 TRACE_EVENT_CATEGORY_GROUP_ENABLED( 41 TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats_sampling"), &enabled); 42 if (enabled) { 43 v8::internal::FLAG_runtime_stats |= ENABLED_BY_SAMPLING; 44 } 45 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("v8.gc_stats"), 46 &enabled); 47 if (enabled) { 48 v8::internal::FLAG_gc_stats |= ENABLED_BY_TRACING; 49 } 50 TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("v8.ic_stats"), 51 &enabled); 52 if (enabled) { 53 v8::internal::FLAG_ic_stats |= ENABLED_BY_TRACING; 54 } 55 } 56 57 void TracingCategoryObserver::OnTraceDisabled() { 58 v8::internal::FLAG_runtime_stats &= 59 ~(ENABLED_BY_TRACING | ENABLED_BY_SAMPLING); 60 v8::internal::FLAG_gc_stats &= ~ENABLED_BY_TRACING; 61 v8::internal::FLAG_ic_stats &= ~ENABLED_BY_TRACING; 62 } 63 64 } // namespace tracing 65 } // namespace v8 66