| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 977af25 commit 31fdb88
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ const { | |||
| 8 | 8 | } = primordials; | |
| 9 | 9 | ||
| 10 | 10 | const { setUnrefTimeout } = require('internal/timers'); | |
| 11 | - const { trace, isTraceCategoryEnabled } = internalBinding('trace_events'); | ||
| 11 | + const { getCategoryEnabledBuffer, trace } = internalBinding('trace_events'); | ||
| 12 | 12 | const { | |
| 13 | 13 | CHAR_LOWERCASE_B, | |
| 14 | 14 | CHAR_LOWERCASE_E, | |
@@ -37,8 +37,10 @@ function getNextTraceEventId() { | |||
| 37 | 37 | return ++traceEventId; | |
| 38 | 38 | } | |
| 39 | 39 | ||
| 40 | + const httpEnabled = getCategoryEnabledBuffer('node.http'); | ||
| 41 | + | ||
| 40 | 42 | function isTraceHTTPEnabled() { | |
| 41 | - return isTraceCategoryEnabled('node.http'); | ||
| 43 | + return httpEnabled[0] > 0; | ||
| 42 | 44 | } | |
| 43 | 45 | ||
| 44 | 46 | const traceEventCategory = 'node,node.http'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,6 +16,8 @@ namespace node { | |||
| 16 | 16 | class ExternalReferenceRegistry; | |
| 17 | 17 | ||
| 18 | 18 | using v8::Array; | |
| 19 | + using v8::ArrayBuffer; | ||
| 20 | + using v8::BackingStore; | ||
| 19 | 21 | using v8::Context; | |
| 20 | 22 | using v8::Function; | |
| 21 | 23 | using v8::FunctionCallbackInfo; | |
@@ -25,6 +27,7 @@ using v8::Local; | |||
| 25 | 27 | using v8::NewStringType; | |
| 26 | 28 | using v8::Object; | |
| 27 | 29 | using v8::String; | |
| 30 | + using v8::Uint8Array; | ||
| 28 | 31 | using v8::Value; | |
| 29 | 32 | ||
| 30 | 33 | class NodeCategorySet : public BaseObject { | |
@@ -120,6 +123,27 @@ static void SetTraceCategoryStateUpdateHandler( | |||
| 120 | 123 | env->set_trace_category_state_function(args[0].As<Function>()); | |
| 121 | 124 | } | |
| 122 | 125 | ||
| 126 | + static void GetCategoryEnabledBuffer(const FunctionCallbackInfo<Value>& args) { | ||
| 127 | + CHECK(args[0]->IsString()); | ||
| 128 | + | ||
| 129 | + Isolate* isolate = args.GetIsolate(); | ||
| 130 | + node::Utf8Value category_name(isolate, args[0]); | ||
| 131 | + | ||
| 132 | + const uint8_t* enabled_pointer = | ||
| 133 | + TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_name.out()); | ||
| 134 | + uint8_t* enabled_pointer_cast = const_cast<uint8_t*>(enabled_pointer); | ||
| 135 | + | ||
| 136 | + std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore( | ||
| 137 | + enabled_pointer_cast, | ||
| 138 | + sizeof(*enabled_pointer_cast), | ||
| 139 | + [](void*, size_t, void*) {}, | ||
| 140 | + nullptr); | ||
| 141 | + auto ab = ArrayBuffer::New(isolate, std::move(bs)); | ||
| 142 | + v8::Local<Uint8Array> u8 = v8::Uint8Array::New(ab, 0, 1); | ||
| 143 | + | ||
| 144 | + args.GetReturnValue().Set(u8); | ||
| 145 | + } | ||
| 146 | + | ||
| 123 | 147 | void NodeCategorySet::Initialize(Local<Object> target, | |
| 124 | 148 | Local<Value> unused, | |
| 125 | 149 | Local<Context> context, | |
@@ -132,6 +156,8 @@ void NodeCategorySet::Initialize(Local<Object> target, | |||
| 132 | 156 | target, | |
| 133 | 157 | "setTraceCategoryStateUpdateHandler", | |
| 134 | 158 | SetTraceCategoryStateUpdateHandler); | |
| 159 | + SetMethod( | ||
| 160 | + context, target, "getCategoryEnabledBuffer", GetCategoryEnabledBuffer); | ||
| 135 | 161 | ||
| 136 | 162 | Local<FunctionTemplate> category_set = | |
| 137 | 163 | NewFunctionTemplate(isolate, NodeCategorySet::New); | |
@@ -160,6 +186,7 @@ void NodeCategorySet::RegisterExternalReferences( | |||
| 160 | 186 | ExternalReferenceRegistry* registry) { | |
| 161 | 187 | registry->Register(GetEnabledCategories); | |
| 162 | 188 | registry->Register(SetTraceCategoryStateUpdateHandler); | |
| 189 | + registry->Register(GetCategoryEnabledBuffer); | ||
| 163 | 190 | registry->Register(NodeCategorySet::New); | |
| 164 | 191 | registry->Register(NodeCategorySet::Enable); | |
| 165 | 192 | registry->Register(NodeCategorySet::Disable); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,43 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + // Flags: --expose-internals | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const { it } = require('node:test'); | ||
| 6 | + | ||
| 7 | + try { | ||
| 8 | + require('trace_events'); | ||
| 9 | + } catch { | ||
| 10 | + common.skip('missing trace events'); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + const { createTracing, getEnabledCategories } = require('trace_events'); | ||
| 14 | + const assert = require('assert'); | ||
| 15 | + | ||
| 16 | + const binding = require('internal/test/binding'); | ||
| 17 | + const getCategoryEnabledBuffer = binding.internalBinding('trace_events').getCategoryEnabledBuffer; | ||
| 18 | + | ||
| 19 | + it('should track enabled/disabled categories', () => { | ||
| 20 | + const random = Math.random().toString().slice(2); | ||
| 21 | + const category = `node.${random}`; | ||
| 22 | + | ||
| 23 | + const buffer = getCategoryEnabledBuffer(category); | ||
| 24 | + | ||
| 25 | + const tracing = createTracing({ | ||
| 26 | + categories: [category], | ||
| 27 | + }); | ||
| 28 | + | ||
| 29 | + assert.ok(buffer[0] === 0, `the buffer[0] should start with value 0, got: ${buffer[0]}`); | ||
| 30 | + | ||
| 31 | + tracing.enable(); | ||
| 32 | + | ||
| 33 | + let currentCategories = getEnabledCategories(); | ||
| 34 | + | ||
| 35 | + assert.ok(currentCategories.includes(category), `the getEnabledCategories should include ${category}, got: ${currentCategories}`); | ||
| 36 | + assert.ok(buffer[0] > 0, `the buffer[0] should be greater than 0, got: ${buffer[0]}`); | ||
| 37 | + | ||
| 38 | + tracing.disable(); | ||
| 39 | + | ||
| 40 | + currentCategories = getEnabledCategories(); | ||
| 41 | + assert.ok(currentCategories === undefined, `the getEnabledCategories should return undefined, got: ${currentCategories}`); | ||
| 42 | + assert.ok(buffer[0] === 0, `the buffer[0] should be 0, got: ${buffer[0]}`); | ||
| 43 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments