Skip to content

Instantly share code, notes, and snippets.

@jinwoo
Created May 8, 2018 20:06
Show Gist options
  • Save jinwoo/1d90cb5749720cf8972e87b6133c33de to your computer and use it in GitHub Desktop.
Save jinwoo/1d90cb5749720cf8972e87b6133c33de to your computer and use it in GitHub Desktop.
Node trace events testing
$ npm start
> [email protected] start /Users/jinwoo/src/trace-events
> node index.js
supported categories:
node
node.async
node.bootstrap
node.perf
node.perf.usertiming
node.perf.timerify
v8
const CDP = require('chrome-remote-interface');
const minimist = require('minimist');
const args = minimist(process.argv.slice(2), {
alias: {port: 'p'},
default: {port: 9222},
});
async function main() {
const client = await CDP({port: args.port});
if (!client.NodeTracing) {
console.error(
`The implementation doesn't support NodeTracing domain. Closing.`);
client.close();
return;
}
const cats = await client.NodeTracing.getCategories();
console.log('supported categories:');
for (const c of cats.categories) {
console.log(' ', c);
}
client.on('event', (message) => {
console.log('event:', message.method);
});
client.NodeTracing.tracingComplete(() => {
client.close();
});
client.NodeTracing.dataCollected((data) => {
for (const value of data.value) {
if (value.cat !== 'v8' && value.cat !== 'node') {
continue;
}
console.log(' pid:', value.pid);
console.log(' tid:', value.tid);
console.log(' ts:', value.ts);
console.log(' ph:', value.ph);
console.log(' dur:', value.dur);
console.log(' cat:', value.cat);
console.log(' name:', value.name);
console.log(' args:', value.args);
console.log();
}
});
await client.NodeTracing.start({
traceConfig: {
recordMode: 'recordContinuously',
includedCategories: ['v8', 'node'],
},
});
setTimeout(() => {
client.NodeTracing.end();
}, 10000).unref();
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment