11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst { 41cb0ef41Sopenharmony_ci ObjectDefineProperty, 51cb0ef41Sopenharmony_ci ObjectDefineProperties, 61cb0ef41Sopenharmony_ci ObjectSetPrototypeOf, 71cb0ef41Sopenharmony_ci} = primordials; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst { 101cb0ef41Sopenharmony_ci codes: { 111cb0ef41Sopenharmony_ci ERR_ILLEGAL_CONSTRUCTOR, 121cb0ef41Sopenharmony_ci ERR_MISSING_ARGS, 131cb0ef41Sopenharmony_ci }, 141cb0ef41Sopenharmony_ci} = require('internal/errors'); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst { 171cb0ef41Sopenharmony_ci EventTarget, 181cb0ef41Sopenharmony_ci Event, 191cb0ef41Sopenharmony_ci kTrustEvent, 201cb0ef41Sopenharmony_ci} = require('internal/event_target'); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciconst { now } = require('internal/perf/utils'); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciconst { markResourceTiming } = require('internal/perf/resource_timing'); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ciconst { 271cb0ef41Sopenharmony_ci mark, 281cb0ef41Sopenharmony_ci measure, 291cb0ef41Sopenharmony_ci clearMarkTimings, 301cb0ef41Sopenharmony_ci} = require('internal/perf/usertiming'); 311cb0ef41Sopenharmony_ciconst { 321cb0ef41Sopenharmony_ci clearEntriesFromBuffer, 331cb0ef41Sopenharmony_ci filterBufferMapByNameAndType, 341cb0ef41Sopenharmony_ci setResourceTimingBufferSize, 351cb0ef41Sopenharmony_ci setDispatchBufferFull, 361cb0ef41Sopenharmony_ci} = require('internal/perf/observe'); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ciconst eventLoopUtilization = require('internal/perf/event_loop_utilization'); 391cb0ef41Sopenharmony_ciconst nodeTiming = require('internal/perf/nodetiming'); 401cb0ef41Sopenharmony_ciconst timerify = require('internal/perf/timerify'); 411cb0ef41Sopenharmony_ciconst { customInspectSymbol: kInspect } = require('internal/util'); 421cb0ef41Sopenharmony_ciconst { inspect } = require('util'); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ciconst { 451cb0ef41Sopenharmony_ci getTimeOriginTimestamp, 461cb0ef41Sopenharmony_ci} = internalBinding('performance'); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciclass Performance extends EventTarget { 491cb0ef41Sopenharmony_ci constructor() { 501cb0ef41Sopenharmony_ci throw new ERR_ILLEGAL_CONSTRUCTOR(); 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci [kInspect](depth, options) { 541cb0ef41Sopenharmony_ci if (depth < 0) return this; 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci const opts = { 571cb0ef41Sopenharmony_ci ...options, 581cb0ef41Sopenharmony_ci depth: options.depth == null ? null : options.depth - 1, 591cb0ef41Sopenharmony_ci }; 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci return `Performance ${inspect({ 621cb0ef41Sopenharmony_ci nodeTiming: this.nodeTiming, 631cb0ef41Sopenharmony_ci timeOrigin: this.timeOrigin, 641cb0ef41Sopenharmony_ci }, opts)}`; 651cb0ef41Sopenharmony_ci } 661cb0ef41Sopenharmony_ci} 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_cifunction toJSON() { 691cb0ef41Sopenharmony_ci return { 701cb0ef41Sopenharmony_ci nodeTiming: this.nodeTiming, 711cb0ef41Sopenharmony_ci timeOrigin: this.timeOrigin, 721cb0ef41Sopenharmony_ci eventLoopUtilization: this.eventLoopUtilization(), 731cb0ef41Sopenharmony_ci }; 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_cifunction clearMarks(name) { 771cb0ef41Sopenharmony_ci if (name !== undefined) { 781cb0ef41Sopenharmony_ci name = `${name}`; 791cb0ef41Sopenharmony_ci } 801cb0ef41Sopenharmony_ci clearMarkTimings(name); 811cb0ef41Sopenharmony_ci clearEntriesFromBuffer('mark', name); 821cb0ef41Sopenharmony_ci} 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_cifunction clearMeasures(name) { 851cb0ef41Sopenharmony_ci if (name !== undefined) { 861cb0ef41Sopenharmony_ci name = `${name}`; 871cb0ef41Sopenharmony_ci } 881cb0ef41Sopenharmony_ci clearEntriesFromBuffer('measure', name); 891cb0ef41Sopenharmony_ci} 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_cifunction clearResourceTimings(name) { 921cb0ef41Sopenharmony_ci if (name !== undefined) { 931cb0ef41Sopenharmony_ci name = `${name}`; 941cb0ef41Sopenharmony_ci } 951cb0ef41Sopenharmony_ci clearEntriesFromBuffer('resource', name); 961cb0ef41Sopenharmony_ci} 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_cifunction getEntries() { 991cb0ef41Sopenharmony_ci return filterBufferMapByNameAndType(); 1001cb0ef41Sopenharmony_ci} 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_cifunction getEntriesByName(name) { 1031cb0ef41Sopenharmony_ci if (arguments.length === 0) { 1041cb0ef41Sopenharmony_ci throw new ERR_MISSING_ARGS('name'); 1051cb0ef41Sopenharmony_ci } 1061cb0ef41Sopenharmony_ci name = `${name}`; 1071cb0ef41Sopenharmony_ci return filterBufferMapByNameAndType(name, undefined); 1081cb0ef41Sopenharmony_ci} 1091cb0ef41Sopenharmony_ci 1101cb0ef41Sopenharmony_cifunction getEntriesByType(type) { 1111cb0ef41Sopenharmony_ci if (arguments.length === 0) { 1121cb0ef41Sopenharmony_ci throw new ERR_MISSING_ARGS('type'); 1131cb0ef41Sopenharmony_ci } 1141cb0ef41Sopenharmony_ci type = `${type}`; 1151cb0ef41Sopenharmony_ci return filterBufferMapByNameAndType(undefined, type); 1161cb0ef41Sopenharmony_ci} 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ciclass InternalPerformance extends EventTarget {} 1191cb0ef41Sopenharmony_ciInternalPerformance.prototype.constructor = Performance.prototype.constructor; 1201cb0ef41Sopenharmony_ciObjectSetPrototypeOf(InternalPerformance.prototype, Performance.prototype); 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ciObjectDefineProperties(Performance.prototype, { 1231cb0ef41Sopenharmony_ci clearMarks: { 1241cb0ef41Sopenharmony_ci __proto__: null, 1251cb0ef41Sopenharmony_ci configurable: true, 1261cb0ef41Sopenharmony_ci enumerable: false, 1271cb0ef41Sopenharmony_ci value: clearMarks, 1281cb0ef41Sopenharmony_ci }, 1291cb0ef41Sopenharmony_ci clearMeasures: { 1301cb0ef41Sopenharmony_ci __proto__: null, 1311cb0ef41Sopenharmony_ci configurable: true, 1321cb0ef41Sopenharmony_ci enumerable: false, 1331cb0ef41Sopenharmony_ci value: clearMeasures, 1341cb0ef41Sopenharmony_ci }, 1351cb0ef41Sopenharmony_ci clearResourceTimings: { 1361cb0ef41Sopenharmony_ci __proto__: null, 1371cb0ef41Sopenharmony_ci configurable: true, 1381cb0ef41Sopenharmony_ci enumerable: false, 1391cb0ef41Sopenharmony_ci value: clearResourceTimings, 1401cb0ef41Sopenharmony_ci }, 1411cb0ef41Sopenharmony_ci eventLoopUtilization: { 1421cb0ef41Sopenharmony_ci __proto__: null, 1431cb0ef41Sopenharmony_ci configurable: true, 1441cb0ef41Sopenharmony_ci enumerable: false, 1451cb0ef41Sopenharmony_ci value: eventLoopUtilization, 1461cb0ef41Sopenharmony_ci }, 1471cb0ef41Sopenharmony_ci getEntries: { 1481cb0ef41Sopenharmony_ci __proto__: null, 1491cb0ef41Sopenharmony_ci configurable: true, 1501cb0ef41Sopenharmony_ci enumerable: false, 1511cb0ef41Sopenharmony_ci value: getEntries, 1521cb0ef41Sopenharmony_ci }, 1531cb0ef41Sopenharmony_ci getEntriesByName: { 1541cb0ef41Sopenharmony_ci __proto__: null, 1551cb0ef41Sopenharmony_ci configurable: true, 1561cb0ef41Sopenharmony_ci enumerable: false, 1571cb0ef41Sopenharmony_ci value: getEntriesByName, 1581cb0ef41Sopenharmony_ci }, 1591cb0ef41Sopenharmony_ci getEntriesByType: { 1601cb0ef41Sopenharmony_ci __proto__: null, 1611cb0ef41Sopenharmony_ci configurable: true, 1621cb0ef41Sopenharmony_ci enumerable: false, 1631cb0ef41Sopenharmony_ci value: getEntriesByType, 1641cb0ef41Sopenharmony_ci }, 1651cb0ef41Sopenharmony_ci mark: { 1661cb0ef41Sopenharmony_ci __proto__: null, 1671cb0ef41Sopenharmony_ci configurable: true, 1681cb0ef41Sopenharmony_ci enumerable: false, 1691cb0ef41Sopenharmony_ci value: mark, 1701cb0ef41Sopenharmony_ci }, 1711cb0ef41Sopenharmony_ci measure: { 1721cb0ef41Sopenharmony_ci __proto__: null, 1731cb0ef41Sopenharmony_ci configurable: true, 1741cb0ef41Sopenharmony_ci enumerable: false, 1751cb0ef41Sopenharmony_ci value: measure, 1761cb0ef41Sopenharmony_ci }, 1771cb0ef41Sopenharmony_ci nodeTiming: { 1781cb0ef41Sopenharmony_ci __proto__: null, 1791cb0ef41Sopenharmony_ci configurable: true, 1801cb0ef41Sopenharmony_ci enumerable: false, 1811cb0ef41Sopenharmony_ci value: nodeTiming, 1821cb0ef41Sopenharmony_ci }, 1831cb0ef41Sopenharmony_ci // In the browser, this function is not public. However, it must be used inside fetch 1841cb0ef41Sopenharmony_ci // which is a Node.js dependency, not a internal module 1851cb0ef41Sopenharmony_ci markResourceTiming: { 1861cb0ef41Sopenharmony_ci __proto__: null, 1871cb0ef41Sopenharmony_ci configurable: true, 1881cb0ef41Sopenharmony_ci enumerable: false, 1891cb0ef41Sopenharmony_ci value: markResourceTiming, 1901cb0ef41Sopenharmony_ci }, 1911cb0ef41Sopenharmony_ci now: { 1921cb0ef41Sopenharmony_ci __proto__: null, 1931cb0ef41Sopenharmony_ci configurable: true, 1941cb0ef41Sopenharmony_ci enumerable: false, 1951cb0ef41Sopenharmony_ci value: now, 1961cb0ef41Sopenharmony_ci }, 1971cb0ef41Sopenharmony_ci setResourceTimingBufferSize: { 1981cb0ef41Sopenharmony_ci __proto__: null, 1991cb0ef41Sopenharmony_ci configurable: true, 2001cb0ef41Sopenharmony_ci enumerable: false, 2011cb0ef41Sopenharmony_ci value: setResourceTimingBufferSize, 2021cb0ef41Sopenharmony_ci }, 2031cb0ef41Sopenharmony_ci timerify: { 2041cb0ef41Sopenharmony_ci __proto__: null, 2051cb0ef41Sopenharmony_ci configurable: true, 2061cb0ef41Sopenharmony_ci enumerable: false, 2071cb0ef41Sopenharmony_ci value: timerify, 2081cb0ef41Sopenharmony_ci }, 2091cb0ef41Sopenharmony_ci timeOrigin: { 2101cb0ef41Sopenharmony_ci __proto__: null, 2111cb0ef41Sopenharmony_ci configurable: true, 2121cb0ef41Sopenharmony_ci enumerable: true, 2131cb0ef41Sopenharmony_ci get() { 2141cb0ef41Sopenharmony_ci const value = getTimeOriginTimestamp(); 2151cb0ef41Sopenharmony_ci ObjectDefineProperty(Performance.prototype, 'timeOrigin', { 2161cb0ef41Sopenharmony_ci __proto__: null, 2171cb0ef41Sopenharmony_ci value, 2181cb0ef41Sopenharmony_ci }); 2191cb0ef41Sopenharmony_ci return value; 2201cb0ef41Sopenharmony_ci }, 2211cb0ef41Sopenharmony_ci set(value) { 2221cb0ef41Sopenharmony_ci ObjectDefineProperty(Performance.prototype, 'timeOrigin', { 2231cb0ef41Sopenharmony_ci __proto__: null, 2241cb0ef41Sopenharmony_ci value, 2251cb0ef41Sopenharmony_ci }); 2261cb0ef41Sopenharmony_ci }, 2271cb0ef41Sopenharmony_ci }, 2281cb0ef41Sopenharmony_ci toJSON: { 2291cb0ef41Sopenharmony_ci __proto__: null, 2301cb0ef41Sopenharmony_ci configurable: true, 2311cb0ef41Sopenharmony_ci enumerable: true, 2321cb0ef41Sopenharmony_ci value: toJSON, 2331cb0ef41Sopenharmony_ci }, 2341cb0ef41Sopenharmony_ci}); 2351cb0ef41Sopenharmony_ci 2361cb0ef41Sopenharmony_ciconst performance = new InternalPerformance(); 2371cb0ef41Sopenharmony_ci 2381cb0ef41Sopenharmony_cifunction dispatchBufferFull(type) { 2391cb0ef41Sopenharmony_ci const event = new Event(type, { 2401cb0ef41Sopenharmony_ci [kTrustEvent]: true, 2411cb0ef41Sopenharmony_ci }); 2421cb0ef41Sopenharmony_ci performance.dispatchEvent(event); 2431cb0ef41Sopenharmony_ci} 2441cb0ef41Sopenharmony_cisetDispatchBufferFull(dispatchBufferFull); 2451cb0ef41Sopenharmony_ci 2461cb0ef41Sopenharmony_cimodule.exports = { 2471cb0ef41Sopenharmony_ci Performance, 2481cb0ef41Sopenharmony_ci performance, 2491cb0ef41Sopenharmony_ci}; 250