| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5cc2574 commit 966546c
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,9 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { getOptionValue } = require('internal/options'); | |
| 4 | + // Lazy load internal/trace_events_async_hooks only if the async_hooks | ||
| 5 | + // trace event category is enabled. | ||
| 6 | + let traceEventsAsyncHook; | ||
| 4 | 7 | ||
| 5 | 8 | function prepareMainThreadExecution() { | |
| 6 | 9 | setupTraceCategoryState(); | |
@@ -27,32 +30,27 @@ function prepareMainThreadExecution() { | |||
| 27 | 30 | ||
| 28 | 31 | function setupTraceCategoryState() { | |
| 29 | 32 | const { | |
| 30 | - traceCategoryState, | ||
| 33 | + asyncHooksEnabledInitial, | ||
| 31 | 34 | setTraceCategoryStateUpdateHandler | |
| 32 | 35 | } = internalBinding('trace_events'); | |
| 33 | - const kCategoryAsyncHooks = 0; | ||
| 34 | - let traceEventsAsyncHook; | ||
| 35 | - | ||
| 36 | - function toggleTraceCategoryState() { | ||
| 37 | - // Dynamically enable/disable the traceEventsAsyncHook | ||
| 38 | - const asyncHooksEnabled = !!traceCategoryState[kCategoryAsyncHooks]; | ||
| 39 | - | ||
| 40 | - if (asyncHooksEnabled) { | ||
| 41 | - // Lazy load internal/trace_events_async_hooks only if the async_hooks | ||
| 42 | - // trace event category is enabled. | ||
| 43 | - if (!traceEventsAsyncHook) { | ||
| 44 | - traceEventsAsyncHook = require('internal/trace_events_async_hooks'); | ||
| 45 | - } | ||
| 46 | - traceEventsAsyncHook.enable(); | ||
| 47 | - } else if (traceEventsAsyncHook) { | ||
| 48 | - traceEventsAsyncHook.disable(); | ||
| 49 | - } | ||
| 50 | - } | ||
| 51 | 36 | ||
| 52 | - toggleTraceCategoryState(); | ||
| 37 | + toggleTraceCategoryState(asyncHooksEnabledInitial); | ||
| 53 | 38 | setTraceCategoryStateUpdateHandler(toggleTraceCategoryState); | |
| 54 | 39 | } | |
| 55 | 40 | ||
| 41 | + // Dynamically enable/disable the traceEventsAsyncHook | ||
| 42 | + function toggleTraceCategoryState(asyncHooksEnabled) { | ||
| 43 | + if (asyncHooksEnabled) { | ||
| 44 | + if (!traceEventsAsyncHook) { | ||
| 45 | + traceEventsAsyncHook = | ||
| 46 | + require('internal/trace_events_async_hooks').createHook(); | ||
| 47 | + } | ||
| 48 | + traceEventsAsyncHook.enable(); | ||
| 49 | + } else if (traceEventsAsyncHook) { | ||
| 50 | + traceEventsAsyncHook.disable(); | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + | ||
| 56 | 54 | // In general deprecations are intialized wherever the APIs are implemented, | |
| 57 | 55 | // this is used to deprecate APIs implemented in C++ where the deprecation | |
| 58 | 56 | // utitlities are not easily accessible. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,4 +83,4 @@ function createHook() { | |||
| 83 | 83 | }; | |
| 84 | 84 | } | |
| 85 | 85 | ||
| 86 | - module.exports = createHook(); | ||
| 86 | + exports.createHook = createHook; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -455,11 +455,6 @@ Environment::should_abort_on_uncaught_toggle() { | |||
| 455 | 455 | return should_abort_on_uncaught_toggle_; | |
| 456 | 456 | } | |
| 457 | 457 | ||
| 458 | - inline AliasedBuffer<uint8_t, v8::Uint8Array>& | ||
| 459 | - Environment::trace_category_state() { | ||
| 460 | - return trace_category_state_; | ||
| 461 | - } | ||
| 462 | - | ||
| 463 | 458 | inline AliasedBuffer<int32_t, v8::Int32Array>& | |
| 464 | 459 | Environment::stream_base_state() { | |
| 465 | 460 | return stream_base_state_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ | |||
| 21 | 21 | namespace node { | |
| 22 | 22 | ||
| 23 | 23 | using errors::TryCatchScope; | |
| 24 | + using v8::Boolean; | ||
| 24 | 25 | using v8::Context; | |
| 25 | 26 | using v8::EmbedderGraph; | |
| 26 | 27 | using v8::External; | |
@@ -152,9 +153,8 @@ void Environment::TrackingTraceStateObserver::UpdateTraceCategoryState() { | |||
| 152 | 153 | return; | |
| 153 | 154 | } | |
| 154 | 155 | ||
| 155 | - env_->trace_category_state()[0] = | ||
| 156 | - *TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | ||
| 157 | - TRACING_CATEGORY_NODE1(async_hooks)); | ||
| 156 | + bool async_hooks_enabled = (*(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | ||
| 157 | + TRACING_CATEGORY_NODE1(async_hooks)))) != 0; | ||
| 158 | 158 | ||
| 159 | 159 | Isolate* isolate = env_->isolate(); | |
| 160 | 160 | HandleScope handle_scope(isolate); | |
@@ -163,8 +163,9 @@ void Environment::TrackingTraceStateObserver::UpdateTraceCategoryState() { | |||
| 163 | 163 | return; | |
| 164 | 164 | TryCatchScope try_catch(env_); | |
| 165 | 165 | try_catch.SetVerbose(true); | |
| 166 | - cb->Call(env_->context(), Undefined(isolate), | ||
| 167 | - 0, nullptr).ToLocalChecked(); | ||
| 166 | + Local<Value> args[] = {Boolean::New(isolate, async_hooks_enabled)}; | ||
| 167 | + cb->Call(env_->context(), Undefined(isolate), arraysize(args), args) | ||
| 168 | + .ToLocalChecked(); | ||
| 168 | 169 | } | |
| 169 | 170 | ||
| 170 | 171 | static std::atomic<uint64_t> next_thread_id{0}; | |
@@ -183,7 +184,6 @@ Environment::Environment(IsolateData* isolate_data, | |||
| 183 | 184 | tick_info_(context->GetIsolate()), | |
| 184 | 185 | timer_base_(uv_now(isolate_data->event_loop())), | |
| 185 | 186 | should_abort_on_uncaught_toggle_(isolate_, 1), | |
| 186 | - trace_category_state_(isolate_, kTraceCategoryCount), | ||
| 187 | 187 | stream_base_state_(isolate_, StreamBase::kNumStreamBaseStateFields), | |
| 188 | 188 | flags_(flags), | |
| 189 | 189 | thread_id_(thread_id == kNoThreadId ? AllocateThreadId() : thread_id), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -705,7 +705,6 @@ class Environment { | |||
| 705 | 705 | inline AliasedBuffer<uint32_t, v8::Uint32Array>& | |
| 706 | 706 | should_abort_on_uncaught_toggle(); | |
| 707 | 707 | ||
| 708 | - inline AliasedBuffer<uint8_t, v8::Uint8Array>& trace_category_state(); | ||
| 709 | 708 | inline AliasedBuffer<int32_t, v8::Int32Array>& stream_base_state(); | |
| 710 | 709 | ||
| 711 | 710 | // The necessary API for async_hooks. | |
@@ -1026,8 +1025,6 @@ class Environment { | |||
| 1026 | 1025 | AliasedBuffer<uint32_t, v8::Uint32Array> should_abort_on_uncaught_toggle_; | |
| 1027 | 1026 | int should_not_abort_scope_counter_ = 0; | |
| 1028 | 1027 | ||
| 1029 | - // Attached to a Uint8Array that tracks the state of trace category | ||
| 1030 | - AliasedBuffer<uint8_t, v8::Uint8Array> trace_category_state_; | ||
| 1031 | 1028 | std::unique_ptr<TrackingTraceStateObserver> trace_state_observer_; | |
| 1032 | 1029 | ||
| 1033 | 1030 | AliasedBuffer<int32_t, v8::Int32Array> stream_base_state_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | #include "base_object-inl.h" | |
| 2 | 2 | #include "env.h" | |
| 3 | 3 | #include "node.h" | |
| 4 | + #include "node_internals.h" | ||
| 4 | 5 | #include "node_v8_platform-inl.h" | |
| 5 | 6 | #include "tracing/agent.h" | |
| 6 | 7 | ||
@@ -10,6 +11,7 @@ | |||
| 10 | 11 | namespace node { | |
| 11 | 12 | ||
| 12 | 13 | using v8::Array; | |
| 14 | + using v8::Boolean; | ||
| 13 | 15 | using v8::Context; | |
| 14 | 16 | using v8::Function; | |
| 15 | 17 | using v8::FunctionCallbackInfo; | |
@@ -148,9 +150,14 @@ void NodeCategorySet::Initialize(Local<Object> target, | |||
| 148 | 150 | target->Set(context, trace, | |
| 149 | 151 | binding->Get(context, trace).ToLocalChecked()).FromJust(); | |
| 150 | 152 | ||
| 151 | - target->Set(context, | ||
| 152 | - FIXED_ONE_BYTE_STRING(env->isolate(), "traceCategoryState"), | ||
| 153 | - env->trace_category_state().GetJSArray()).FromJust(); | ||
| 153 | + // Initial value of async hook trace events | ||
| 154 | + bool async_hooks_enabled = (*(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | ||
| 155 | + TRACING_CATEGORY_NODE1(async_hooks)))) != 0; | ||
| 156 | + target | ||
| 157 | + ->Set(context, | ||
| 158 | + FIXED_ONE_BYTE_STRING(env->isolate(), "asyncHooksEnabledInitial"), | ||
| 159 | + Boolean::New(env->isolate(), async_hooks_enabled)) | ||
| 160 | + .FromJust(); | ||
| 154 | 161 | } | |
| 155 | 162 | ||
| 156 | 163 | } // namespace node | |
| Back | FazBrowse Home | New Git URL |
0 commit comments