Skip to content

Instantly share code, notes, and snippets.

@ofrobots

ofrobots/test.js Secret

Created July 18, 2018 20:47
Show Gist options
  • Save ofrobots/ab4c4e68b0de4852197308cd25f3cc0e to your computer and use it in GitHub Desktop.
Save ofrobots/ab4c4e68b0de4852197308cd25f3cc0e to your computer and use it in GitHub Desktop.
const execa = require('execa');
const delay = require('delay');
const CDP = require('chrome-remote-interface');
async function trace(port) {
const client = await CDP({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();
});
const result = await client.NodeTracing.start({
traceConfig: {
recordMode: 'recordContinuously',
includedCategories: ['node'],
},
});
console.log('start result', result);
setTimeout(() => {
console.log('stoping tracing');
client.NodeTracing.stop();
}, 5000).unref();
}
async function main() {
execa(process.execPath, ['--inspect', '-e', 'setTimeout(_=>_, 5000)'])
.stdout.pipe(process.stdout);
await delay(100);
trace(9229);
await delay(5000);
}
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment