Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2cf3ce8

Browse filesBrowse files
theanarkhruyadorno
authored andcommitted
trace_events: add example
PR-URL: #43253 Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
1 parent 87f75a2 commit 2cf3ce8
Copy full SHA for 2cf3ce8

File tree

Expand file treeCollapse file tree

1 file changed

+42
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+42
-0
lines changed
Open diff view settings
Collapse file

‎doc/api/tracing.md‎

Copy file name to clipboardExpand all lines: doc/api/tracing.md
+42Lines changed: 42 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,48 @@ t2.enable();
228228
console.log(trace_events.getEnabledCategories());
229229
```
230230

231+
## Examples
232+
233+
### Collect trace events data by inspector
234+
235+
```js
236+
'use strict';
237+
238+
const { Session } = require('inspector');
239+
const session = new Session();
240+
session.connect();
241+
242+
function post(message, data) {
243+
return new Promise((resolve, reject) => {
244+
session.post(message, data, (err, result) => {
245+
if (err)
246+
reject(new Error(JSON.stringify(err)));
247+
else
248+
resolve(result);
249+
});
250+
});
251+
}
252+
253+
async function collect() {
254+
const data = [];
255+
session.on('NodeTracing.dataCollected', (chunk) => data.push(chunk));
256+
session.on('NodeTracing.tracingComplete', () => {
257+
// done
258+
});
259+
const traceConfig = { includedCategories: ['v8'] };
260+
await post('NodeTracing.start', { traceConfig });
261+
// do something
262+
setTimeout(() => {
263+
post('NodeTracing.stop').then(() => {
264+
session.disconnect();
265+
console.log(data);
266+
});
267+
}, 1000);
268+
}
269+
270+
collect();
271+
```
272+
231273
[Performance API]: perf_hooks.md
232274
[V8]: v8.md
233275
[`Worker`]: worker_threads.md#class-worker

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.