Skip to content

Commit

Permalink
process: fix calculation in process.uptime()
Browse files Browse the repository at this point in the history
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

PR-URL: #26206
Fixes: #26205
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information
joyeecheung authored and rvagg committed Feb 28, 2019
1 parent 6b7d836 commit fde4011
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 fde4011

Please sign in to comment.