From bd09f7f3698deacb6e50f745d054f02500c42200 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 20 Feb 2019 01:40:40 +0800 Subject: [PATCH] process: fix calculation in process.uptime() In https://github.com/nodejs/node/pull/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: https://github.com/nodejs/node/pull/26016 --- src/node_process_methods.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index dfcc6641a1c5f8..80027c26ebcf15 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -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. */ @@ -246,7 +244,7 @@ static void Uptime(const FunctionCallbackInfo& args) { uv_update_time(env->event_loop()); double uptime = static_cast(uv_hrtime() - per_process::node_start_time); - Local result = Number::New(env->isolate(), uptime / NANOS_PER_MICROS); + Local result = Number::New(env->isolate(), uptime / NANOS_PER_SEC); args.GetReturnValue().Set(result); }