Skip to content

Commit

Permalink
trace_events: add example
Browse files Browse the repository at this point in the history
PR-URL: #43253
Reviewed-By: Erick Wendel <erick.workspace@gmail.com>
  • Loading branch information
theanarkh authored and ruyadorno committed Aug 22, 2022
1 parent 87f75a2 commit 2cf3ce8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions doc/api/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,48 @@ t2.enable();
console.log(trace_events.getEnabledCategories());
```

## Examples

### Collect trace events data by inspector

```js
'use strict';

const { Session } = require('inspector');
const session = new Session();
session.connect();

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 collect() {
const data = [];
session.on('NodeTracing.dataCollected', (chunk) => data.push(chunk));
session.on('NodeTracing.tracingComplete', () => {
// done
});
const traceConfig = { includedCategories: ['v8'] };
await post('NodeTracing.start', { traceConfig });
// do something
setTimeout(() => {
post('NodeTracing.stop').then(() => {
session.disconnect();
console.log(data);
});
}, 1000);
}

collect();
```

[Performance API]: perf_hooks.md
[V8]: v8.md
[`Worker`]: worker_threads.md#class-worker
Expand Down

0 comments on commit 2cf3ce8

Please sign in to comment.