On Mon, Mar 19, 2012 at 09:53, Darin <darin.chamb...@gmail.com> wrote: > I had 36 hours of uptime reported by my ubuntu system and only 7 hours of > uptime reported by node, which seemed about accurate for this weekend. I > likely only had 7 hours of use on my laptop and 29 hours in standby. > > If you dive into the source, os.uptime refers to uv_uptime which is defined > in libuv for linux > here: https://github.com/indutny/libuv/blob/master/src/unix/linux.c > > > uv_err_t uv_uptime(double* uptime) { > #ifdef CLOCK_MONOTONIC > struct timespec now; > if (0 == clock_gettime(CLOCK_MONOTONIC, &now)) { > *uptime = now.tv_sec; > *uptime += (double)now.tv_nsec / 1000000000.0; > return uv_ok_; > } > return uv__new_sys_error(errno); > #else > struct sysinfo info; > if (sysinfo(&info) < 0) { > return uv__new_sys_error(errno); > } > *uptime = (double)info.uptime; > return uv_ok_; > #endif > } > > Following a question and multiple answers on stack > overflow: http://stackoverflow.com/questions/3523442/difference-between-clock-realtime-and-clock-monotonic > it appears that the use of CLOCK_MONOTONIC ends up ignoring all standby time > and thus only reports time that the system was actually up and running. > > The following perl code reports the exact same number as node code: > perl -w -MTime::HiRes=clock_gettime,CLOCK_MONOTONIC -E 'say > clock_gettime(CLOCK_MONOTONIC)' > same as > node -e "console.log(require('os').uptime())" > > <>Darin
I've landed a fix in libuv[1] that makes it use CLOCK_BOOTTIME if available (2.6.39 and newer kernels). [1] https://github.com/joyent/libuv/commit/49d4e18 -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en