GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add test to dynamic enablement of trace-events · nodejs/node@e5b732f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-trace-events-dynamic-enable.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-trace-events-dynamic-enable.js‎

Copy file name to clipboard
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
common.skipIfInspectorDisabled();
6+
7+
const assert = require('assert');
8+
const { performance } = require('perf_hooks');
9+
const { Session } = require('inspector');
10+
11+
const session = new Session();
12+
13+
function post(message, data) {
14+
return new Promise((resolve, reject) => {
15+
session.post(message, data, (err, result) => {
16+
if (err)
17+
reject(new Error(JSON.stringify(err)));
18+
else
19+
resolve(result);
20+
});
21+
});
22+
}
23+
24+
async function test() {
25+
session.connect();
26+
27+
let traceNotification = null;
28+
let tracingComplete = false;
29+
session.on('NodeTracing.dataCollected', (n) => traceNotification = n);
30+
session.on('NodeTracing.tracingComplete', () => tracingComplete = true);
31+
32+
// Generate a node.perf event before tracing is enabled.
33+
performance.mark('mark1');
34+
35+
const traceConfig = { includedCategories: ['node.perf'] };
36+
await post('NodeTracing.start', { traceConfig });
37+
38+
// Generate a node.perf event after tracing is enabled. This should be the
39+
// mark event captured.
40+
performance.mark('mark2');
41+
42+
await post('NodeTracing.stop', { traceConfig });
43+
44+
performance.mark('mark3');
45+
46+
session.disconnect();
47+
48+
assert.ok(tracingComplete);
49+
assert.ok(traceNotification);
50+
assert.ok(traceNotification.data && traceNotification.data.value);
51+
52+
const events = traceNotification.data.value;
53+
const marks = events.filter((t) => null !== /node\.perf\.usertim/.exec(t.cat));
54+
assert.strictEqual(marks.length, 1);
55+
assert.strictEqual(marks[0].name, 'mark2');
56+
}
57+
58+
test();

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.