Skip to content

Commit fde4011

Browse files
joyeecheungrvagg
authored andcommitted
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 PR-URL: #26206 Fixes: #26205 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 6b7d836 commit fde4011

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/node_process_methods.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ Mutex umask_mutex;
5757

5858
// Microseconds in a second, as a float, used in CPUUsage() below
5959
#define MICROS_PER_SEC 1e6
60-
// used in Hrtime() below
60+
// used in Hrtime() and Uptime() below
6161
#define NANOS_PER_SEC 1000000000
62-
// Used in Uptime()
63-
#define NANOS_PER_MICROS 1e3
6462

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

0 commit comments

Comments
 (0)