Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace_events: fix dynamic enabling of trace events #22114

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.23',
'v8_embedder_string': '-node.24',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
13 changes: 4 additions & 9 deletions deps/v8/src/libplatform/tracing/tracing-controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ namespace tracing {
// convert internally to determine the category name from the char enabled
// pointer.
const char* g_category_groups[MAX_CATEGORY_GROUPS] = {
"toplevel", "tracing already shutdown",
"toplevel",
"tracing categories exhausted; must increase MAX_CATEGORY_GROUPS",
"__metadata"};

// The enabled flag is char instead of bool so that the API can be used from C.
unsigned char g_category_group_enabled[MAX_CATEGORY_GROUPS] = {0};
// Indexes here have to match the g_category_groups array indexes above.
const int g_category_already_shutdown = 1;
const int g_category_categories_exhausted = 2;
const int g_category_categories_exhausted = 1;
// Metadata category not used in V8.
// const int g_category_metadata = 3;
const int g_num_builtin_categories = 4;
// const int g_category_metadata = 2;
const int g_num_builtin_categories = 3;

// Skip default categories.
v8::base::AtomicWord g_category_index = g_num_builtin_categories;
Expand Down Expand Up @@ -103,10 +102,6 @@ void TracingController::UpdateTraceEventDuration(

const uint8_t* TracingController::GetCategoryGroupEnabled(
const char* category_group) {
if (!trace_buffer_) {
DCHECK(!g_category_group_enabled[g_category_already_shutdown]);
return &g_category_group_enabled[g_category_already_shutdown];
}
return GetCategoryGroupEnabledInternal(category_group);
}

Expand Down
58 changes: 58 additions & 0 deletions test/parallel/test-trace-events-dynamic-enable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

const common = require('../common');

common.skipIfInspectorDisabled();

const assert = require('assert');
const { performance } = require('perf_hooks');
const { Session } = require('inspector');

const session = new Session();

function post(message, data) {
return new Promise((resolve, reject) => {
session.post(message, data, (err, result) => {
if (err)
reject(new Error(JSON.stringify(err)));
else
resolve(result);
});
});
}

async function test() {
session.connect();

let traceNotification = null;
let tracingComplete = false;
session.on('NodeTracing.dataCollected', (n) => traceNotification = n);
session.on('NodeTracing.tracingComplete', () => tracingComplete = true);

// Generate a node.perf event before tracing is enabled.
performance.mark('mark1');

const traceConfig = { includedCategories: ['node.perf'] };
await post('NodeTracing.start', { traceConfig });

// Generate a node.perf event after tracing is enabled. This should be the
// mark event captured.
performance.mark('mark2');

await post('NodeTracing.stop', { traceConfig });

performance.mark('mark3');

session.disconnect();

assert.ok(tracingComplete);
assert.ok(traceNotification);
assert.ok(traceNotification.data && traceNotification.data.value);

const events = traceNotification.data.value;
const marks = events.filter((t) => null !== /node\.perf\.usertim/.exec(t.cat));
assert.strictEqual(marks.length, 1);
assert.strictEqual(marks[0].name, 'mark2');
}

test();