diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/node_trace_events.cc | 3 | ||||
-rw-r--r-- | src/node_v8_platform-inl.h | 16 | ||||
-rw-r--r-- | src/tracing/agent.h | 6 |
3 files changed, 21 insertions, 4 deletions
diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc index 9538e75d2c..6a0d4f037a 100644 --- a/src/node_trace_events.cc +++ b/src/node_trace_events.cc @@ -74,6 +74,9 @@ void NodeCategorySet::Enable(const FunctionCallbackInfo<Value>& args) { CHECK_NOT_NULL(category_set); const auto& categories = category_set->GetCategories(); if (!category_set->enabled_ && !categories.empty()) { + // Starts the Tracing Agent if it wasn't started already (e.g. through + // a command line flag.) + StartTracingAgent(); GetTracingAgentWriter()->Enable(categories); category_set->enabled_ = true; } diff --git a/src/node_v8_platform-inl.h b/src/node_v8_platform-inl.h index ed91ee3a02..2c89ee9e52 100644 --- a/src/node_v8_platform-inl.h +++ b/src/node_v8_platform-inl.h @@ -85,7 +85,11 @@ struct V8Platform { tracing_agent_->GetTracingController(); trace_state_observer_.reset(new NodeTraceStateObserver(controller)); controller->AddTraceStateObserver(trace_state_observer_.get()); - StartTracingAgent(); + tracing_file_writer_ = tracing_agent_->DefaultHandle(); + // Only start the tracing agent if we enabled any tracing categories. + if (!per_process::cli_options->trace_event_categories.empty()) { + StartTracingAgent(); + } // Tracing must be initialized before platform threads are created. platform_ = new NodePlatform(thread_pool_size, controller); v8::V8::InitializePlatform(platform_); @@ -111,9 +115,9 @@ struct V8Platform { } inline void StartTracingAgent() { - if (per_process::cli_options->trace_event_categories.empty()) { - tracing_file_writer_ = tracing_agent_->DefaultHandle(); - } else { + // Attach a new NodeTraceWriter only if this function hasn't been called + // before. + if (tracing_file_writer_.IsDefaultHandle()) { std::vector<std::string> categories = SplitString(per_process::cli_options->trace_event_categories, ','); @@ -163,6 +167,10 @@ namespace per_process { extern struct V8Platform v8_platform; } +inline void StartTracingAgent() { + return per_process::v8_platform.StartTracingAgent(); +} + inline tracing::AgentWriterHandle* GetTracingAgentWriter() { return per_process::v8_platform.GetTracingAgentWriter(); } diff --git a/src/tracing/agent.h b/src/tracing/agent.h index 2e95e38582..0039cc3679 100644 --- a/src/tracing/agent.h +++ b/src/tracing/agent.h @@ -59,6 +59,8 @@ class AgentWriterHandle { inline void Enable(const std::set<std::string>& categories); inline void Disable(const std::set<std::string>& categories); + inline bool IsDefaultHandle(); + inline Agent* agent() { return agent_; } inline v8::TracingController* GetTracingController(); @@ -175,6 +177,10 @@ void AgentWriterHandle::Disable(const std::set<std::string>& categories) { if (agent_ != nullptr) agent_->Disable(id_, categories); } +bool AgentWriterHandle::IsDefaultHandle() { + return agent_ != nullptr && id_ == Agent::kDefaultHandleId; +} + inline v8::TracingController* AgentWriterHandle::GetTracingController() { return agent_ != nullptr ? agent_->GetTracingController() : nullptr; } |