| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,58 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + | ||
| 5 | + common.skipIfInspectorDisabled(); | ||
| 6 | + | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + const { performance } = require('perf_hooks'); | ||
| 9 | + const { Session } = require('inspector'); | ||
| 10 | + | ||
| 11 | + const session = new Session(); | ||
| 12 | + | ||
| 13 | + function post(message, data) { | ||
| 14 | + return new Promise((resolve, reject) => { | ||
| 15 | + session.post(message, data, (err, result) => { | ||
| 16 | + if (err) | ||
| 17 | + reject(new Error(JSON.stringify(err))); | ||
| 18 | + else | ||
| 19 | + resolve(result); | ||
| 20 | + }); | ||
| 21 | + }); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + async function test() { | ||
| 25 | + session.connect(); | ||
| 26 | + | ||
| 27 | + let traceNotification = null; | ||
| 28 | + let tracingComplete = false; | ||
| 29 | + session.on('NodeTracing.dataCollected', (n) => traceNotification = n); | ||
| 30 | + session.on('NodeTracing.tracingComplete', () => tracingComplete = true); | ||
| 31 | + | ||
| 32 | + // Generate a node.perf event before tracing is enabled. | ||
| 33 | + performance.mark('mark1'); | ||
| 34 | + | ||
| 35 | + const traceConfig = { includedCategories: ['node.perf'] }; | ||
| 36 | + await post('NodeTracing.start', { traceConfig }); | ||
| 37 | + | ||
| 38 | + // Generate a node.perf event after tracing is enabled. This should be the | ||
| 39 | + // mark event captured. | ||
| 40 | + performance.mark('mark2'); | ||
| 41 | + | ||
| 42 | + await post('NodeTracing.stop', { traceConfig }); | ||
| 43 | + | ||
| 44 | + performance.mark('mark3'); | ||
| 45 | + | ||
| 46 | + session.disconnect(); | ||
| 47 | + | ||
| 48 | + assert.ok(tracingComplete); | ||
| 49 | + assert.ok(traceNotification); | ||
| 50 | + assert.ok(traceNotification.data && traceNotification.data.value); | ||
| 51 | + | ||
| 52 | + const events = traceNotification.data.value; | ||
| 53 | + const marks = events.filter((t) => null !== /node\.perf\.usertim/.exec(t.cat)); | ||
| 54 | + assert.strictEqual(marks.length, 1); | ||
| 55 | + assert.strictEqual(marks[0].name, 'mark2'); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + test(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments