From 75485ef77d7538ccdf2f118b548da3a2821d5fd1 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 da8ca222b3361f..f0a8f2631f2398 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 b79f6a2ed0dbeb..f833354b4207d3 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 08751165547b0c..82f68f1b11989c 100644 --- a/src/env.h +++ b/src/env.h @@ -596,8 +596,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, @@ -633,7 +632,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; @@ -920,7 +918,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 a71ae26ef6ff0a..0764adc10bc9e0 100644 --- a/src/node.cc +++ b/src/node.cc @@ -379,6 +379,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 @@ -2763,8 +2767,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; } @@ -2834,7 +2837,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 6a26b8820be647..b3070198529b19 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -486,6 +486,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 6530bdb04c44e8..ce60cde2d0d433 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 debec3078c55d9..cb6adbeba34adc 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);