All files / lib/internal/perf nodetiming.js

94.77% Statements 163/172
100% Branches 13/13
100% Functions 9/9
94.77% Lines 163/172

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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 226x 226x 226x 226x 177x 226x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 37x 37x 4096x 4096x 4096x 4096x 4096x 4096x 30x 30x 4096x 4096x 4096x 4096x 4096x 4096x 30x 30x 4096x 4096x 4096x 4096x 4096x 4096x 67x 67x 4096x 4096x 4096x 4096x 4096x 4096x 30x 30x 4096x 4096x 4096x 4096x 4096x 4096x 32x 32x 32x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 4096x 103x 103x                   103x 103x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 103x 103x 4096x 4096x 103x 103x 103x 103x 103x 103x 103x  
'use strict';
 
const {
  ObjectDefineProperties,
  ObjectSetPrototypeOf,
  SafeArrayIterator,
  SafeSet,
} = primordials;
 
const {
  PerformanceEntry,
  kReadOnlyAttributes,
  now,
} = require('internal/perf/perf');
 
const {
  customInspectSymbol: kInspect,
} = require('internal/util');
 
const { inspect } = require('util');
 
const {
  constants: {
    NODE_PERFORMANCE_MILESTONE_NODE_START,
    NODE_PERFORMANCE_MILESTONE_V8_START,
    NODE_PERFORMANCE_MILESTONE_LOOP_START,
    NODE_PERFORMANCE_MILESTONE_LOOP_EXIT,
    NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE,
    NODE_PERFORMANCE_MILESTONE_ENVIRONMENT
  },
  loopIdleTime,
  milestones,
  timeOrigin,
} = internalBinding('performance');
 
function getMilestoneTimestamp(milestoneIdx) {
  const ns = milestones[milestoneIdx];
  if (ns === -1)
    return ns;
  return ns / 1e6 - timeOrigin;
}
 
const readOnlyAttributes = new SafeSet(new SafeArrayIterator([
  'nodeStart',
  'v8Start',
  'environment',
  'loopStart',
  'loopExit',
  'bootstrapComplete',
]));
 
class PerformanceNodeTiming {
  constructor() {
    ObjectDefineProperties(this, {
      name: {
        enumerable: true,
        configurable: true,
        value: 'node'
      },
 
      entryType: {
        enumerable: true,
        configurable: true,
        value: 'node'
      },
 
      startTime: {
        enumerable: true,
        configurable: true,
        value: 0
      },
 
      duration: {
        enumerable: true,
        configurable: true,
        get: now
      },
 
      nodeStart: {
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
        }
      },
 
      v8Start: {
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
        }
      },
 
      environment: {
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
        }
      },
 
      loopStart: {
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
        }
      },
 
      loopExit: {
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
        }
      },
 
      bootstrapComplete: {
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(
            NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
        }
      },
 
      idleTime: {
        enumerable: true,
        configurable: true,
        get: loopIdleTime,
      }
    });
  }
 
  [kInspect](depth, options) {
    if (depth < 0) return this;

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

    return `PerformanceNodeTiming ${inspect(this.toJSON(), opts)}`;
  }
 
  toJSON() {
    return {
      name: 'node',
      entryType: 'node',
      startTime: this.startTime,
      duration: this.duration,
      nodeStart: this.nodeStart,
      v8Start: this.v8Start,
      bootstrapComplete: this.bootstrapComplete,
      environment: this.environment,
      loopStart: this.loopStart,
      loopExit: this.loopExit,
      idleTime: this.idleTime,
    };
  }
 
  static get [kReadOnlyAttributes]() {
    return readOnlyAttributes;
  }
}
 
ObjectSetPrototypeOf(
  PerformanceNodeTiming.prototype,
  PerformanceEntry.prototype);
 
module.exports = new PerformanceNodeTiming();