-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,lib: expose getCategoryEnabledBuffer to use on node.http
Instead call the C++ code every time we need to check for a trace category, now we get the C++ pointer to the flag that holds the info if the trace is enabled and return this pointer inside a buffer that we can use to call/check if the value is enabled. With this change, no C++ call is made and the access to the info happens in JS side, which has no perf penalty.
- Loading branch information
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
test/parallel/test-trace-events-get-category-enabled-buffer.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Flags: --expose-internals | ||
|
||
import '../common/index.mjs'; | ||
import { it } from 'node:test'; | ||
import { createTracing, getEnabledCategories } from 'node:trace_events'; | ||
import assert from 'node:assert'; | ||
|
||
import binding from 'internal/test/binding'; | ||
const getCategoryEnabledBuffer = binding.internalBinding('trace_events').getCategoryEnabledBuffer; | ||
|
||
it('should track enabled/disabled categories', () => { | ||
const random = Math.random().toString().slice(2); | ||
const category = `node.${random}`; | ||
|
||
const buffer = getCategoryEnabledBuffer(category); | ||
|
||
const tracing = createTracing({ | ||
categories: [category], | ||
}); | ||
|
||
assert.ok(buffer[0] === 0, `the buffer[0] should start with value 0, got: ${buffer[0]}`); | ||
|
||
tracing.enable(); | ||
|
||
let currentCategories = getEnabledCategories(); | ||
|
||
assert.ok(currentCategories.includes(category), `the getEnabledCategories should include ${category}, got: ${currentCategories}`); | ||
assert.ok(buffer[0] > 0, `the buffer[0] should be greater than 0, got: ${buffer[0]}`); | ||
|
||
tracing.disable(); | ||
|
||
currentCategories = getEnabledCategories(); | ||
assert.ok(currentCategories === undefined, `the getEnabledCategories should return undefined, got: ${currentCategories}`); | ||
assert.ok(buffer[0] === 0, `the buffer[0] should be 0, got: ${buffer[0]}`); | ||
}); |