diff options
author | Eugene Ostroukhov <eostroukhov@google.com> | 2018-04-27 17:20:37 -0700 |
---|---|---|
committer | Eugene Ostroukhov <eostroukhov@google.com> | 2018-05-17 13:14:26 -0700 |
commit | 47bdc716f83462b6ab938315d11de6c92be082ac (patch) | |
tree | 8bdfd8c487cdcfb4e5b573b24d7809d053c675a6 /test/parallel/test-inspector-tracing-domain.js | |
parent | 5248401174ff1ec02f5e1a247a97594341bbfd89 (diff) | |
download | android-node-v8-47bdc716f83462b6ab938315d11de6c92be082ac.tar.gz android-node-v8-47bdc716f83462b6ab938315d11de6c92be082ac.tar.bz2 android-node-v8-47bdc716f83462b6ab938315d11de6c92be082ac.zip |
inspector: add a "NodeTracing" domain support
This change adds a new inspector domain for receiving Node tracing
data.
1. Node.js now can extend Inspector protocol with new domains with
the API defined in the src/inspector/node_protocol.pdl.
2. Plumbing code will be generated at the build time. /json/protocol
HTTP endpoint returns both V8 and Node.js inspector protocol.
3. "NodeTracing" domain was introduced. It is based on the Chrome
"Tracing" domain.
PR-URL: https://github.com/nodejs/node/pull/20608
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-inspector-tracing-domain.js')
-rw-r--r-- | test/parallel/test-inspector-tracing-domain.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/parallel/test-inspector-tracing-domain.js b/test/parallel/test-inspector-tracing-domain.js new file mode 100644 index 0000000000..61a853a265 --- /dev/null +++ b/test/parallel/test-inspector-tracing-domain.js @@ -0,0 +1,70 @@ +'use strict'; + +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const { Session } = require('inspector'); + +const session = new Session(); + +function compareIgnoringOrder(array1, array2) { + const set = new Set(array1); + const test = set.size === array2.length && array2.every((el) => set.has(el)); + assert.ok(test, `[${array1}] differs from [${array2}]`); +} + +function post(message, data) { + return new Promise((resolve, reject) => { + session.post(message, data, (err, result) => { + if (err) + reject(new Error(JSON.stringify(err))); + else + resolve(result); + }); + }); +} + +function generateTrace() { + return new Promise((resolve) => setTimeout(() => { + for (let i = 0; i << 1000000; i++) { + 'test' + i; + } + resolve(); + }, 1)); +} + +async function test() { + // This interval ensures Node does not terminate till the test is finished. + // Inspector session does not keep the node process running (e.g. it does not + // have async handles on the main event loop). It is debatable whether this + // should be considered a bug, and there are no plans to fix it atm. + const interval = setInterval(() => {}, 5000); + session.connect(); + let traceNotification = null; + let tracingComplete = false; + session.on('NodeTracing.dataCollected', (n) => traceNotification = n); + session.on('NodeTracing.tracingComplete', () => tracingComplete = true); + const { categories } = await post('NodeTracing.getCategories'); + compareIgnoringOrder(['node', 'node.async', 'node.bootstrap', 'node.fs.sync', + 'node.perf', 'node.perf.usertiming', + 'node.perf.timerify', 'v8'], + categories); + + const traceConfig = { includedCategories: ['node'] }; + await post('NodeTracing.start', { traceConfig }); + + for (let i = 0; i < 5; i++) + await generateTrace(); + JSON.stringify(await post('NodeTracing.stop', { traceConfig })); + session.disconnect(); + assert(traceNotification.data.value.length > 0); + assert(tracingComplete); + clearInterval(interval); + console.log('Success'); +} + +common.crashOnUnhandledRejection(); + +test(); |