Skip to content

Instantly share code, notes, and snippets.

@jinwoo
Last active May 26, 2018 00:03
Show Gist options
  • Save jinwoo/770429da1990752b59b7fa5de0c01482 to your computer and use it in GitHub Desktop.
Save jinwoo/770429da1990752b59b7fa5de0c01482 to your computer and use it in GitHub Desktop.
trace event
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);
}
// Events are emitted only after the timeout expires below (currently 5 sec).
client.on('event', (message) => {
console.log('event:', message.method);
if (message && message.data && message.data.value) {
for (const value of message.data.value) {
console.log(value);
}
}
});
client.NodeTracing.tracingComplete(() => {
client.close();
});
// `data` here is undefined somehow with Node 10.2.0. Use the client.on('event') above instead.
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.stop();
}, 5000).unref();
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment