All files / lib/internal/perf nodetiming.js

100% Statements 160/160
83.33% Branches 10/12
100% Functions 8/8
100% Lines 160/160

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 16123x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 40x 40x 804x 804x 804x 804x 804x 804x 804x 32x 32x 804x 804x 804x 804x 804x 804x 804x 32x 32x 804x 804x 804x 804x 804x 804x 804x 69x 69x 804x 804x 804x 804x 804x 804x 804x 32x 32x 804x 804x 804x 804x 804x 804x 804x 34x 34x 34x 804x 804x 804x 804x 804x 804x 804x 804x 804x 804x 23x 23x 2x 2x 2x 2x 2x 2x 2x 2x 2x 23x 23x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 23x 23x 23x 23x 23x 23x 23x  
'use strict';
 
const {
  ObjectDefineProperties,
  ObjectSetPrototypeOf,
} = primordials;
 
const { PerformanceEntry } = require('internal/perf/performance_entry');
 
const {
  now,
  getMilestoneTimestamp,
} = require('internal/perf/utils');
 
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,
} = internalBinding('performance');
 
class PerformanceNodeTiming {
  constructor() {
    ObjectDefineProperties(this, {
      name: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        value: 'node'
      },
 
      entryType: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        value: 'node'
      },
 
      startTime: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        value: 0
      },
 
      duration: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        get: now
      },
 
      nodeStart: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
        }
      },
 
      v8Start: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
        }
      },
 
      environment: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
        }
      },
 
      loopStart: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
        }
      },
 
      loopExit: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
        }
      },
 
      bootstrapComplete: {
        __proto__: null,
        enumerable: true,
        configurable: true,
        get() {
          return getMilestoneTimestamp(
            NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
        }
      },
 
      idleTime: {
        __proto__: null,
        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,
    };
  }
}
 
ObjectSetPrototypeOf(
  PerformanceNodeTiming.prototype,
  PerformanceEntry.prototype);
 
module.exports = new PerformanceNodeTiming();