Commit 6df8096a authored by lpy's avatar lpy Committed by Commit bot

[Tracing] Implement TracingCategoryObserver.

This patch implements TracingCategoryObserver to set global flag when a V8
specific category is enabled. Previously, we set a global flag each time when we
encounter a top level trace event, and use it as a global check. With this
patch, we can set a group of flags when tracing is enabled; besides, we make
V8 tracing feature use V8 flags instead of defining its own flag in a messy way.

With this patch, whatever V8 flag we want to imply in tracing, we define another
integer flag, and the original V8 flag will set it to 0x01 when passing by
commandline, tracing will set it to 0x10 when we start tracing and reset the bit
when we stop tracing.

Review-Url: https://codereview.chromium.org/2436273002
Cr-Commit-Position: refs/heads/master@{#40659}
parent aee3542f
......@@ -852,6 +852,7 @@ v8_source_set("v8_base") {
"include/v8-platform.h",
"include/v8-profiler.h",
"include/v8-testing.h",
"include/v8-tracing.h",
"include/v8-util.h",
"include/v8-version.h",
"include/v8.h",
......@@ -1674,6 +1675,8 @@ v8_source_set("v8_base") {
"src/tracing/trace-event.h",
"src/tracing/traced-value.cc",
"src/tracing/traced-value.h",
"src/tracing/tracing-category-observer.cc",
"src/tracing/tracing-category-observer.h",
"src/transitions-inl.h",
"src/transitions.cc",
"src/transitions.h",
......
// Copyright 2016 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_V8_TRACING_H_
#define V8_V8_TRACING_H_
#include "v8.h" // NOLINT(build/include)
namespace v8 {
namespace tracing {
class V8_EXPORT TracingCategoryObserver {
public:
enum Mode {
ENABLED_BY_NATIVE = 1 << 0,
ENABLED_BY_TRACING = 1 << 1,
};
static std::unique_ptr<TracingCategoryObserver> Create();
virtual ~TracingCategoryObserver() = default;
protected:
TracingCategoryObserver() = default;
};
} // namespace tracing
} // namespace v8
#endif // V8_V8_TRACING_H_
......@@ -22,6 +22,7 @@
#include "include/libplatform/libplatform.h"
#include "include/libplatform/v8-tracing.h"
#include "include/v8-tracing.h"
#include "src/api.h"
#include "src/base/cpu.h"
#include "src/base/debug/stack_trace.h"
......@@ -152,7 +153,7 @@ class PredictablePlatform : public Platform {
v8::Platform* g_platform = NULL;
std::unique_ptr<tracing::TracingCategoryObserver> g_tracing_category_observer;
static Local<Value> Throw(Isolate* isolate, const char* message) {
return isolate->ThrowException(
......@@ -2878,10 +2879,14 @@ int Shell::Main(int argc, char* argv[]) {
platform::tracing::TraceConfig::CreateDefaultTraceConfig();
}
tracing_controller->Initialize(trace_buffer);
tracing_controller->StartTracing(trace_config);
if (!i::FLAG_verify_predictable) {
platform::SetTracingController(g_platform, tracing_controller);
}
g_tracing_category_observer = tracing::TracingCategoryObserver::Create();
g_platform->AddTraceStateObserver(
reinterpret_cast<Platform::TraceStateObserver*>(
g_tracing_category_observer.get()));
tracing_controller->StartTracing(trace_config);
}
if (options.dump_heap_constants) {
......@@ -2942,6 +2947,9 @@ int Shell::Main(int argc, char* argv[]) {
isolate->Dispose();
V8::Dispose();
V8::ShutdownPlatform();
g_platform->RemoveTraceStateObserver(
reinterpret_cast<Platform::TraceStateObserver*>(
g_tracing_category_observer.get()));
delete g_platform;
return result;
......
......@@ -886,6 +886,9 @@ DEFINE_BOOL(print_all_exceptions, false,
// runtime.cc
DEFINE_BOOL(runtime_call_stats, false, "report runtime call counts and times")
DEFINE_INT(runtime_stats, 0,
"internal usage only for controlling runtime statistics")
DEFINE_VALUE_IMPLICATION(runtime_call_stats, runtime_stats, 1)
// snapshot-common.cc
DEFINE_BOOL(profile_deserialization, false,
......
// Copyright 2016 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/tracing/tracing-category-observer.h"
#include "include/v8.h"
#include "src/flags.h"
#include "src/tracing/trace-event.h"
#include "src/v8.h"
namespace v8 {
namespace tracing {
std::unique_ptr<TracingCategoryObserver> TracingCategoryObserver::Create() {
return std::unique_ptr<TracingCategoryObserver>(
new TracingCategoryObserverImpl());
}
TracingCategoryObserverImpl::TracingCategoryObserverImpl() {}
TracingCategoryObserverImpl::~TracingCategoryObserverImpl() {
OnTraceDisabled();
}
void TracingCategoryObserverImpl::OnTraceEnabled() {
bool enabled = false;
TRACE_EVENT_CATEGORY_GROUP_ENABLED(
TRACE_DISABLED_BY_DEFAULT("v8.runtime_stats"), &enabled);
if (enabled) {
v8::internal::FLAG_runtime_stats |= ENABLED_BY_TRACING;
}
}
void TracingCategoryObserverImpl::OnTraceDisabled() {
v8::internal::FLAG_runtime_stats &= ~ENABLED_BY_TRACING;
}
} // namespace tracing
} // namespace v8
// Copyright 2016 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_TRACING_TRACING_CATEGORY_OBSERVER_H_
#define V8_TRACING_TRACING_CATEGORY_OBSERVER_H_
#include "include/v8-platform.h"
#include "include/v8-tracing.h"
namespace v8 {
namespace tracing {
class TracingCategoryObserverImpl : public TracingCategoryObserver,
public Platform::TraceStateObserver {
public:
TracingCategoryObserverImpl();
~TracingCategoryObserverImpl();
// v8::Platform::TraceStateObserver
void OnTraceEnabled() final;
void OnTraceDisabled() final;
};
} // namespace tracing
} // namespace v8
#endif // V8_TRACING_TRACING_CATEGORY_OBSERVER_H_
......@@ -392,6 +392,7 @@
'../include/v8-platform.h',
'../include/v8-profiler.h',
'../include/v8-testing.h',
'../include/v8-tracing.h',
'../include/v8-util.h',
'../include/v8-version.h',
'../include/v8.h',
......@@ -1214,6 +1215,8 @@
'tracing/trace-event.h',
'tracing/traced-value.cc',
'tracing/traced-value.h',
'tracing/tracing-category-observer.cc',
'tracing/tracing-category-observer.h',
'transitions-inl.h',
'transitions.cc',
'transitions.h',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment