node/test/parallel/test-inspector-has-idle.js
Stephen Belanger aaf98062b0 src: report idle time correctly
With this change, the V8 profiler will attribute any time between
prepare and check cycles, except any entrances to InternalCallbackScope,
to be "idle" time. All callbacks, microtasks, and timers will be marked
as not idle. The one exception is native modules which don't use the
MakeCallback helper, but those are already broken anyway for async
context tracking so we should just encourage broken modules to be fixed.

PR-URL: https://github.com/nodejs/node/pull/37868
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2021-03-25 12:15:14 -07:00

44 lines
921 B
JavaScript

'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const { Session } = require('inspector');
const { promisify } = require('util');
const sleep = promisify(setTimeout);
async function test() {
const inspector = new Session();
inspector.connect();
inspector.post('Profiler.enable');
inspector.post('Profiler.start');
await sleep(1000);
const { profile } = await new Promise((resolve, reject) => {
inspector.post('Profiler.stop', (err, params) => {
if (err) return reject(err);
resolve(params);
});
});
let hasIdle = false;
for (const node of profile.nodes) {
if (node.callFrame.functionName === '(idle)') {
hasIdle = true;
break;
}
}
assert(hasIdle);
inspector.post('Profiler.disable');
inspector.disconnect();
}
test().then(common.mustCall(() => {
console.log('Done!');
}));