Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ static node_module* modlist_builtin;
static node_module* modlist_internal;
static node_module* modlist_linked;
static node_module* modlist_addon;
static bool trace_forced = false;
static bool trace_enabled = false;
static std::string trace_enabled_categories; // NOLINT(runtime/string)
static bool abort_on_uncaught_exception = false;
Expand Down Expand Up @@ -331,6 +332,16 @@ static struct {
tracing_agent_->Stop();
}

void SetTracingAgent(tracing::Agent* agent) {
if (agent) {
tracing_agent_.reset(agent);
platform_->SetTracingController(agent->GetTracingController());
} else {
tracing_agent_.reset(nullptr);
platform_->SetTracingController(nullptr);
}
}

NodePlatform* Platform() {
return platform_;
}
Expand All @@ -353,6 +364,7 @@ static struct {
"so event tracing is not available.\n");
}
void StopTracingAgent() {}
void SetTracingAgent(tracing::Agent* agent) {}

NodePlatform* Platform() {
return nullptr;
Expand Down Expand Up @@ -1996,6 +2008,35 @@ static void Exit(const FunctionCallbackInfo<Value>& args) {
}


static void StartTracingAgent(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
if (!trace_enabled) {
if (args[0]->IsString()) {
Utf8Value categories(env->isolate(), args[0]);
trace_enabled_categories = *categories;
}
trace_enabled = true;
tracing::Agent* agent = new tracing::Agent();
v8_platform.SetTracingAgent(agent);
tracing::TraceEventHelper::SetTracingController(
agent->GetTracingController());
v8_platform.StartTracingAgent();
return args.GetReturnValue().Set(true);
}
args.GetReturnValue().Set(false);
}

static void StopTracingAgent(const FunctionCallbackInfo<Value>& args) {
if (trace_enabled && !trace_forced) {
v8_platform.StopTracingAgent();
v8_platform.SetTracingAgent(nullptr);
tracing::TraceEventHelper::SetTracingController(nullptr);
trace_enabled = false;
return args.GetReturnValue().Set(true);
}
args.GetReturnValue().Set(false);
}

static void Uptime(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
double uptime;
Expand Down Expand Up @@ -3234,6 +3275,9 @@ void SetupProcessObject(Environment* env,
env->SetMethod(process, "uptime", Uptime);
env->SetMethod(process, "memoryUsage", MemoryUsage);

env->SetMethod(process, "startTracingAgent", StartTracingAgent);
env->SetMethod(process, "stopTracingAgent", StopTracingAgent);

env->SetMethod(process, "binding", Binding);
env->SetMethod(process, "_linkedBinding", LinkedBinding);
env->SetMethod(process, "_internalBinding", InternalBinding);
Expand Down Expand Up @@ -3667,6 +3711,7 @@ static void ParseArgs(int* argc,
} else if (strcmp(arg, "--no-force-async-hooks-checks") == 0) {
no_force_async_hooks_checks = true;
} else if (strcmp(arg, "--trace-events-enabled") == 0) {
trace_forced = true;
trace_enabled = true;
} else if (strcmp(arg, "--trace-event-categories") == 0) {
const char* categories = argv[index + 1];
Expand Down
15 changes: 9 additions & 6 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ int PerIsolatePlatformData::unref() {

NodePlatform::NodePlatform(int thread_pool_size,
TracingController* tracing_controller) {
if (tracing_controller) {
tracing_controller_.reset(tracing_controller);
} else {
TracingController* controller = new TracingController();
tracing_controller_.reset(controller);
}
SetTracingController(tracing_controller);
background_task_runner_ =
std::make_shared<BackgroundTaskRunner>(thread_pool_size);
}
Expand Down Expand Up @@ -287,6 +282,14 @@ TracingController* NodePlatform::GetTracingController() {
return tracing_controller_.get();
}

void NodePlatform::SetTracingController(v8::TracingController* controller) {
if (controller) {
tracing_controller_.reset(controller);
} else {
tracing_controller_.reset(new TracingController());
}
}

template <class T>
TaskQueue<T>::TaskQueue()
: lock_(), tasks_available_(), tasks_drained_(),
Expand Down
1 change: 1 addition & 0 deletions src/node_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class NodePlatform : public MultiIsolatePlatform {
double MonotonicallyIncreasingTime() override;
double CurrentClockTimeMillis() override;
v8::TracingController* GetTracingController() override;
void SetTracingController(v8::TracingController* controller);

void FlushForegroundTasks(v8::Isolate* isolate);

Expand Down