All files / lib/internal/perf nodetiming.js

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

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 15019x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 565x 40x 40x 565x 565x 565x 565x 565x 565x 32x 32x 565x 565x 565x 565x 565x 565x 32x 32x 565x 565x 565x 565x 565x 565x 69x 69x 565x 565x 565x 565x 565x 565x 32x 32x 565x 565x 565x 565x 565x 565x 34x 34x 34x 565x 565x 565x 565x 565x 565x 565x 565x 565x 19x 19x 2x 2x 2x 2x 2x 2x 2x 2x 2x 19x 19x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 19x 19x 19x 19x 19x 19x 19x  
'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: {
        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,
    };
  }
}
 
ObjectSetPrototypeOf(
  PerformanceNodeTiming.prototype,
  PerformanceEntry.prototype);
 
module.exports = new PerformanceNodeTiming();