Commit 44823c3c authored by fmeawad's avatar fmeawad Committed by Commit bot

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.

BUG=v8:4565
LOG=N

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

Cr-Commit-Position: refs/heads/master@{#34092}
parent 0f94e0d3
......@@ -150,6 +150,20 @@ class Platform {
* used by the trace macros. The returned handle can be used by
* 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.
*/
virtual uint64_t AddTraceEvent(
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,
......
......@@ -58,6 +58,7 @@
#include "src/snapshot/natives.h"
#include "src/snapshot/snapshot.h"
#include "src/startup-data-util.h"
#include "src/tracing/trace-event.h"
#include "src/unicode-inl.h"
#include "src/v8.h"
#include "src/v8threads.h"
......@@ -79,6 +80,7 @@ namespace v8 {
if (IsExecutionTerminatingCheck(isolate)) { \
return bailout_value; \
} \
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate); \
HandleScopeClass handle_scope(isolate); \
CallDepthScope call_depth_scope(isolate, context, do_callback); \
LOG_API(isolate, function_name); \
......@@ -195,6 +197,7 @@ class CallDepthScope {
static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate,
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> source_map_url(script->source_mapping_url(), isolate);
v8::Isolate* v8_isolate =
......@@ -373,6 +376,7 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
ArrayBufferAllocator allocator;
internal_isolate->set_array_buffer_allocator(&allocator);
Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate);
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
StartupData result = {NULL, 0};
{
base::ElapsedTimer timer;
......@@ -1850,6 +1854,7 @@ MaybeLocal<Script> ScriptCompiler::CompileModule(Local<Context> context,
CompileOptions options) {
CHECK(i::FLAG_harmony_modules);
auto isolate = context->GetIsolate();
TRACE_EVENT_SCOPED_CONTEXT("V8", "Isolate", isolate);
auto maybe = CompileUnboundInternal(isolate, source, options, true);
Local<UnboundScript> generic;
if (!maybe.ToLocal(&generic)) return MaybeLocal<Script>();
......@@ -2276,6 +2281,7 @@ void v8::TryCatch::SetCaptureMessage(bool value) {
Local<String> Message::Get() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
i::Handle<i::Object> obj = Utils::OpenHandle(this);
......@@ -2302,6 +2308,7 @@ v8::Local<Value> Message::GetScriptResourceName() const {
v8::Local<v8::StackTrace> Message::GetStackTrace() const {
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
ENTER_V8(isolate);
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this));
......@@ -5510,6 +5517,7 @@ Local<Context> v8::Context::New(v8::Isolate* external_isolate,
v8::Local<ObjectTemplate> global_template,
v8::Local<Value> global_object) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
LOG_API(isolate, "Context::New");
i::HandleScope scope(isolate);
ExtensionConfiguration no_extensions;
......@@ -7148,6 +7156,7 @@ Isolate* Isolate::GetCurrent() {
Isolate* Isolate::New(const Isolate::CreateParams& params) {
i::Isolate* isolate = new i::Isolate(false);
Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
TRACE_EVENT_SCOPED_CONTEXT("v8", "Isolate", isolate);
CHECK(params.array_buffer_allocator != NULL);
isolate->set_array_buffer_allocator(params.array_buffer_allocator);
if (params.snapshot_blob != NULL) {
......
......@@ -137,8 +137,8 @@ class PredictablePlatform : public Platform {
}
uint64_t AddTraceEvent(char phase, const uint8_t* categoryEnabledFlag,
const char* name, uint64_t id, uint64_t bind_id,
int numArgs, const char** argNames,
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;
......
......@@ -172,8 +172,9 @@ double DefaultPlatform::MonotonicallyIncreasingTime() {
uint64_t DefaultPlatform::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) {
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;
}
......
......@@ -47,9 +47,10 @@ class DefaultPlatform : public Platform {
const char* GetCategoryGroupName(
const uint8_t* category_enabled_flag) override;
uint64_t AddTraceEvent(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,
const uint8_t* arg_types, const uint64_t* arg_values,
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;
void UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
const char* name, uint64_t handle) override;
......
......@@ -38,6 +38,9 @@ void Logger::CallEventLogger(Isolate* isolate, const char* name, StartEnd se,
isolate->event_logger()(name, se);
}
}
// We make 2 different macro calls instead of precalculating the category
// name because the category enabled status is cached based on its line no.
if (expose_to_api) {
if (se == START) {
TRACE_EVENT_BEGIN0("v8", name);
......
This diff is collapsed.
......@@ -256,3 +256,27 @@ TEST(TestEventWithId) {
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