Skip to content

Commit 75485ef

Browse files
addaleaxtargos
authored andcommitted
src: remove Environment::tracing_agent_writer()
As per the conversation in #22513, this is essentially global, and adding this on the Environment is generally just confusing. Refs: #22513 Fixes: #22767 PR-URL: #23781 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Matheus Marchini <[email protected]>
1 parent 790755d commit 75485ef

8 files changed

+24
-29
lines changed

src/env-inl.h

-4
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,6 @@ inline v8::Isolate* Environment::isolate() const {
334334
return isolate_;
335335
}
336336

337-
inline tracing::AgentWriterHandle* Environment::tracing_agent_writer() const {
338-
return tracing_agent_writer_;
339-
}
340-
341337
inline Environment* Environment::from_timer_handle(uv_timer_t* handle) {
342338
return ContainerOf(&Environment::timer_handle_, handle);
343339
}

src/env.cc

+7-9
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,9 @@ void Environment::TrackingTraceStateObserver::UpdateTraceCategoryState() {
143143
}
144144

145145
Environment::Environment(IsolateData* isolate_data,
146-
Local<Context> context,
147-
tracing::AgentWriterHandle* tracing_agent_writer)
146+
Local<Context> context)
148147
: isolate_(context->GetIsolate()),
149148
isolate_data_(isolate_data),
150-
tracing_agent_writer_(tracing_agent_writer),
151149
immediate_info_(context->GetIsolate()),
152150
tick_info_(context->GetIsolate()),
153151
timer_base_(uv_now(isolate_data->event_loop())),
@@ -183,10 +181,9 @@ Environment::Environment(IsolateData* isolate_data,
183181

184182
AssignToContext(context, ContextInfo(""));
185183

186-
if (tracing_agent_writer_ != nullptr) {
184+
if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) {
187185
trace_state_observer_.reset(new TrackingTraceStateObserver(this));
188-
v8::TracingController* tracing_controller =
189-
tracing_agent_writer_->GetTracingController();
186+
v8::TracingController* tracing_controller = writer->GetTracingController();
190187
if (tracing_controller != nullptr)
191188
tracing_controller->AddTraceStateObserver(trace_state_observer_.get());
192189
}
@@ -235,9 +232,10 @@ Environment::~Environment() {
235232
context()->SetAlignedPointerInEmbedderData(
236233
ContextEmbedderIndex::kEnvironment, nullptr);
237234

238-
if (tracing_agent_writer_ != nullptr) {
239-
v8::TracingController* tracing_controller =
240-
tracing_agent_writer_->GetTracingController();
235+
if (trace_state_observer_) {
236+
tracing::AgentWriterHandle* writer = GetTracingAgentWriter();
237+
CHECK_NOT_NULL(writer);
238+
v8::TracingController* tracing_controller = writer->GetTracingController();
241239
if (tracing_controller != nullptr)
242240
tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get());
243241
}

src/env.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ class Environment {
596596
static inline Environment* GetThreadLocalEnv();
597597

598598
Environment(IsolateData* isolate_data,
599-
v8::Local<v8::Context> context,
600-
tracing::AgentWriterHandle* tracing_agent_writer);
599+
v8::Local<v8::Context> context);
601600
~Environment();
602601

603602
void Start(const std::vector<std::string>& args,
@@ -633,7 +632,6 @@ class Environment {
633632
inline bool profiler_idle_notifier_started() const;
634633

635634
inline v8::Isolate* isolate() const;
636-
inline tracing::AgentWriterHandle* tracing_agent_writer() const;
637635
inline uv_loop_t* event_loop() const;
638636
inline uint32_t watched_providers() const;
639637

@@ -920,7 +918,6 @@ class Environment {
920918

921919
v8::Isolate* const isolate_;
922920
IsolateData* const isolate_data_;
923-
tracing::AgentWriterHandle* const tracing_agent_writer_;
924921
uv_timer_t timer_handle_;
925922
uv_check_t immediate_check_handle_;
926923
uv_idle_t immediate_idle_handle_;

src/inspector/tracing_agent.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "tracing_agent.h"
2+
#include "node_internals.h"
23

34
#include "env-inl.h"
45
#include "v8.h"
@@ -74,9 +75,9 @@ DispatchResponse TracingAgent::start(
7475
if (categories_set.empty())
7576
return DispatchResponse::Error("At least one category should be enabled");
7677

77-
auto* writer = env_->tracing_agent_writer();
78+
tracing::AgentWriterHandle* writer = GetTracingAgentWriter();
7879
if (writer != nullptr) {
79-
trace_writer_ = env_->tracing_agent_writer()->agent()->AddClient(
80+
trace_writer_ = writer->agent()->AddClient(
8081
categories_set,
8182
std::unique_ptr<InspectorTraceWriter>(
8283
new InspectorTraceWriter(frontend_.get())),

src/node.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ static struct {
379379
#endif // !NODE_USE_V8_PLATFORM || !HAVE_INSPECTOR
380380
} v8_platform;
381381

382+
tracing::AgentWriterHandle* GetTracingAgentWriter() {
383+
return v8_platform.GetTracingAgentWriter();
384+
}
385+
382386
#ifdef __POSIX__
383387
static const unsigned kMaxSignal = 32;
384388
#endif
@@ -2763,8 +2767,7 @@ Environment* CreateEnvironment(IsolateData* isolate_data,
27632767
// options than the global parse call.
27642768
std::vector<std::string> args(argv, argv + argc);
27652769
std::vector<std::string> exec_args(exec_argv, exec_argv + exec_argc);
2766-
Environment* env = new Environment(isolate_data, context,
2767-
v8_platform.GetTracingAgentWriter());
2770+
Environment* env = new Environment(isolate_data, context);
27682771
env->Start(args, exec_args, v8_is_profiling);
27692772
return env;
27702773
}
@@ -2834,7 +2837,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data,
28342837
HandleScope handle_scope(isolate);
28352838
Local<Context> context = NewContext(isolate);
28362839
Context::Scope context_scope(context);
2837-
Environment env(isolate_data, context, v8_platform.GetTracingAgentWriter());
2840+
Environment env(isolate_data, context);
28382841
env.Start(args, exec_args, v8_is_profiling);
28392842

28402843
const char* path = args.size() > 1 ? args[1].c_str() : nullptr;

src/node_internals.h

+2
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ int ThreadPoolWork::CancelWork() {
486486
return uv_cancel(reinterpret_cast<uv_req_t*>(&work_req_));
487487
}
488488

489+
tracing::AgentWriterHandle* GetTracingAgentWriter();
490+
489491
static inline const char* errno_string(int errorno) {
490492
#define ERRNO_CASE(e) case e: return #e;
491493
switch (errorno) {

src/node_trace_events.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void NodeCategorySet::New(const FunctionCallbackInfo<Value>& args) {
5757
if (!*val) return;
5858
categories.emplace(*val);
5959
}
60-
CHECK_NOT_NULL(env->tracing_agent_writer());
60+
CHECK_NOT_NULL(GetTracingAgentWriter());
6161
new NodeCategorySet(env, args.This(), std::move(categories));
6262
}
6363

@@ -68,7 +68,7 @@ void NodeCategorySet::Enable(const FunctionCallbackInfo<Value>& args) {
6868
CHECK_NOT_NULL(category_set);
6969
const auto& categories = category_set->GetCategories();
7070
if (!category_set->enabled_ && !categories.empty()) {
71-
env->tracing_agent_writer()->Enable(categories);
71+
GetTracingAgentWriter()->Enable(categories);
7272
category_set->enabled_ = true;
7373
}
7474
}
@@ -80,15 +80,15 @@ void NodeCategorySet::Disable(const FunctionCallbackInfo<Value>& args) {
8080
CHECK_NOT_NULL(category_set);
8181
const auto& categories = category_set->GetCategories();
8282
if (category_set->enabled_ && !categories.empty()) {
83-
env->tracing_agent_writer()->Disable(categories);
83+
GetTracingAgentWriter()->Disable(categories);
8484
category_set->enabled_ = false;
8585
}
8686
}
8787

8888
void GetEnabledCategories(const FunctionCallbackInfo<Value>& args) {
8989
Environment* env = Environment::GetCurrent(args);
9090
std::string categories =
91-
env->tracing_agent_writer()->agent()->GetEnabledCategories();
91+
GetTracingAgentWriter()->agent()->GetEnabledCategories();
9292
if (!categories.empty()) {
9393
args.GetReturnValue().Set(
9494
String::NewFromUtf8(env->isolate(),

src/node_worker.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ Worker::Worker(Environment* env, Local<Object> wrap, const std::string& url)
116116
Context::Scope context_scope(context);
117117

118118
// TODO(addaleax): Use CreateEnvironment(), or generally another public API.
119-
env_.reset(new Environment(isolate_data_.get(),
120-
context,
121-
nullptr));
119+
env_.reset(new Environment(isolate_data_.get(), context));
122120
CHECK_NE(env_, nullptr);
123121
env_->set_abort_on_uncaught_exception(false);
124122
env_->set_worker_context(this);

0 commit comments

Comments
 (0)