Skip to content

Commit 699ac6e

Browse files
legendecasnodejs-github-bot
authored andcommitted
src,test: disable trace events tests when perfetto is enabled
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net> PR-URL: #64721 Fixes: nodejs/diagnostics#654 Refs: #64565 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 19cf50c commit 699ac6e

34 files changed

Lines changed: 99 additions & 3 deletions

benchmark/misc/trace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ const bench = common.createBenchmark(main, {
1414
});
1515

1616
const {
17-
TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN: kBeforeEvent,
17+
TRACE_EVENT_PHASE_BEGIN: kBeginEvent,
1818
} = common.binding('constants').trace;
1919

2020
function doTrace(n, trace) {
2121
bench.start();
2222
for (let i = 0; i < n; i++) {
23-
trace(kBeforeEvent, 'foo', 'test', 0, 'test');
23+
trace(kBeginEvent, 'foo', 'test', 0, 'test');
2424
}
2525
bench.end(n);
2626
}

src/debug_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void NODE_EXTERN_PRIVATE FWrite(FILE* file, const std::string& str);
6161
V(MODULE) \
6262
V(MKSNAPSHOT) \
6363
V(SNAPSHOT_SERDES) \
64+
V(PERFETTO) \
6465
V(PERMISSION_MODEL) \
6566
V(PLATFORM_MINIMAL) \
6667
V(PLATFORM_VERBOSE) \

src/tracing/agent_perfetto.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ std::set<std::string> flatten(
3030
return result;
3131
}
3232

33+
void perfetto_log_callback(perfetto::LogMessageCallbackArgs args) {
34+
const char* level_str = "UNKNOWN";
35+
switch (args.level) {
36+
case perfetto::base::kLogDebug:
37+
level_str = "DEBUG";
38+
break;
39+
case perfetto::base::kLogInfo:
40+
level_str = "INFO";
41+
break;
42+
case perfetto::base::kLogImportant:
43+
level_str = "IMPORTANT";
44+
break;
45+
case perfetto::base::kLogError:
46+
level_str = "ERROR";
47+
break;
48+
}
49+
per_process::Debug(DebugCategory::PERFETTO,
50+
"[%s] %s:%d: %s\n",
51+
level_str,
52+
args.filename,
53+
args.line,
54+
args.message);
55+
}
56+
3357
} // namespace
3458

3559
// Writes trace chunks to a file, rotating by size. It deliberately uses the
@@ -252,6 +276,7 @@ PerfettoTracingAgent::PerfettoTracingAgent() {
252276
// Set up the in-process backend that the tracing controller will connect
253277
// to.
254278
perfetto::TracingInitArgs init_args;
279+
init_args.log_message_callback = perfetto_log_callback;
255280
init_args.backends = perfetto::BackendType::kInProcessBackend;
256281
perfetto::Tracing::Initialize(init_args);
257282

test/common/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const hasCrypto = Boolean(process.versions.openssl) &&
7171
const hasInspector = Boolean(process.features.inspector);
7272
const hasSQLite = Boolean(process.versions.sqlite);
7373
const hasFFI = Boolean(process.config.variables.node_use_ffi);
74+
const hasPerfetto = Boolean(process.config.variables.v8_use_perfetto);
7475

7576
const hasDtls = hasCrypto && !!process.features.dtls;
7677
const hasQuic = hasCrypto && !!process.features.quic;
@@ -769,6 +770,18 @@ function skipIfFFIMissing() {
769770
}
770771
}
771772

773+
function skipIfPerfettoEnabled() {
774+
if (hasPerfetto) {
775+
skip('Perfetto is enabled');
776+
}
777+
}
778+
779+
function skipIfPerfettoDisabled() {
780+
if (!hasPerfetto) {
781+
skip('Perfetto is disabled');
782+
}
783+
}
784+
772785
function getArrayBufferViews(buf) {
773786
const { buffer, byteOffset, byteLength } = buf;
774787

@@ -1047,6 +1060,8 @@ const common = {
10471060
skipIfInspectorDisabled,
10481061
skipIfFFIMissing,
10491062
skipIfSQLiteMissing,
1063+
skipIfPerfettoEnabled,
1064+
skipIfPerfettoDisabled,
10501065
spawnPromisified,
10511066
sleepSync,
10521067
usesSharedLibrary,

test/common/index.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const {
5353
skipIfEslintMissing,
5454
skipIfInspectorDisabled,
5555
skipIfSQLiteMissing,
56+
skipIfPerfettoEnabled,
5657
spawnPromisified,
5758
sleepSync,
5859
} = common;
@@ -111,6 +112,7 @@ export {
111112
skipIfEslintMissing,
112113
skipIfInspectorDisabled,
113114
skipIfSQLiteMissing,
115+
skipIfPerfettoEnabled,
114116
spawnPromisified,
115117
sleepSync,
116118
};

test/parallel/test-inspector-tracing-domain.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const common = require('../common');
44

55
common.skipIfInspectorDisabled();
6+
common.skipIfPerfettoEnabled();
67

78
const { isMainThread } = require('worker_threads');
89

test/parallel/test-module-print-timing.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isWindows } from '../common/index.mjs';
1+
import { isWindows, skipIfPerfettoEnabled } from '../common/index.mjs';
22
import assert from 'node:assert';
33
import { writeFileSync } from 'node:fs';
44
import { readFile } from 'node:fs/promises';
@@ -7,6 +7,7 @@ import tmpdir from '../common/tmpdir.js';
77
import { spawnSyncAndAssert } from '../common/child_process.js';
88
import fixtures from '../common/fixtures.js';
99

10+
skipIfPerfettoEnabled();
1011
tmpdir.refresh();
1112

1213
it('should print the timing information for cjs', () => {

test/parallel/test-permission-fs-write-trace-events.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const common = require('../common');
55
const { spawnSyncAndExitWithoutError } = require('../common/child_process');
66
const { isMainThread } = require('worker_threads');
77

8+
common.skipIfPerfettoEnabled();
89
if (!isMainThread) {
910
common.skip('This test only works on a main thread');
1011
}

test/parallel/test-trace-events-all.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const assert = require('assert');
44
const cp = require('child_process');
55
const fs = require('fs');
66

7+
common.skipIfPerfettoEnabled();
8+
79
const CODE =
810
'setTimeout(() => { for (let i = 0; i < 100000; i++) { "test" + i } }, 1)';
911

test/parallel/test-trace-events-api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
const common = require('../common');
55
const { isMainThread } = require('worker_threads');
66

7+
common.skipIfPerfettoEnabled();
8+
79
if (!isMainThread) {
810
// https://github.com/nodejs/node/issues/22767
911
common.skip('This test only works on a main thread');

0 commit comments

Comments
 (0)