Created
May 8, 2018 20:06
-
-
Save jinwoo/1d90cb5749720cf8972e87b6133c33de to your computer and use it in GitHub Desktop.
Node trace events testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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