Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
process: fix calculation in process.uptime()
In #26016 the result returned
by process.uptime() was mistakenly set to be based in the wrong
unit. This patch fixes the calculation and makes sure the returned
value is in seconds.

Refs: #26016
  • Loading branch information
joyeecheung authored and Trott committed Feb 19, 2019
commit bd09f7f3698deacb6e50f745d054f02500c42200
6 changes: 2 additions & 4 deletions src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ Mutex umask_mutex;

// Microseconds in a second, as a float, used in CPUUsage() below
#define MICROS_PER_SEC 1e6
// used in Hrtime() below
// used in Hrtime() and Uptime() below
#define NANOS_PER_SEC 1000000000
// Used in Uptime()
#define NANOS_PER_MICROS 1e3

#ifdef _WIN32
/* MAX_PATH is in characters, not bytes. Make sure we have enough headroom. */
Expand Down Expand Up @@ -246,7 +244,7 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {
uv_update_time(env->event_loop());
double uptime =
static_cast<double>(uv_hrtime() - per_process::node_start_time);
Local<Number> result = Number::New(env->isolate(), uptime / NANOS_PER_MICROS);
Local<Number> result = Number::New(env->isolate(), uptime / NANOS_PER_SEC);
args.GetReturnValue().Set(result);
}

Expand Down