-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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. PR-URL: #53602 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- Loading branch information
1 parent
977af25
commit 31fdb88
Showing
3 changed files
with
74 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
43 changes: 43 additions & 0 deletions
43
test/parallel/test-trace-events-get-category-enabled-buffer.js
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,43 @@ | ||
'use strict'; | ||
// Flags: --expose-internals | ||
|
||
const common = require('../common'); | ||
const { it } = require('node:test'); | ||
|
||
try { | ||
require('trace_events'); | ||
} catch { | ||
common.skip('missing trace events'); | ||
} | ||
|
||
const { createTracing, getEnabledCategories } = require('trace_events'); | ||
const assert = require('assert'); | ||
|
||
const binding = require('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]}`); | ||
}); |