Skip to content

Commit

Permalink
process: fix calculation in process.uptime()
Browse files Browse the repository at this point in the history
In nodejs#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: nodejs#26016
  • Loading branch information
joyeecheung authored and Trott committed Feb 19, 2019
1 parent 5f8ccec commit bd09f7f
Showing 1 changed file with 2 additions and 4 deletions.
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

0 comments on commit bd09f7f

Please sign in to comment.