2017-08-07 15:53:24 -07:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
const {
|
|
|
|
ObjectDefineProperties,
|
|
|
|
ObjectDefineProperty,
|
2021-01-28 16:34:27 -08:00
|
|
|
ObjectSetPrototypeOf,
|
2021-01-30 09:26:15 -08:00
|
|
|
TypeError,
|
2019-11-22 18:04:46 +01:00
|
|
|
} = primordials;
|
2019-04-09 09:55:53 +02:00
|
|
|
|
2017-08-07 15:53:24 -07:00
|
|
|
const {
|
2018-02-25 14:26:22 -08:00
|
|
|
timeOriginTimestamp,
|
2019-02-01 01:04:44 +08:00
|
|
|
constants,
|
2018-07-30 01:34:51 -07:00
|
|
|
} = internalBinding('performance');
|
2017-08-07 15:53:24 -07:00
|
|
|
|
2021-03-06 10:07:54 +01:00
|
|
|
const {
|
|
|
|
EventTarget,
|
|
|
|
} = require('internal/event_target');
|
|
|
|
|
2017-08-07 15:53:24 -07:00
|
|
|
const {
|
2021-01-28 16:34:27 -08:00
|
|
|
PerformanceEntry,
|
|
|
|
now,
|
|
|
|
} = require('internal/perf/perf');
|
|
|
|
const { PerformanceObserver } = require('internal/perf/observe');
|
2017-08-07 15:53:24 -07:00
|
|
|
|
2019-03-19 18:17:49 +08:00
|
|
|
const {
|
2021-01-28 16:34:27 -08:00
|
|
|
PerformanceMark,
|
|
|
|
mark,
|
|
|
|
measure,
|
|
|
|
clearMarks,
|
|
|
|
} = require('internal/perf/usertiming');
|
2019-03-19 18:17:49 +08:00
|
|
|
|
2020-02-27 13:14:38 -08:00
|
|
|
const {
|
2021-01-28 16:34:27 -08:00
|
|
|
createHistogram
|
2020-02-27 13:14:38 -08:00
|
|
|
} = require('internal/histogram');
|
|
|
|
|
2021-01-28 16:34:27 -08:00
|
|
|
const eventLoopUtilization = require('internal/perf/event_loop_utilization');
|
|
|
|
const monitorEventLoopDelay = require('internal/perf/event_loop_delay');
|
|
|
|
const nodeTiming = require('internal/perf/nodetiming');
|
|
|
|
const timerify = require('internal/perf/timerify');
|
|
|
|
const { customInspectSymbol: kInspect } = require('internal/util');
|
|
|
|
const { inspect } = require('util');
|
2017-08-07 15:53:24 -07:00
|
|
|
|
2021-03-06 10:07:54 +01:00
|
|
|
class Performance extends EventTarget {
|
2017-08-07 15:53:24 -07:00
|
|
|
constructor() {
|
2021-01-28 16:34:27 -08:00
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
throw new TypeError('Illegal constructor');
|
2017-08-07 15:53:24 -07:00
|
|
|
}
|
|
|
|
|
2021-01-28 16:34:27 -08:00
|
|
|
[kInspect](depth, options) {
|
|
|
|
if (depth < 0) return this;
|
2020-08-25 13:36:37 -06:00
|
|
|
|
2021-01-28 16:34:27 -08:00
|
|
|
const opts = {
|
|
|
|
...options,
|
|
|
|
depth: options.depth == null ? null : options.depth - 1
|
|
|
|
};
|
2020-08-25 13:36:37 -06:00
|
|
|
|
2021-01-28 16:34:27 -08:00
|
|
|
return `Performance ${inspect({
|
2018-02-25 14:26:22 -08:00
|
|
|
nodeTiming: this.nodeTiming,
|
2020-08-25 13:36:37 -06:00
|
|
|
timeOrigin: this.timeOrigin,
|
2021-01-28 16:34:27 -08:00
|
|
|
}, opts)}`;
|
|
|
|
}
|
2021-03-16 22:15:02 +05:30
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function toJSON() {
|
|
|
|
return {
|
|
|
|
nodeTiming: this.nodeTiming,
|
|
|
|
timeOrigin: this.timeOrigin,
|
|
|
|
eventLoopUtilization: this.eventLoopUtilization()
|
|
|
|
};
|
2021-01-28 16:34:27 -08:00
|
|
|
}
|
|
|
|
|
2021-03-06 10:07:54 +01:00
|
|
|
class InternalPerformance extends EventTarget {}
|
2021-01-28 16:34:27 -08:00
|
|
|
InternalPerformance.prototype.constructor = Performance.prototype.constructor;
|
|
|
|
ObjectSetPrototypeOf(InternalPerformance.prototype, Performance.prototype);
|
|
|
|
|
|
|
|
ObjectDefineProperties(Performance.prototype, {
|
|
|
|
clearMarks: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: false,
|
|
|
|
value: clearMarks,
|
|
|
|
},
|
|
|
|
eventLoopUtilization: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: false,
|
|
|
|
value: eventLoopUtilization,
|
|
|
|
},
|
|
|
|
mark: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: false,
|
|
|
|
value: mark,
|
|
|
|
},
|
|
|
|
measure: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: false,
|
|
|
|
value: measure,
|
|
|
|
},
|
|
|
|
nodeTiming: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: false,
|
|
|
|
value: nodeTiming,
|
|
|
|
},
|
|
|
|
now: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: false,
|
|
|
|
value: now,
|
|
|
|
},
|
|
|
|
timerify: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: false,
|
|
|
|
value: timerify,
|
|
|
|
},
|
|
|
|
timeOrigin: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
value: timeOriginTimestamp,
|
2021-03-16 22:15:02 +05:30
|
|
|
},
|
|
|
|
toJSON: {
|
|
|
|
configurable: true,
|
|
|
|
enumerable: true,
|
|
|
|
value: toJSON,
|
2017-08-07 15:53:24 -07:00
|
|
|
}
|
2021-01-28 16:34:27 -08:00
|
|
|
});
|
2019-01-07 11:36:35 -08:00
|
|
|
|
2017-08-07 15:53:24 -07:00
|
|
|
module.exports = {
|
2021-01-28 16:34:27 -08:00
|
|
|
PerformanceEntry,
|
|
|
|
PerformanceMark,
|
2019-01-07 11:36:35 -08:00
|
|
|
PerformanceObserver,
|
2021-01-30 09:26:15 -08:00
|
|
|
monitorEventLoopDelay,
|
|
|
|
createHistogram,
|
2021-01-28 16:34:27 -08:00
|
|
|
performance: new InternalPerformance(),
|
2017-08-07 15:53:24 -07:00
|
|
|
};
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
ObjectDefineProperty(module.exports, 'constants', {
|
2017-08-07 15:53:24 -07:00
|
|
|
configurable: false,
|
|
|
|
enumerable: true,
|
|
|
|
value: constants
|
|
|
|
});
|