Use higher resolution clock for uptime on Linux (if available).
This commit is contained in:
parent
502900c0bc
commit
2c185a9dfd
@ -2,7 +2,8 @@
|
||||
# configure node for building
|
||||
#
|
||||
include(CheckFunctionExists)
|
||||
|
||||
include(CheckLibraryExists)
|
||||
include(CheckSymbolExists)
|
||||
|
||||
if(NOT "v${CMAKE_BUILD_TYPE}" MATCHES vDebug)
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
@ -72,6 +73,20 @@ else()
|
||||
add_definitions(-DHAVE_FDATASYNC=0)
|
||||
endif()
|
||||
|
||||
# check first without rt and then with rt
|
||||
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME)
|
||||
check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME_RT)
|
||||
|
||||
if(HAVE_CLOCK_GETTIME OR HAVE_CLOCK_GETTIME_RT)
|
||||
check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_MONOTONIC_CLOCK)
|
||||
endif()
|
||||
|
||||
if(HAVE_MONOTONIC_CLOCK)
|
||||
add_definitions(-DHAVE_MONOTONIC_CLOCK=1)
|
||||
else()
|
||||
add_definitions(-DHAVE_MONOTONIC_CLOCK=0)
|
||||
endif()
|
||||
|
||||
if(DTRACE)
|
||||
if(NOT ${node_platform} MATCHES sunos)
|
||||
message(FATAL_ERROR "DTrace support only currently available on Solaris")
|
||||
|
@ -15,6 +15,10 @@
|
||||
#include <stdlib.h> // free
|
||||
#include <string.h> // strdup
|
||||
|
||||
#if HAVE_MONOTONIC_CLOCK
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
namespace node {
|
||||
|
||||
using namespace v8;
|
||||
@ -240,13 +244,21 @@ double Platform::GetTotalMemory() {
|
||||
}
|
||||
|
||||
double Platform::GetUptimeImpl() {
|
||||
#if HAVE_MONOTONIC_CLOCK
|
||||
struct timespec now;
|
||||
if (0 == clock_gettime(CLOCK_MONOTONIC, &now)) {
|
||||
double uptime = now.tv_sec;
|
||||
uptime += (double)now.tv_nsec / 1000000000.0;
|
||||
return uptime;
|
||||
}
|
||||
return -1;
|
||||
#else
|
||||
struct sysinfo info;
|
||||
|
||||
if (sysinfo(&info) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return static_cast<double>(info.uptime);
|
||||
#endif
|
||||
}
|
||||
|
||||
int Platform::GetLoadAvg(Local<Array> *loads) {
|
||||
|
19
wscript
19
wscript
@ -328,7 +328,24 @@ def configure(conf):
|
||||
elif 'DEST_CPU' in conf.env and conf.env['DEST_CPU']:
|
||||
conf.env['DEST_CPU'] = canonical_cpu_type(conf.env['DEST_CPU'])
|
||||
|
||||
conf.check(lib='rt', uselib_store='RT')
|
||||
have_librt = conf.check(lib='rt', uselib_store='RT')
|
||||
|
||||
have_monotonic = False
|
||||
if have_librt:
|
||||
code = """
|
||||
#include <time.h>
|
||||
int main(void) {
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
have_monotonic = conf.check_cc(lib="rt", msg="Checking for CLOCK_MONOTONIC", fragment=code)
|
||||
|
||||
if have_monotonic:
|
||||
conf.env.append_value('CPPFLAGS', '-DHAVE_MONOTONIC_CLOCK=1')
|
||||
else:
|
||||
conf.env.append_value('CPPFLAGS', '-DHAVE_MONOTONIC_CLOCK=0')
|
||||
|
||||
if sys.platform.startswith("sunos"):
|
||||
if not conf.check(lib='socket', uselib_store="SOCKET"):
|
||||
|
Loading…
x
Reference in New Issue
Block a user