} = constants; const kinds = [ NODE_PERFORMANCE_GC_MAJOR, NODE_PERFORMANCE_GC_MINOR, NODE_PERFORMANCE_GC_INCREMENTAL, NODE_PERFORMANCE_GC_WEAKCB ]; // Adding an observer should force at least one gc to appear { const obs = new PerformanceObserver(common.mustCallAtLeast((list) => { const entry = list.getEntries()[0]; assert(entry); assert.strictEqual(entry.name, 'gc'); assert.strictEqual(entry.entryType, 'gc'); assert(kinds.includes(entry.kind)); assert.strictEqual(typeof entry.startTime, 'number'); assert.strictEqual(typeof entry.duration, 'number'); obs.disconnect(); })); obs.observe({ entryTypes: ['gc'] }); global.gc(); // Keep the event loop alive to witness the GC async callback happen. setImmediate(() => setImmediate(() => 0)); } // GC should not keep the event loop alive { let didCall = false; process.on('beforeExit', () => { assert(!didCall);
}); [1, undefined, null, {}, Infinity].forEach((i) => { common.expectsError(() => observer.observe({ entryTypes: i }), { code: 'ERR_INVALID_OPT_VALUE', type: TypeError, message: 'The value "[object Object]" is invalid ' + 'for option "entryTypes"' }); }); } // Test Non-Buffered { const observer = new PerformanceObserver(common.mustCall(callback, 3)); const countdown = new Countdown(3, () => { observer.disconnect(); assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_MARK], 0); }); function callback(list, obs) { assert.strictEqual(obs, observer); const entries = list.getEntries(); assert.strictEqual(entries.length, 1); countdown.dec(); } assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_MARK], 0); observer.observe({ entryTypes: ['mark'] });
const assert = require('assert'); const { performance, PerformanceObserver } = require('perf_hooks'); { // Intentional non-op. Do not wrap in common.mustCall(); const n = performance.timerify(function noop() {}); const obs = new PerformanceObserver(common.mustCall((list) => { const entries = list.getEntries(); const entry = entries[0]; assert(entry); assert.strictEqual(entry.name, 'noop'); assert.strictEqual(entry.entryType, 'function'); assert.strictEqual(typeof entry.duration, 'number'); assert.strictEqual(typeof entry.startTime, 'number'); obs.disconnect(); })); obs.observe({ entryTypes: ['function'] }); n(); } { // If the error throws, the error should just be bubbled up and the // performance timeline entry will not be reported. const obs = new PerformanceObserver(common.mustNotCall()); obs.observe({ entryTypes: ['function'] }); const n = performance.timerify(() => { throw new Error('test');
const obs = new PerformanceObserver(common.mustCall((items) => { const entry = items.getEntries()[0]; assert.strictEqual(entry.entryType, 'http2'); assert.strictEqual(typeof entry.startTime, 'number'); assert.strictEqual(typeof entry.duration, 'number'); switch (entry.name) { case 'Http2Session': assert.strictEqual(typeof entry.pingRTT, 'number'); assert.strictEqual(typeof entry.streamAverageDuration, 'number'); assert.strictEqual(typeof entry.streamCount, 'number'); assert.strictEqual(typeof entry.framesReceived, 'number'); assert.strictEqual(typeof entry.framesSent, 'number'); assert.strictEqual(typeof entry.bytesWritten, 'number'); assert.strictEqual(typeof entry.bytesRead, 'number'); assert.strictEqual(typeof entry.maxConcurrentStreams, 'number'); switch (entry.type) { case 'server': assert.strictEqual(entry.streamCount, 1); assert(entry.framesReceived >= 3); break; case 'client': assert.strictEqual(entry.streamCount, 1); assert.strictEqual(entry.framesReceived, 8); break; default: assert.fail('invalid Http2Session type'); } break; case 'Http2Stream': assert.strictEqual(typeof entry.timeToFirstByte, 'number'); assert.strictEqual(typeof entry.timeToFirstByteSent, 'number'); assert.strictEqual(typeof entry.timeToFirstHeader, 'number'); assert.strictEqual(typeof entry.bytesWritten, 'number'); assert.strictEqual(typeof entry.bytesRead, 'number'); break; default: assert.fail('invalid entry name'); } }, 4));