diff --git a/BUILD.gn b/BUILD.gn index 580956498d..81f4bf9106 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2630,6 +2630,8 @@ v8_source_set("v8_base_without_compiler") { "src/logging/log.cc", "src/logging/log.h", "src/logging/off-thread-logger.h", + "src/logging/tracing-flags.cc", + "src/logging/tracing-flags.h", "src/numbers/bignum-dtoa.cc", "src/numbers/bignum-dtoa.h", "src/numbers/bignum.cc", diff --git a/src/api/api.cc b/src/api/api.cc index 0f41b923e8..09d269b962 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -11,11 +11,10 @@ #include // For move #include -#include "src/api/api-inl.h" - #include "include/v8-fast-api-calls.h" #include "include/v8-profiler.h" #include "include/v8-util.h" +#include "src/api/api-inl.h" #include "src/api/api-natives.h" #include "src/base/functional.h" #include "src/base/logging.h" @@ -58,6 +57,7 @@ #include "src/json/json-parser.h" #include "src/json/json-stringifier.h" #include "src/logging/counters.h" +#include "src/logging/tracing-flags.h" #include "src/numbers/conversions-inl.h" #include "src/objects/api-callbacks.h" #include "src/objects/contexts.h" diff --git a/src/flags/flag-definitions.h b/src/flags/flag-definitions.h index a8df928467..aef7ce0c06 100644 --- a/src/flags/flag-definitions.h +++ b/src/flags/flag-definitions.h @@ -965,6 +965,10 @@ DEFINE_BOOL(track_gc_object_stats, false, DEFINE_BOOL(trace_gc_object_stats, false, "trace object counts and memory usage") DEFINE_BOOL(trace_zone_stats, false, "trace zone memory usage") +DEFINE_GENERIC_IMPLICATION( + trace_zone_stats, + TracingFlags::zone_stats.store( + v8::tracing::TracingCategoryObserver::ENABLED_BY_NATIVE)) DEFINE_BOOL(track_retaining_path, false, "enable support for tracking retaining path") DEFINE_DEBUG_BOOL(trace_backing_store, false, "trace backing store events") diff --git a/src/logging/counters-inl.h b/src/logging/counters-inl.h index 3b4acf1f93..3e067c7c06 100644 --- a/src/logging/counters-inl.h +++ b/src/logging/counters-inl.h @@ -6,6 +6,7 @@ #define V8_LOGGING_COUNTERS_INL_H_ #include "src/logging/counters.h" +#include "src/logging/tracing-flags.h" namespace v8 { namespace internal { diff --git a/src/logging/counters.cc b/src/logging/counters.cc index 21248389b2..386bb8a75a 100644 --- a/src/logging/counters.cc +++ b/src/logging/counters.cc @@ -17,11 +17,6 @@ namespace v8 { namespace internal { -std::atomic_uint TracingFlags::runtime_stats{0}; -std::atomic_uint TracingFlags::gc{0}; -std::atomic_uint TracingFlags::gc_stats{0}; -std::atomic_uint TracingFlags::ic_stats{0}; - StatsTable::StatsTable(Counters* counters) : lookup_function_(nullptr), create_histogram_function_(nullptr), diff --git a/src/logging/counters.h b/src/logging/counters.h index 02a6feee2e..5002d6e9a1 100644 --- a/src/logging/counters.h +++ b/src/logging/counters.h @@ -16,6 +16,7 @@ #include "src/execution/isolate.h" #include "src/init/heap-symbols.h" #include "src/logging/counters-definitions.h" +#include "src/logging/tracing-flags.h" #include "src/objects/objects.h" #include "src/runtime/runtime.h" #include "src/tracing/trace-event.h" @@ -26,33 +27,6 @@ namespace v8 { namespace internal { -// This struct contains a set of flags that can be modified from multiple -// threads at runtime unlike the normal FLAG_-like flags which are not modified -// after V8 instance is initialized. - -struct TracingFlags { - static V8_EXPORT_PRIVATE std::atomic_uint runtime_stats; - static V8_EXPORT_PRIVATE std::atomic_uint gc; - static V8_EXPORT_PRIVATE std::atomic_uint gc_stats; - static V8_EXPORT_PRIVATE std::atomic_uint ic_stats; - - static bool is_runtime_stats_enabled() { - return runtime_stats.load(std::memory_order_relaxed) != 0; - } - - static bool is_gc_enabled() { - return gc.load(std::memory_order_relaxed) != 0; - } - - static bool is_gc_stats_enabled() { - return gc_stats.load(std::memory_order_relaxed) != 0; - } - - static bool is_ic_stats_enabled() { - return ic_stats.load(std::memory_order_relaxed) != 0; - } -}; - // StatsCounters is an interface for plugging into external // counters for monitoring. Counters can be looked up and // manipulated by name. diff --git a/src/logging/log-utils.h b/src/logging/log-utils.h index e89a449f3b..bae665cd45 100644 --- a/src/logging/log-utils.h +++ b/src/logging/log-utils.h @@ -37,7 +37,7 @@ class Log { FLAG_log_suspect || FLAG_ll_prof || FLAG_perf_basic_prof || FLAG_perf_prof || FLAG_log_source_code || FLAG_gdbjit || FLAG_log_internal_timer_events || FLAG_prof_cpp || FLAG_trace_ic || - FLAG_log_function_events; + FLAG_log_function_events || FLAG_trace_zone_stats; } // Frees all resources acquired in Initialize and Open... functions. diff --git a/src/logging/tracing-flags.cc b/src/logging/tracing-flags.cc new file mode 100644 index 0000000000..930469fde7 --- /dev/null +++ b/src/logging/tracing-flags.cc @@ -0,0 +1,17 @@ +// Copyright 2020 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. + +#include "src/logging/tracing-flags.h" + +namespace v8 { +namespace internal { + +std::atomic_uint TracingFlags::runtime_stats{0}; +std::atomic_uint TracingFlags::gc{0}; +std::atomic_uint TracingFlags::gc_stats{0}; +std::atomic_uint TracingFlags::ic_stats{0}; +std::atomic_uint TracingFlags::zone_stats{0}; + +} // namespace internal +} // namespace v8 diff --git a/src/logging/tracing-flags.h b/src/logging/tracing-flags.h new file mode 100644 index 0000000000..b23ed03a20 --- /dev/null +++ b/src/logging/tracing-flags.h @@ -0,0 +1,50 @@ +// Copyright 2020 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_LOGGING_TRACING_FLAGS_H_ +#define V8_LOGGING_TRACING_FLAGS_H_ + +#include + +#include "src/base/macros.h" + +namespace v8 { +namespace internal { + +// This struct contains a set of flags that can be modified from multiple +// threads at runtime unlike the normal FLAG_-like flags which are not modified +// after V8 instance is initialized. + +struct TracingFlags { + static V8_EXPORT_PRIVATE std::atomic_uint runtime_stats; + static V8_EXPORT_PRIVATE std::atomic_uint gc; + static V8_EXPORT_PRIVATE std::atomic_uint gc_stats; + static V8_EXPORT_PRIVATE std::atomic_uint ic_stats; + static V8_EXPORT_PRIVATE std::atomic_uint zone_stats; + + static bool is_runtime_stats_enabled() { + return runtime_stats.load(std::memory_order_relaxed) != 0; + } + + static bool is_gc_enabled() { + return gc.load(std::memory_order_relaxed) != 0; + } + + static bool is_gc_stats_enabled() { + return gc_stats.load(std::memory_order_relaxed) != 0; + } + + static bool is_ic_stats_enabled() { + return ic_stats.load(std::memory_order_relaxed) != 0; + } + + static bool is_zone_stats_enabled() { + return zone_stats.load(std::memory_order_relaxed) != 0; + } +}; + +} // namespace internal +} // namespace v8 + +#endif // V8_LOGGING_TRACING_FLAGS_H_ diff --git a/src/tracing/trace-categories.h b/src/tracing/trace-categories.h index 4ad9693515..4382178c56 100644 --- a/src/tracing/trace-categories.h +++ b/src/tracing/trace-categories.h @@ -47,6 +47,7 @@ PERFETTO_DEFINE_CATEGORIES( perfetto::Category(TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats_sampling")), perfetto::Category(TRACE_DISABLED_BY_DEFAULT("v8.turbofan")), perfetto::Category(TRACE_DISABLED_BY_DEFAULT("v8.wasm")), + perfetto::Category(TRACE_DISABLED_BY_DEFAULT("v8.zone_stats")), perfetto::Category::Group("v8,devtools.timeline"), perfetto::Category::Group(TRACE_DISABLED_BY_DEFAULT("v8.turbofan") "," TRACE_DISABLED_BY_DEFAULT("v8.wasm"))); diff --git a/src/tracing/tracing-category-observer.cc b/src/tracing/tracing-category-observer.cc index a44074d52d..3debacb548 100644 --- a/src/tracing/tracing-category-observer.cc +++ b/src/tracing/tracing-category-observer.cc @@ -57,6 +57,13 @@ void TracingCategoryObserver::OnTraceEnabled() { i::TracingFlags::ic_stats.fetch_or(ENABLED_BY_TRACING, std::memory_order_relaxed); } + + TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("v8.zone_stats"), + &enabled); + if (enabled) { + i::TracingFlags::zone_stats.fetch_or(ENABLED_BY_TRACING, + std::memory_order_relaxed); + } } void TracingCategoryObserver::OnTraceDisabled() {