node_patches/node8.9.3_modified/src/node.cc
// CPUUsage use libuv's uv_getrusage() this-process resource usage accessor,
// to access ru_utime (user CPU time used) and ru_stime (system CPU time used),
// which are uv_timeval_t structs (long tv_sec, long tv_usec).
// Returns those values as Float64 microseconds in the elements of the array
// passed to the function.
CPUUsage use libuv's uv_getrusage() this-process resource usage accessor,
to access ru_utime (user CPU time used) and ru_stime (system CPU time used),
which are uv_timeval_t structs (long tv_sec, long tv_usec).
Returns those values as Float64 microseconds in the elements of the array
passed to the function.
CPUUsage use libuv ' s uv_getrusage () this - process resource usage accessor to access ru_utime ( user CPU time used ) and ru_stime ( system CPU time used ) which are uv_timeval_t structs ( long tv_sec long tv_usec ) . Returns those values as Float64 microseconds in the elements of the array passed to the function .
static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
  uv_rusage_t rusage;
  int err = uv_getrusage(&rusage);
  if (err) {
    Local<String> errmsg = OneByteString(args.GetIsolate(), uv_strerror(err));
    args.GetReturnValue().Set(errmsg);
    return;
  }
  CHECK(args[0]->IsFloat64Array());
  Local<Float64Array> array = args[0].As<Float64Array>();
  CHECK_EQ(array->Length(), 2);
  Local<ArrayBuffer> ab = array->Buffer();
  double* fields = static_cast<double*>(ab->GetContents().Data());
  fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec;
  fields[1] = MICROS_PER_SEC * rusage.ru_stime.tv_sec + rusage.ru_stime.tv_usec;
}
static void CPUUsage ( const FunctionCallbackInfo < Value > & args ) { uv_rusage_t rusage ; int err = uv_getrusage ( & rusage ) ; if ( err ) { Local < String > errmsg = OneByteString ( args . GetIsolate ( ) , uv_strerror ( err ) ) ; args . GetReturnValue ( ) . Set ( errmsg ) ; return ; } CHECK ( args [ 0 ] -> IsFloat64Array ( ) ) ; Local < Float64Array > array = args [ 0 ] . As < Float64Array > ( ) ; CHECK_EQ ( array -> Length ( ) , 2 ) ; Local < ArrayBuffer > ab = array -> Buffer ( ) ; double * fields = static_cast < double * > ( ab -> GetContents ( ) . Data ( ) ) ; fields [ 0 ] = MICROS_PER_SEC * rusage . ru_utime . tv_sec + rusage . ru_utime . tv_usec ; fields [ 1 ] = MICROS_PER_SEC * rusage . ru_stime . tv_sec + rusage . ru_stime . tv_usec ; }
CPUUsage use libuv's uv_getrusage() this-process resource usage accessor,
to access ru_utime (user CPU time used) and ru_stime (system CPU time used),
which are uv_timeval_t structs (long tv_sec, long tv_usec).
CPUUsage use libuv ' s uv_getrusage () this - process resource usage accessor to access ru_utime ( user CPU time used ) and ru_stime ( system CPU time used ) which are uv_timeval_t structs ( long tv_sec long tv_usec ) .
// Call libuv to get the values we'll return. // On error, return the strerror version of the error code. // Get the double array pointer from the Float64Array argument. // Set the Float64Array elements to be user / system values in microseconds.