index.js
function performance() {
  /* eslint prefer-rest-params: 0 */
  const args = Array.from(arguments);
  const interval = get(args, isNumber, 100);
  const fn = get(args, isFunction, noop);
  const unitInfo = convertUnit(get(args, isString, 'B').toUpperCase());
  let start = process.hrtime();
  let cpuUsage = process.cpuUsage && process.cpuUsage();
  const timer = setInterval(() => {
    let result = {
      lag: getDelay(start, interval),
      heap: getHeapStatistics(unitInfo),
      memoryUsage: getMemoryUsage(unitInfo),
    };
    if (cpuUsage) {
      result.cpuUsage = getCpuUsage(cpuUsage, start);
    }
    if (v8.getHeapSpaceStatistics) {
      result.heapSpace = getHeapSpaceStatistics(unitInfo);
    }
    if (performance.flatten) {
      result = flatten(result);
    }
    if (performance.camelCase) {
      result = camelCaseData(result);
    }
    fn(result);
    start = process.hrtime();
    cpuUsage = process.cpuUsage && process.cpuUsage();
  }, interval);
  timer.unref();
  return timer;
}
function performance() {
  /* eslint prefer-rest-params: 0 */
  const args = Array.from(arguments);
  const interval = get(args, isNumber, 100);
  const fn = get(args, isFunction, noop);
  const unitInfo = convertUnit(get(args, isString, 'B').toUpperCase());
  let start = process.hrtime();
  let cpuUsage = process.cpuUsage && process.cpuUsage();
  const timer = setInterval(() => {
    let result = {
      lag: getDelay(start, interval),
      heap: getHeapStatistics(unitInfo),
      memoryUsage: getMemoryUsage(unitInfo),
    };
    if (cpuUsage) {
      result.cpuUsage = getCpuUsage(cpuUsage, start);
    }
    if (v8.getHeapSpaceStatistics) {
      result.heapSpace = getHeapSpaceStatistics(unitInfo);
    }
    if (performance.flatten) {
      result = flatten(result);
    }
    if (performance.camelCase) {
      result = camelCaseData(result);
    }
    fn(result);
    start = process.hrtime();
    cpuUsage = process.cpuUsage && process.cpuUsage();
  }, interval);
  timer.unref();
  return timer;
}
function performance ( ) { /* eslint prefer-rest-params: 0 */ const args = Array . from ( arguments ) ; const interval = get ( args , isNumber , 100 ) ; const fn = get ( args , isFunction , noop ) ; const unitInfo = convertUnit ( get ( args , isString , 'B' ) . toUpperCase ( ) ) ; let start = process . hrtime ( ) ; let cpuUsage = process . cpuUsage && process . cpuUsage ( ) ; const timer = setInterval ( ( ) => { let result = { lag : getDelay ( start , interval ) , heap : getHeapStatistics ( unitInfo ) , memoryUsage : getMemoryUsage ( unitInfo ) , } ; if ( cpuUsage ) { result . cpuUsage = getCpuUsage ( cpuUsage , start ) ; } if ( v8 . getHeapSpaceStatistics ) { result . heapSpace = getHeapSpaceStatistics ( unitInfo ) ; } if ( performance . flatten ) { result = flatten ( result ) ; } if ( performance . camelCase ) { result = camelCaseData ( result ) ; } fn ( result ) ; start = process . hrtime ( ) ; cpuUsage = process . cpuUsage && process . cpuUsage ( ) ; } , interval ) ; timer . unref ( ) ; return timer ; }
Get the performance of node, include lag, heap, heapSpace, cpuUsage, memoryUsage
@param {Function} fn The callback function of performance
@param {Interval} interval The interval of get performance
@returns {Timer} The setInterval timer
Get the performance of node include lag heap heapSpace cpuUsage memoryUsage