-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process.uptime() not correct when adjust time #2573
Comments
On what platform are you seeing this? I'm not sure I understand, libuv uses monotonic clocks - i.e. clocks that are unaffected by |
I mean js-function diff --git a/src/node.cc b/src/node.cc
index b900388..1751f09 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -1972,10 +1972,10 @@ static void Uptime(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
double uptime;
- uv_update_time(env->event_loop());
- uptime = uv_now(env->event_loop()) - prog_start_time;
+ uv_uptime(&uptime);
+ uptime -= prog_start_time;
- args.GetReturnValue().Set(Number::New(env->isolate(), uptime / 1000));
+ args.GetReturnValue().Set(Number::New(env->isolate(), uptime));
}
@@ -3606,8 +3606,7 @@ void Init(int* argc,
int* exec_argc,
const char*** exec_argv) {
// Initialize prog_start_time to get relative uptime.
- prog_start_time = static_cast<double>(uv_now(uv_default_loop()));
-
+ uv_uptime(&prog_start_time);
// Make inherited handles noninheritable.
|
There is no
Can you explain how? Like I said, libuv uses monotonic clocks (think On some platforms it doesn't matter if you use |
in netbsd, int uv_uptime(double* uptime) {
time_t now;
struct timeval info;
size_t size = sizeof(info);
static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno;
now = time(NULL);
*uptime = (double)(now - info.tv_sec);
return 0;
}
uint64_t uv__hrtime(uv_clocktype_t type) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec);
} I want to know, why |
I don't know the exact reason. Someone (@shigeki?) contributed that code a long time ago. |
All of the BSDs use the same |
I forgot the detail when I submitted netBSD patch in 3 years ago. Probably I referred FreeBSD implementation of I guess it comes from an old implementation of |
I think , we can update libuv implementation. And I was wondering why |
FWIW, this landed in libuv, thanks @yjhjstz! |
This was fixed by the upgrade to libuv 1.7.5. Thanks! |
Now ,
iojs
use relative time to computeuptime
[1], but when callsettimeofday
to change time,process.time()
isn't correct. So, my PR #2572 is to slove this, using time that refer to the kernel boot time.That's always ok at most platforms.
refer [1]: https://en.wikipedia.org/wiki/Uptime
The text was updated successfully, but these errors were encountered: