GeezerVison is showing github.com — src: allow non-Node.js TracingControllers · cheza24/node@887b6a1
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/api/environment.cc +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -498,6 +498,14 @@ MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env) { | 498 | 498 | MultiIsolatePlatform* CreatePlatform( | 499 | 499 | int thread_pool_size, | 500 | 500 | node::tracing::TracingController* tracing_controller) { | | 501 | + return CreatePlatform( | | 502 | + thread_pool_size, | | 503 | + static_cast<v8::TracingController*>(tracing_controller)); | | 504 | +} | | 505 | + | | 506 | +MultiIsolatePlatform* CreatePlatform( | | 507 | + int thread_pool_size, | | 508 | + v8::TracingController* tracing_controller) { | 501 | 509 | return MultiIsolatePlatform::Create(thread_pool_size, tracing_controller) | 502 | 510 | .release(); | 503 | 511 | } | @@ -508,7 +516,7 @@ void FreePlatform(MultiIsolatePlatform* platform) { | 508 | 516 |
| 509 | 517 | std::unique_ptr<MultiIsolatePlatform> MultiIsolatePlatform::Create( | 510 | 518 | int thread_pool_size, | 511 | | - node::tracing::TracingController* tracing_controller) { | | 519 | + v8::TracingController* tracing_controller) { | 512 | 520 | return std::make_unique<NodePlatform>(thread_pool_size, tracing_controller); | 513 | 521 | } | 514 | 522 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/node.h +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -329,7 +329,7 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform { | 329 | 329 |
| 330 | 330 | static std::unique_ptr<MultiIsolatePlatform> Create( | 331 | 331 | int thread_pool_size, | 332 | | - node::tracing::TracingController* tracing_controller = nullptr); | | 332 | + v8::TracingController* tracing_controller = nullptr); | 333 | 333 | }; | 334 | 334 |
| 335 | 335 | enum IsolateSettingsFlags { | @@ -487,9 +487,13 @@ NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env); | 487 | 487 | NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env); | 488 | 488 |
| 489 | 489 | // Legacy variants of MultiIsolatePlatform::Create(). | | 490 | +// TODO(addaleax): Deprecate in favour of the v8::TracingController variant. | 490 | 491 | NODE_EXTERN MultiIsolatePlatform* CreatePlatform( | 491 | 492 | int thread_pool_size, | 492 | 493 | node::tracing::TracingController* tracing_controller); | | 494 | +NODE_EXTERN MultiIsolatePlatform* CreatePlatform( | | 495 | + int thread_pool_size, | | 496 | + v8::TracingController* tracing_controller); | 493 | 497 | NODE_EXTERN void FreePlatform(MultiIsolatePlatform* platform); | 494 | 498 |
| 495 | 499 | NODE_EXTERN void EmitBeforeExit(Environment* env); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_platform.cc +8-5Lines changed: 8 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,6 @@ using v8::Isolate; | 13 | 13 | using v8::Object; | 14 | 14 | using v8::Platform; | 15 | 15 | using v8::Task; | 16 | | -using node::tracing::TracingController; | 17 | 16 |
| 18 | 17 | namespace { | 19 | 18 |
| @@ -325,12 +324,16 @@ void PerIsolatePlatformData::DecreaseHandleCount() { | 325 | 324 | } | 326 | 325 |
| 327 | 326 | NodePlatform::NodePlatform(int thread_pool_size, | 328 | | - TracingController* tracing_controller) { | 329 | | - if (tracing_controller) { | | 327 | + v8::TracingController* tracing_controller) { | | 328 | + if (tracing_controller != nullptr) { | 330 | 329 | tracing_controller_ = tracing_controller; | 331 | 330 | } else { | 332 | | - tracing_controller_ = new TracingController(); | | 331 | + tracing_controller_ = new v8::TracingController(); | 333 | 332 | } | | 333 | + // TODO(addaleax): It's a bit icky that we use global state here, but we can't | | 334 | + // really do anything about it unless V8 starts exposing a way to access the | | 335 | + // current v8::Platform instance. | | 336 | + tracing::TraceEventHelper::SetTracingController(tracing_controller_); | 334 | 337 | worker_thread_task_runner_ = | 335 | 338 | std::make_shared<WorkerThreadsTaskRunner>(thread_pool_size); | 336 | 339 | } | @@ -518,7 +521,7 @@ double NodePlatform::CurrentClockTimeMillis() { | 518 | 521 | return SystemClockTimeMillis(); | 519 | 522 | } | 520 | 523 |
| 521 | | -TracingController* NodePlatform::GetTracingController() { | | 524 | +v8::TracingController* NodePlatform::GetTracingController() { | 522 | 525 | CHECK_NOT_NULL(tracing_controller_); | 523 | 526 | return tracing_controller_; | 524 | 527 | } | |
Collapse file Copy file name to clipboardExpand all lines: src/node_platform.h +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -139,7 +139,7 @@ class WorkerThreadsTaskRunner { | 139 | 139 | class NodePlatform : public MultiIsolatePlatform { | 140 | 140 | public: | 141 | 141 | NodePlatform(int thread_pool_size, | 142 | | - node::tracing::TracingController* tracing_controller); | | 142 | + v8::TracingController* tracing_controller); | 143 | 143 | ~NodePlatform() override = default; | 144 | 144 |
| 145 | 145 | void DrainTasks(v8::Isolate* isolate) override; | @@ -153,7 +153,7 @@ class NodePlatform : public MultiIsolatePlatform { | 153 | 153 | bool IdleTasksEnabled(v8::Isolate* isolate) override; | 154 | 154 | double MonotonicallyIncreasingTime() override; | 155 | 155 | double CurrentClockTimeMillis() override; | 156 | | - node::tracing::TracingController* GetTracingController() override; | | 156 | + v8::TracingController* GetTracingController() override; | 157 | 157 | bool FlushForegroundTasks(v8::Isolate* isolate) override; | 158 | 158 |
| 159 | 159 | void RegisterIsolate(v8::Isolate* isolate, uv_loop_t* loop) override; | @@ -178,7 +178,7 @@ class NodePlatform : public MultiIsolatePlatform { | 178 | 178 | IsolatePlatformDelegate*, std::shared_ptr<PerIsolatePlatformData>>; | 179 | 179 | std::unordered_map<v8::Isolate*, DelegatePair> per_isolate_; | 180 | 180 |
| 181 | | - node::tracing::TracingController* tracing_controller_; | | 181 | + v8::TracingController* tracing_controller_; | 182 | 182 | std::shared_ptr<WorkerThreadsTaskRunner> worker_thread_task_runner_; | 183 | 183 | }; | 184 | 184 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/tracing/agent.cc +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -242,8 +242,9 @@ void TracingController::AddMetadataEvent( | 242 | 242 | TRACE_EVENT_FLAG_NONE, | 243 | 243 | CurrentTimestampMicroseconds(), | 244 | 244 | CurrentCpuTimestampMicroseconds()); | 245 | | - node::tracing::TraceEventHelper::GetAgent()->AddMetadataEvent( | 246 | | - std::move(trace_event)); | | 245 | + Agent* node_agent = node::tracing::TraceEventHelper::GetAgent(); | | 246 | + if (node_agent != nullptr) | | 247 | + node_agent->AddMetadataEvent(std::move(trace_event)); | 247 | 248 | } | 248 | 249 |
| 249 | 250 | } // namespace tracing | |
Collapse file Copy file name to clipboardExpand all lines: src/tracing/trace_event.cc +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,17 +4,23 @@ namespace node { | 4 | 4 | namespace tracing { | 5 | 5 |
| 6 | 6 | Agent* g_agent = nullptr; | | 7 | +v8::TracingController* g_controller = nullptr; | 7 | 8 |
| 8 | 9 | void TraceEventHelper::SetAgent(Agent* agent) { | 9 | 10 | g_agent = agent; | | 11 | + g_controller = agent->GetTracingController(); | 10 | 12 | } | 11 | 13 |
| 12 | 14 | Agent* TraceEventHelper::GetAgent() { | 13 | 15 | return g_agent; | 14 | 16 | } | 15 | 17 |
| 16 | | -TracingController* TraceEventHelper::GetTracingController() { | 17 | | - return g_agent->GetTracingController(); | | 18 | +v8::TracingController* TraceEventHelper::GetTracingController() { | | 19 | + return g_controller; | | 20 | +} | | 21 | + | | 22 | +void TraceEventHelper::SetTracingController(v8::TracingController* controller) { | | 23 | + g_controller = controller; | 18 | 24 | } | 19 | 25 |
| 20 | 26 | } // namespace tracing | |
Collapse file Copy file name to clipboardExpand all lines: src/tracing/trace_event.h +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -314,7 +314,9 @@ const uint64_t kNoId = 0; | 314 | 314 | // Refs: https://github.com/nodejs/node/pull/28724 | 315 | 315 | class NODE_EXTERN TraceEventHelper { | 316 | 316 | public: | 317 | | - static TracingController* GetTracingController(); | | 317 | + static v8::TracingController* GetTracingController(); | | 318 | + static void SetTracingController(v8::TracingController* controller); | | 319 | + | 318 | 320 | static Agent* GetAgent(); | 319 | 321 | static void SetAgent(Agent* agent); | 320 | 322 | }; | @@ -505,9 +507,10 @@ static V8_INLINE void AddMetadataEventImpl( | 505 | 507 | arg_convertibles[1].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>( | 506 | 508 | static_cast<intptr_t>(arg_values[1]))); | 507 | 509 | } | 508 | | - node::tracing::TracingController* controller = | 509 | | - node::tracing::TraceEventHelper::GetTracingController(); | 510 | | - return controller->AddMetadataEvent( | | 510 | + node::tracing::Agent* agent = | | 511 | + node::tracing::TraceEventHelper::GetAgent(); | | 512 | + if (agent == nullptr) return; | | 513 | + return agent->GetTracingController()->AddMetadataEvent( | 511 | 514 | category_group_enabled, name, num_args, arg_names, arg_types, arg_values, | 512 | 515 | arg_convertibles, flags); | 513 | 516 | } | |
|