[zone-stats] Introduce v8.zone_stats tracing category

... in order to make it possible to collect zone memory usage stats
from Chrome.

Drive-by-cleanup: move TracingFlags definition to a separate file.

Bug: v8:10572
Change-Id: I05fb65e207d573d5c18821067cfff4c37f2d77cd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2226561
Reviewed-by: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68135}
This commit is contained in:
Igor Sheludko 2020-06-03 11:43:01 +02:00 committed by Commit Bot
parent ae489decb1
commit 0262bc10fc
11 changed files with 86 additions and 35 deletions

View File

@ -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",

View File

@ -11,11 +11,10 @@
#include <utility> // For move
#include <vector>
#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"

View File

@ -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")

View File

@ -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 {

View File

@ -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),

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -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 <atomic>
#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_

View File

@ -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")));

View File

@ -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() {