| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 01d8b91 commit 5362fef
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -510,6 +510,15 @@ NODE_EXTERN MultiIsolatePlatform* CreatePlatform( | |||
| 510 | 510 | v8::TracingController* tracing_controller); | |
| 511 | 511 | NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform); | |
| 512 | 512 | ||
| 513 | + // Get/set the currently active tracing controller. Using CreatePlatform() | ||
| 514 | + // will implicitly set this by default. This is global and should be initialized | ||
| 515 | + // along with the v8::Platform instance that is being used. `controller` | ||
| 516 | + // is allowed to be `nullptr`. | ||
| 517 | + // This is used for tracing events from Node.js itself. V8 uses the tracing | ||
| 518 | + // controller returned from the active `v8::Platform` instance. | ||
| 519 | + NODE_EXTERN v8::TracingController* GetTracingController(); | ||
| 520 | + NODE_EXTERN void SetTracingController(v8::TracingController* controller); | ||
| 521 | + | ||
| 513 | 522 | NODE_EXTERN void EmitBeforeExit(Environment* env); | |
| 514 | 523 | NODE_EXTERN int EmitExit(Environment* env); | |
| 515 | 524 | NODE_EXTERN void RunAtExit(Environment* env); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -333,7 +333,8 @@ NodePlatform::NodePlatform(int thread_pool_size, | |||
| 333 | 333 | // TODO(addaleax): It's a bit icky that we use global state here, but we can't | |
| 334 | 334 | // really do anything about it unless V8 starts exposing a way to access the | |
| 335 | 335 | // current v8::Platform instance. | |
| 336 | - tracing::TraceEventHelper::SetTracingController(tracing_controller_); | ||
| 336 | + SetTracingController(tracing_controller_); | ||
| 337 | + DCHECK_EQ(GetTracingController(), tracing_controller_); | ||
| 337 | 338 | worker_thread_task_runner_ = | |
| 338 | 339 | std::make_shared<WorkerThreadsTaskRunner>(thread_pool_size); | |
| 339 | 340 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,7 +11,6 @@ | |||
| 11 | 11 | #include "libplatform/libplatform.h" | |
| 12 | 12 | #include "node.h" | |
| 13 | 13 | #include "node_mutex.h" | |
| 14 | - #include "tracing/agent.h" | ||
| 15 | 14 | #include "uv.h" | |
| 16 | 15 | ||
| 17 | 16 | namespace node { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ | |||
| 8 | 8 | #include "env-inl.h" | |
| 9 | 9 | #include "node.h" | |
| 10 | 10 | #include "node_metadata.h" | |
| 11 | + #include "node_platform.h" | ||
| 11 | 12 | #include "node_options.h" | |
| 12 | 13 | #include "tracing/node_trace_writer.h" | |
| 13 | 14 | #include "tracing/trace_event.h" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | #include "tracing/trace_event.h" | |
| 2 | + #include "node.h" | ||
| 2 | 3 | ||
| 3 | 4 | namespace node { | |
| 4 | 5 | namespace tracing { | |
@@ -24,4 +25,13 @@ void TraceEventHelper::SetTracingController(v8::TracingController* controller) { | |||
| 24 | 25 | } | |
| 25 | 26 | ||
| 26 | 27 | } // namespace tracing | |
| 28 | + | ||
| 29 | + v8::TracingController* GetTracingController() { | ||
| 30 | + return tracing::TraceEventHelper::GetTracingController(); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + void SetTracingController(v8::TracingController* controller) { | ||
| 34 | + tracing::TraceEventHelper::SetTracingController(controller); | ||
| 35 | + } | ||
| 36 | + | ||
| 27 | 37 | } // namespace node | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,8 @@ | |||
| 5 | 5 | #ifndef SRC_TRACING_TRACE_EVENT_H_ | |
| 6 | 6 | #define SRC_TRACING_TRACE_EVENT_H_ | |
| 7 | 7 | ||
| 8 | - #include "node_platform.h" | ||
| 9 | 8 | #include "v8-platform.h" | |
| 9 | + #include "tracing/agent.h" | ||
| 10 | 10 | #include "trace_event_common.h" | |
| 11 | 11 | #include <atomic> | |
| 12 | 12 | ||
@@ -310,9 +310,7 @@ const int kZeroNumArgs = 0; | |||
| 310 | 310 | const decltype(nullptr) kGlobalScope = nullptr; | |
| 311 | 311 | const uint64_t kNoId = 0; | |
| 312 | 312 | ||
| 313 | - // Extern (for now) because embedders need access to TraceEventHelper. | ||
| 314 | - // Refs: https://github.com/nodejs/node/pull/28724 | ||
| 315 | - class NODE_EXTERN TraceEventHelper { | ||
| 313 | + class TraceEventHelper { | ||
| 316 | 314 | public: | |
| 317 | 315 | static v8::TracingController* GetTracingController(); | |
| 318 | 316 | static void SetTracingController(v8::TracingController* controller); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -104,3 +104,22 @@ TEST_F(NodeZeroIsolateTestFixture, IsolatePlatformDelegateTest) { | |||
| 104 | 104 | platform->UnregisterIsolate(isolate); | |
| 105 | 105 | isolate->Dispose(); | |
| 106 | 106 | } | |
| 107 | + | ||
| 108 | + TEST_F(PlatformTest, TracingControllerNullptr) { | ||
| 109 | + v8::TracingController* orig_controller = node::GetTracingController(); | ||
| 110 | + node::SetTracingController(nullptr); | ||
| 111 | + EXPECT_EQ(node::GetTracingController(), nullptr); | ||
| 112 | + | ||
| 113 | + v8::Isolate::Scope isolate_scope(isolate_); | ||
| 114 | + const v8::HandleScope handle_scope(isolate_); | ||
| 115 | + const Argv argv; | ||
| 116 | + Env env {handle_scope, argv}; | ||
| 117 | + | ||
| 118 | + node::LoadEnvironment(*env, [&](const node::StartExecutionCallbackInfo& info) | ||
| 119 | + -> v8::MaybeLocal<v8::Value> { | ||
| 120 | + return v8::Null(isolate_); | ||
| 121 | + }); | ||
| 122 | + | ||
| 123 | + node::SetTracingController(orig_controller); | ||
| 124 | + EXPECT_EQ(node::GetTracingController(), orig_controller); | ||
| 125 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments