diff options
author | Ujjwal Sharma <usharma1998@gmail.com> | 2019-05-30 15:21:49 +0530 |
---|---|---|
committer | Ujjwal Sharma <usharma1998@gmail.com> | 2019-06-01 16:48:24 +0530 |
commit | 389804ec96b4fd9519b8271e5dff394827bf1617 (patch) | |
tree | e68e4565946fe212de3ee7a11234b8ff94bad642 /test/sequential/test-perf-hooks.js | |
parent | 4c2345f4f6761e30440c5e6645a40d63cd74ddf5 (diff) | |
download | android-node-v8-389804ec96b4fd9519b8271e5dff394827bf1617.tar.gz android-node-v8-389804ec96b4fd9519b8271e5dff394827bf1617.tar.bz2 android-node-v8-389804ec96b4fd9519b8271e5dff394827bf1617.zip |
test: rename test-performance to test-perf-hooks
Rename test-performance to test-perf-hooks to better match its function
Refs: https://github.com/nodejs/node/pull/27884#issuecomment-497270542
PR-URL: https://github.com/nodejs/node/pull/27969
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test/sequential/test-perf-hooks.js')
-rw-r--r-- | test/sequential/test-perf-hooks.js | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/test/sequential/test-perf-hooks.js b/test/sequential/test-perf-hooks.js new file mode 100644 index 0000000000..825cf85ef5 --- /dev/null +++ b/test/sequential/test-perf-hooks.js @@ -0,0 +1,120 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const { performance } = require('perf_hooks'); + +if (!common.isMainThread) + common.skip('bootstrapping workers works differently'); + +assert(performance); +assert(performance.nodeTiming); +assert.strictEqual(typeof performance.timeOrigin, 'number'); +// Use a fairly large epsilon value, since we can only guarantee that the node +// process started up in 15 seconds. +assert(Math.abs(performance.timeOrigin - Date.now()) < 15000); + +const inited = performance.now(); +assert(inited < 15000); + +{ + // Should work without throwing any errors + performance.mark('A'); + performance.clearMarks('A'); + + performance.mark('B'); + performance.clearMarks(); +} + +{ + performance.mark('A'); + [undefined, null, 'foo', 'initialize', 1].forEach((i) => { + performance.measure('test', i, 'A'); // Should not throw. + }); + + [undefined, null, 'foo', 1].forEach((i) => { + common.expectsError( + () => performance.measure('test', 'A', i), + { + code: 'ERR_INVALID_PERFORMANCE_MARK', + type: Error, + message: `The "${i}" performance mark has not been set` + }); + }); + + performance.clearMarks(); +} + +{ + performance.mark('A'); + setImmediate(() => { + performance.mark('B'); + performance.measure('foo', 'A', 'B'); + }); +} + +assert.strictEqual(performance.nodeTiming.name, 'node'); +assert.strictEqual(performance.nodeTiming.entryType, 'node'); + +const delay = 250; +function checkNodeTiming(props) { + console.log(props); + + for (const prop of Object.keys(props)) { + if (props[prop].around !== undefined) { + assert.strictEqual(typeof performance.nodeTiming[prop], 'number'); + const delta = performance.nodeTiming[prop] - props[prop].around; + assert( + Math.abs(delta) < (props[prop].delay || delay), + `${prop}: ${Math.abs(delta)} >= ${props[prop].delay || delay}` + ); + } else { + assert.strictEqual(performance.nodeTiming[prop], props[prop], + `mismatch for performance property ${prop}: ` + + `${performance.nodeTiming[prop]} vs ${props[prop]}`); + } + } +} + +checkNodeTiming({ + name: 'node', + entryType: 'node', + startTime: 0, + duration: { around: performance.now() }, + nodeStart: { around: 0 }, + v8Start: { around: 0 }, + bootstrapComplete: { around: inited, delay: 2500 }, + environment: { around: 0 }, + loopStart: -1, + loopExit: -1 +}); + +setTimeout(() => { + checkNodeTiming({ + name: 'node', + entryType: 'node', + startTime: 0, + duration: { around: performance.now() }, + nodeStart: { around: 0 }, + v8Start: { around: 0 }, + bootstrapComplete: { around: inited, delay: 2500 }, + environment: { around: 0 }, + loopStart: { around: inited, delay: 2500 }, + loopExit: -1 + }); +}, 1000); + +process.on('exit', () => { + checkNodeTiming({ + name: 'node', + entryType: 'node', + startTime: 0, + duration: { around: performance.now() }, + nodeStart: { around: 0 }, + v8Start: { around: 0 }, + bootstrapComplete: { around: inited, delay: 2500 }, + environment: { around: 0 }, + loopStart: { around: inited, delay: 2500 }, + loopExit: { around: performance.now() } + }); +}); |