All files / lib/internal/perf perf.js

78.72% Statements 74/94
100% Branches 9/9
80% Functions 8/10
78.72% Lines 74/94

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 145862x 145862x 145862x 145862x 104x 77x 77x 77x 104x 104x 104x       104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x                   104x 104x                 104x 104x 104x 104x 77x 77x 77x 77x 77x 77x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x 104x  
'use strict';
 
const {
  ObjectSetPrototypeOf,
  Symbol,
  TypeError,
} = primordials;
 
const {
  timeOrigin,
} = internalBinding('performance');
 
const {
  customInspectSymbol: kInspect,
} = require('internal/util');
 
const { inspect } = require('util');
 
const kName = Symbol('kName');
const kType = Symbol('kType');
const kStart = Symbol('kStart');
const kDuration = Symbol('kDuration');
const kDetail = Symbol('kDetail');
const kReadOnlyAttributes = Symbol('kReadOnlyAttributes');
 
function now() {
  const hr = process.hrtime();
  return (hr[0] * 1000 + hr[1] / 1e6) - timeOrigin;
}
 
function isPerformanceEntry(obj) {
  return obj?.[kName] !== undefined;
}
 
class PerformanceEntry {
  constructor() {
    // eslint-disable-next-line no-restricted-syntax
    throw new TypeError('illegal constructor');
  }
 
  get name() { return this[kName]; }
 
  get entryType() { return this[kType]; }
 
  get startTime() { return this[kStart]; }
 
  get duration() { return this[kDuration]; }
 
  get detail() { return this[kDetail]; }
 
  [kInspect](depth, options) {
    if (depth < 0) return this;

    const opts = {
      ...options,
      depth: options.depth == null ? null : options.depth - 1
    };

    return `${this.constructor.name} ${inspect(this.toJSON(), opts)}`;
  }
 
  toJSON() {
    return {
      name: this.name,
      entryType: this.entryType,
      startTime: this.startTime,
      duration: this.duration,
      detail: this.detail,
    };
  }
}
 
class InternalPerformanceEntry {
  constructor(name, type, start, duration, detail) {
    this[kName] = name;
    this[kType] = type;
    this[kStart] = start;
    this[kDuration] = duration;
    this[kDetail] = detail;
  }
}
 
InternalPerformanceEntry.prototype.constructor = PerformanceEntry;
ObjectSetPrototypeOf(
  InternalPerformanceEntry.prototype,
  PerformanceEntry.prototype);
 
module.exports = {
  InternalPerformanceEntry,
  PerformanceEntry,
  kReadOnlyAttributes,
  isPerformanceEntry,
  now,
};