From 506161009444ba05d56414217af8f17790d8f2b8 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 20 Oct 2018 11:02:37 +0200 Subject: [PATCH] src: remove `Environment::tracing_agent_writer()` As per the conversation in https://github.com/nodejs/node/issues/22513, this is essentially global, and adding this on the Environment is generally just confusing. Refs: https://github.com/nodejs/node/issues/22513 Fixes: https://github.com/nodejs/node/issues/22767 PR-URL: https://github.com/nodejs/node/pull/23781 Reviewed-By: Refael Ackermann Reviewed-By: Richard Lau Reviewed-By: Matheus Marchini --- src/env-inl.h | 4 ---- src/env.cc | 16 +++++++--------- src/env.h | 5 +---- src/inspector/tracing_agent.cc | 5 +++-- src/node.cc | 9 ++++++--- src/node_internals.h | 2 ++ src/node_trace_events.cc | 8 ++++---- src/node_worker.cc | 4 +--- 8 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/env-inl.h b/src/env-inl.h index 70a8e052258531..ba5704ed2e9574 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -334,10 +334,6 @@ inline v8::Isolate* Environment::isolate() const { return isolate_; } -inline tracing::AgentWriterHandle* Environment::tracing_agent_writer() const { - return tracing_agent_writer_; -} - inline Environment* Environment::from_timer_handle(uv_timer_t* handle) { return ContainerOf(&Environment::timer_handle_, handle); } diff --git a/src/env.cc b/src/env.cc index 727d13b98b13a1..5c46a56d7730ef 100644 --- a/src/env.cc +++ b/src/env.cc @@ -143,11 +143,9 @@ void Environment::TrackingTraceStateObserver::UpdateTraceCategoryState() { } Environment::Environment(IsolateData* isolate_data, - Local context, - tracing::AgentWriterHandle* tracing_agent_writer) + Local context) : isolate_(context->GetIsolate()), isolate_data_(isolate_data), - tracing_agent_writer_(tracing_agent_writer), immediate_info_(context->GetIsolate()), tick_info_(context->GetIsolate()), timer_base_(uv_now(isolate_data->event_loop())), @@ -183,10 +181,9 @@ Environment::Environment(IsolateData* isolate_data, AssignToContext(context, ContextInfo("")); - if (tracing_agent_writer_ != nullptr) { + if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) { trace_state_observer_.reset(new TrackingTraceStateObserver(this)); - v8::TracingController* tracing_controller = - tracing_agent_writer_->GetTracingController(); + v8::TracingController* tracing_controller = writer->GetTracingController(); if (tracing_controller != nullptr) tracing_controller->AddTraceStateObserver(trace_state_observer_.get()); } @@ -235,9 +232,10 @@ Environment::~Environment() { context()->SetAlignedPointerInEmbedderData( ContextEmbedderIndex::kEnvironment, nullptr); - if (tracing_agent_writer_ != nullptr) { - v8::TracingController* tracing_controller = - tracing_agent_writer_->GetTracingController(); + if (trace_state_observer_) { + tracing::AgentWriterHandle* writer = GetTracingAgentWriter(); + CHECK_NOT_NULL(writer); + v8::TracingController* tracing_controller = writer->GetTracingController(); if (tracing_controller != nullptr) tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get()); } diff --git a/src/env.h b/src/env.h index 42a76c1fbe8928..0b8da0c23c1791 100644 --- a/src/env.h +++ b/src/env.h @@ -595,8 +595,7 @@ class Environment { static inline Environment* GetThreadLocalEnv(); Environment(IsolateData* isolate_data, - v8::Local context, - tracing::AgentWriterHandle* tracing_agent_writer); + v8::Local context); ~Environment(); void Start(const std::vector& args, @@ -632,7 +631,6 @@ class Environment { inline bool profiler_idle_notifier_started() const; inline v8::Isolate* isolate() const; - inline tracing::AgentWriterHandle* tracing_agent_writer() const; inline uv_loop_t* event_loop() const; inline uint32_t watched_providers() const; @@ -923,7 +921,6 @@ class Environment { v8::Isolate* const isolate_; IsolateData* const isolate_data_; - tracing::AgentWriterHandle* const tracing_agent_writer_; uv_timer_t timer_handle_; uv_check_t immediate_check_handle_; uv_idle_t immediate_idle_handle_; diff --git a/src/inspector/tracing_agent.cc b/src/inspector/tracing_agent.cc index fe69e6f863e2a6..1ad67d9b9e7f71 100644 --- a/src/inspector/tracing_agent.cc +++ b/src/inspector/tracing_agent.cc @@ -1,4 +1,5 @@ #include "tracing_agent.h" +#include "node_internals.h" #include "env-inl.h" #include "v8.h" @@ -74,9 +75,9 @@ DispatchResponse TracingAgent::start( if (categories_set.empty()) return DispatchResponse::Error("At least one category should be enabled"); - auto* writer = env_->tracing_agent_writer(); + tracing::AgentWriterHandle* writer = GetTracingAgentWriter(); if (writer != nullptr) { - trace_writer_ = env_->tracing_agent_writer()->agent()->AddClient( + trace_writer_ = writer->agent()->AddClient( categories_set, std::unique_ptr( new InspectorTraceWriter(frontend_.get())), diff --git a/src/node.cc b/src/node.cc index af11953250ec11..faef976e974b4c 100644 --- a/src/node.cc +++ b/src/node.cc @@ -399,6 +399,10 @@ static struct { #endif // !NODE_USE_V8_PLATFORM || !HAVE_INSPECTOR } v8_platform; +tracing::AgentWriterHandle* GetTracingAgentWriter() { + return v8_platform.GetTracingAgentWriter(); +} + #ifdef __POSIX__ static const unsigned kMaxSignal = 32; #endif @@ -2442,8 +2446,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data, // options than the global parse call. std::vector args(argv, argv + argc); std::vector exec_args(exec_argv, exec_argv + exec_argc); - Environment* env = new Environment(isolate_data, context, - v8_platform.GetTracingAgentWriter()); + Environment* env = new Environment(isolate_data, context); env->Start(args, exec_args, v8_is_profiling); return env; } @@ -2515,7 +2518,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, HandleScope handle_scope(isolate); Local context = NewContext(isolate); Context::Scope context_scope(context); - Environment env(isolate_data, context, v8_platform.GetTracingAgentWriter()); + Environment env(isolate_data, context); env.Start(args, exec_args, v8_is_profiling); const char* path = args.size() > 1 ? args[1].c_str() : nullptr; diff --git a/src/node_internals.h b/src/node_internals.h index 9d419f01f3925b..cdb7492f437d5c 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -501,6 +501,8 @@ int ThreadPoolWork::CancelWork() { return uv_cancel(reinterpret_cast(&work_req_)); } +tracing::AgentWriterHandle* GetTracingAgentWriter(); + static inline const char* errno_string(int errorno) { #define ERRNO_CASE(e) case e: return #e; switch (errorno) { diff --git a/src/node_trace_events.cc b/src/node_trace_events.cc index f51db62ba38ac4..eea9fc612e578e 100644 --- a/src/node_trace_events.cc +++ b/src/node_trace_events.cc @@ -57,7 +57,7 @@ void NodeCategorySet::New(const FunctionCallbackInfo& args) { if (!*val) return; categories.emplace(*val); } - CHECK_NOT_NULL(env->tracing_agent_writer()); + CHECK_NOT_NULL(GetTracingAgentWriter()); new NodeCategorySet(env, args.This(), std::move(categories)); } @@ -68,7 +68,7 @@ void NodeCategorySet::Enable(const FunctionCallbackInfo& args) { CHECK_NOT_NULL(category_set); const auto& categories = category_set->GetCategories(); if (!category_set->enabled_ && !categories.empty()) { - env->tracing_agent_writer()->Enable(categories); + GetTracingAgentWriter()->Enable(categories); category_set->enabled_ = true; } } @@ -80,7 +80,7 @@ void NodeCategorySet::Disable(const FunctionCallbackInfo& args) { CHECK_NOT_NULL(category_set); const auto& categories = category_set->GetCategories(); if (category_set->enabled_ && !categories.empty()) { - env->tracing_agent_writer()->Disable(categories); + GetTracingAgentWriter()->Disable(categories); category_set->enabled_ = false; } } @@ -88,7 +88,7 @@ void NodeCategorySet::Disable(const FunctionCallbackInfo& args) { void GetEnabledCategories(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); std::string categories = - env->tracing_agent_writer()->agent()->GetEnabledCategories(); + GetTracingAgentWriter()->agent()->GetEnabledCategories(); if (!categories.empty()) { args.GetReturnValue().Set( String::NewFromUtf8(env->isolate(), diff --git a/src/node_worker.cc b/src/node_worker.cc index 38a92b34794dd2..e99ac59c01e06d 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -116,9 +116,7 @@ Worker::Worker(Environment* env, Local wrap, const std::string& url) Context::Scope context_scope(context); // TODO(addaleax): Use CreateEnvironment(), or generally another public API. - env_.reset(new Environment(isolate_data_.get(), - context, - nullptr)); + env_.reset(new Environment(isolate_data_.get(), context)); CHECK_NE(env_, nullptr); env_->set_abort_on_uncaught_exception(false); env_->set_worker_context(this);