Commit 567e5839 authored by fmeawad's avatar fmeawad Committed by Commit bot

Reland: Add Scoped Context Info (Isolate) to V8 Traces

This patch adds the newly added support for contexts in V8 Tracing, as well
as use it to mark all the entry points for a V8 Isolate.

Update for reland: The current tracing interface needs to be updated (AddTraceEvent),
but the embedders need to migrate to the new version before removing the old version.
(Reland of: https://codereview.chromium.org/1686233002)

The revert happened because the 2 signatures of the old and new AddTraceEvent where different
so it threw an overload-virtual error on cross arm debug. This issue is temporary, and to solve
it, I added an implementation of the old and new everywhere until the embedder implements the new.

BUG=v8:4565
LOG=N

R=jochen@chromium.org

Review URL: https://codereview.chromium.org/1704253002

Cr-Commit-Position: refs/heads/master@{#34332}
parent 23cf6592
...@@ -150,6 +150,21 @@ class Platform { ...@@ -150,6 +150,21 @@ class Platform {
* used by the trace macros. The returned handle can be used by * used by the trace macros. The returned handle can be used by
* UpdateTraceEventDuration to update the duration of COMPLETE events. * UpdateTraceEventDuration to update the duration of COMPLETE events.
*/ */
virtual uint64_t AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values, unsigned int flags) {
return AddTraceEvent(phase, category_enabled_flag, name, id, bind_id,
num_args, arg_names, arg_types, arg_values, flags);
}
/**
* This method will soon be depreacted in favor of the version with the 'const
* char* scope' parameter. If you do not already override this method, please
* implement the other version instead.
*/
// TODO(fmeawad): Remove once all embedders implement the scope version.
virtual uint64_t AddTraceEvent( virtual uint64_t AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name, char phase, const uint8_t* category_enabled_flag, const char* name,
uint64_t id, uint64_t bind_id, int32_t num_args, const char** arg_names, uint64_t id, uint64_t bind_id, int32_t num_args, const char** arg_names,
......
...@@ -81,6 +81,7 @@ namespace v8 { ...@@ -81,6 +81,7 @@ namespace v8 {
if (IsExecutionTerminatingCheck(isolate)) { \ if (IsExecutionTerminatingCheck(isolate)) { \
return bailout_value; \ return bailout_value; \
} \ } \
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); \
HandleScopeClass handle_scope(isolate); \ HandleScopeClass handle_scope(isolate); \
CallDepthScope call_depth_scope(isolate, context, do_callback); \ CallDepthScope call_depth_scope(isolate, context, do_callback); \
LOG_API(isolate, function_name); \ LOG_API(isolate, function_name); \
...@@ -198,6 +199,7 @@ class CallDepthScope { ...@@ -198,6 +199,7 @@ class CallDepthScope {
static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
i::Handle<i::Script> script) { i::Handle<i::Script> script) {
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script)); i::Handle<i::Object> scriptName(i::Script::GetNameOrSourceURL(script));
i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate); i::Handle<i::Object> source_map_url(script->source_mapping_url(), isolate);
v8::Isolate* v8_isolate = v8::Isolate* v8_isolate =
...@@ -376,6 +378,7 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) { ...@@ -376,6 +378,7 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
ArrayBufferAllocator allocator; ArrayBufferAllocator allocator;
internal_isolate->set_array_buffer_allocator(&allocator); internal_isolate->set_array_buffer_allocator(&allocator);
Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate);
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
StartupData result = {NULL, 0}; StartupData result = {NULL, 0};
{ {
base::ElapsedTimer timer; base::ElapsedTimer timer;
...@@ -1830,6 +1833,7 @@ MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context, ...@@ -1830,6 +1833,7 @@ MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context,
CompileOptions options) { CompileOptions options) {
CHECK(i::FLAG_harmony_modules); CHECK(i::FLAG_harmony_modules);
auto isolate = context->GetIsolate(); auto isolate = context->GetIsolate();
TRACE_EVENT_SCOPED_CONTEXT("V8", "Isolate", isolate);
auto maybe = CompileUnboundInternal(isolate, source, options, true); auto maybe = CompileUnboundInternal(isolate, source, options, true);
Local<UnboundScript> generic; Local<UnboundScript> generic;
if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>(); if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>();
...@@ -2256,6 +2260,7 @@ void v8::TryCatch::SetCaptureMessage(bool value) { ...@@ -2256,6 +2260,7 @@ void v8::TryCatch::SetCaptureMessage(bool value) {
Local<String> Message::Get() const { Local<String> Message::Get() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
ENTER_V8(isolate); ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::Object> obj = Utils::OpenHandle(this); i::Handle<i::Object> obj = Utils::OpenHandle(this);
...@@ -2282,6 +2287,7 @@ v8::Local<Value> Message::GetScriptResourceName() const { ...@@ -2282,6 +2287,7 @@ v8::Local<Value> Message::GetScriptResourceName() const {
v8::Local<v8::StackTrace> Message::GetStackTrace() const { v8::Local<v8::StackTrace> Message::GetStackTrace() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
ENTER_V8(isolate); ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
...@@ -5513,6 +5519,7 @@ Local<Context> v8::Context::New(v8::Isolate* external_isolate, ...@@ -5513,6 +5519,7 @@ Local<Context> v8::Context::New(v8::Isolate* external_isolate,
v8::Local<ObjectTemplate> global_template, v8::Local<ObjectTemplate> global_template,
v8::Local<Value> global_object) { v8::Local<Value> global_object) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
LOG_API(isolate, "Context::New"); LOG_API(isolate, "Context::New");
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
ExtensionConfiguration no_extensions; ExtensionConfiguration no_extensions;
...@@ -7151,6 +7158,7 @@ Isolate* Isolate::GetCurrent() { ...@@ -7151,6 +7158,7 @@ Isolate* Isolate::GetCurrent() {
Isolate* Isolate::New(const Isolate::CreateParams& params) { Isolate* Isolate::New(const Isolate::CreateParams& params) {
i::Isolate* isolate = new i::Isolate(false); i::Isolate* isolate = new i::Isolate(false);
Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
CHECK(params.array_buffer_allocator != NULL); CHECK(params.array_buffer_allocator != NULL);
isolate->set_array_buffer_allocator(params.array_buffer_allocator); isolate->set_array_buffer_allocator(params.array_buffer_allocator);
if (params.snapshot_blob != NULL) { if (params.snapshot_blob != NULL) {
......
...@@ -132,6 +132,15 @@ class PredictablePlatform : public Platform { ...@@ -132,6 +132,15 @@ class PredictablePlatform : public Platform {
return synthetic_time_in_sec_ += 0.00001; return synthetic_time_in_sec_ += 0.00001;
} }
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
const char* name, const char* scope, uint64_t id,
uint64_t bind_id, int numArgs, const char** argNames,
const uint8_t* argTypes, const uint64_t* argValues,
unsigned int flags) override {
return 0;
}
// TODO(fmeawad): Remove once all embedders implement the scope version.
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag, uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
const char* name, uint64_t id, uint64_t bind_id, const char* name, uint64_t id, uint64_t bind_id,
int numArgs, const char** argNames, int numArgs, const char** argNames,
......
...@@ -170,6 +170,16 @@ double DefaultPlatform::MonotonicallyIncreasingTime() { ...@@ -170,6 +170,16 @@ double DefaultPlatform::MonotonicallyIncreasingTime() {
} }
uint64_t DefaultPlatform::AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values, unsigned int flags) {
return 0;
}
// TODO(fmeawad): Remove once all embedders implement the scope version.
uint64_t DefaultPlatform::AddTraceEvent( uint64_t DefaultPlatform::AddTraceEvent(
char phase, const uint8_t* category_enabled_flag, const char* name, char phase, const uint8_t* category_enabled_flag, const char* name,
uint64_t id, uint64_t bind_id, int num_args, const char** arg_names, uint64_t id, uint64_t bind_id, int num_args, const char** arg_names,
...@@ -194,6 +204,7 @@ const char* DefaultPlatform::GetCategoryGroupName( ...@@ -194,6 +204,7 @@ const char* DefaultPlatform::GetCategoryGroupName(
return dummy; return dummy;
} }
size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() { size_t DefaultPlatform::NumberOfAvailableBackgroundThreads() {
return static_cast<size_t>(thread_pool_size_); return static_cast<size_t>(thread_pool_size_);
} }
......
...@@ -46,6 +46,13 @@ class DefaultPlatform : public Platform { ...@@ -46,6 +46,13 @@ class DefaultPlatform : public Platform {
const uint8_t* GetCategoryGroupEnabled(const char* name) override; const uint8_t* GetCategoryGroupEnabled(const char* name) override;
const char* GetCategoryGroupName( const char* GetCategoryGroupName(
const uint8_t* category_enabled_flag) override; const uint8_t* category_enabled_flag) override;
uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag,
const char* name, const char* scope, uint64_t id,
uint64_t bind_id, int32_t num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values,
unsigned int flags) override;
// TODO(fmeawad): Remove once all embedders implement the scope version.
uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag, uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag,
const char* name, uint64_t id, uint64_t bind_id, const char* name, uint64_t id, uint64_t bind_id,
int32_t num_args, const char** arg_names, int32_t num_args, const char** arg_names,
......
This diff is collapsed.
...@@ -85,6 +85,15 @@ class MockPlatform : public v8::Platform { ...@@ -85,6 +85,15 @@ class MockPlatform : public v8::Platform {
delete task; delete task;
} }
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
const char* name, const char* scope, uint64_t id,
uint64_t bind_id, int numArgs, const char** argNames,
const uint8_t* argTypes, const uint64_t* argValues,
unsigned int flags) override {
return 0;
}
// TODO(fmeawad): Remove once all embedders implement the scope version.
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag, uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
const char* name, uint64_t id, uint64_t bind_id, const char* name, uint64_t id, uint64_t bind_id,
int numArgs, const char** argNames, int numArgs, const char** argNames,
......
...@@ -72,8 +72,8 @@ class MockTracingPlatform : public v8::Platform { ...@@ -72,8 +72,8 @@ class MockTracingPlatform : public v8::Platform {
void PerformDelayedTask() {} void PerformDelayedTask() {}
uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag, uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag,
const char* name, uint64_t id, uint64_t bind_id, const char* name, const char* scope, uint64_t id,
int num_args, const char** arg_names, uint64_t bind_id, int num_args, const char** arg_names,
const uint8_t* arg_types, const uint64_t* arg_values, const uint8_t* arg_types, const uint64_t* arg_values,
unsigned int flags) override { unsigned int flags) override {
MockTraceObject* to = new MockTraceObject(phase, std::string(name), id, MockTraceObject* to = new MockTraceObject(phase, std::string(name), id,
...@@ -82,6 +82,15 @@ class MockTracingPlatform : public v8::Platform { ...@@ -82,6 +82,15 @@ class MockTracingPlatform : public v8::Platform {
return 0; return 0;
} }
// TODO(fmeawad): Remove once all embedders implement the scope version.
uint64_t AddTraceEvent(char phase, const uint8_t* category_enabled_flag,
const char* name, uint64_t id, uint64_t bind_id,
int num_args, const char** arg_names,
const uint8_t* arg_types, const uint64_t* arg_values,
unsigned int flags) override {
return 0;
}
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
const char* name, uint64_t handle) override {} const char* name, uint64_t handle) override {}
...@@ -256,3 +265,27 @@ TEST(TestEventWithId) { ...@@ -256,3 +265,27 @@ TEST(TestEventWithId) {
i::V8::SetPlatformForTesting(old_platform); i::V8::SetPlatformForTesting(old_platform);
} }
TEST(TestEventInContext) {
v8::Platform* old_platform = i::V8::GetCurrentPlatform();
MockTracingPlatform platform(old_platform);
i::V8::SetPlatformForTesting(&platform);
static uint64_t isolate_id = 0x20151021;
{
TRACE_EVENT_SCOPED_CONTEXT("v8-cat", "Isolate", isolate_id);
TRACE_EVENT0("v8-cat", "e");
}
CHECK_EQ(3, GET_TRACE_OBJECTS_LIST->length());
CHECK_EQ(TRACE_EVENT_PHASE_ENTER_CONTEXT, GET_TRACE_OBJECT(0)->phase);
CHECK_EQ("Isolate", GET_TRACE_OBJECT(0)->name);
CHECK_EQ(isolate_id, GET_TRACE_OBJECT(0)->id);
CHECK_EQ(TRACE_EVENT_PHASE_COMPLETE, GET_TRACE_OBJECT(1)->phase);
CHECK_EQ("e", GET_TRACE_OBJECT(1)->name);
CHECK_EQ(TRACE_EVENT_PHASE_LEAVE_CONTEXT, GET_TRACE_OBJECT(2)->phase);
CHECK_EQ("Isolate", GET_TRACE_OBJECT(2)->name);
CHECK_EQ(isolate_id, GET_TRACE_OBJECT(2)->id);
i::V8::SetPlatformForTesting(old_platform);
}
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