Browse Source

Use higher resolution clock for uptime on Linux (if available).

v0.7.4-release
Tom Hughes 14 years ago
committed by Ryan Dahl
parent
commit
2c185a9dfd
  1. 17
      cmake/configure.cmake
  2. 16
      src/platform_linux.cc
  3. 19
      wscript

17
cmake/configure.cmake

@ -2,7 +2,8 @@
# configure node for building # configure node for building
# #
include(CheckFunctionExists) include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckSymbolExists)
if(NOT "v${CMAKE_BUILD_TYPE}" MATCHES vDebug) if(NOT "v${CMAKE_BUILD_TYPE}" MATCHES vDebug)
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")
@ -72,6 +73,20 @@ else()
add_definitions(-DHAVE_FDATASYNC=0) add_definitions(-DHAVE_FDATASYNC=0)
endif() 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(DTRACE)
if(NOT ${node_platform} MATCHES sunos) if(NOT ${node_platform} MATCHES sunos)
message(FATAL_ERROR "DTrace support only currently available on Solaris") message(FATAL_ERROR "DTrace support only currently available on Solaris")

16
src/platform_linux.cc

@ -15,6 +15,10 @@
#include <stdlib.h> // free #include <stdlib.h> // free
#include <string.h> // strdup #include <string.h> // strdup
#if HAVE_MONOTONIC_CLOCK
#include <time.h>
#endif
namespace node { namespace node {
using namespace v8; using namespace v8;
@ -240,13 +244,21 @@ double Platform::GetTotalMemory() {
} }
double Platform::GetUptimeImpl() { 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; struct sysinfo info;
if (sysinfo(&info) < 0) { if (sysinfo(&info) < 0) {
return -1; return -1;
} }
return static_cast<double>(info.uptime); return static_cast<double>(info.uptime);
#endif
} }
int Platform::GetLoadAvg(Local<Array> *loads) { int Platform::GetLoadAvg(Local<Array> *loads) {

19
wscript

@ -328,7 +328,24 @@ def configure(conf):
elif 'DEST_CPU' in conf.env and conf.env['DEST_CPU']: elif 'DEST_CPU' in conf.env and conf.env['DEST_CPU']:
conf.env['DEST_CPU'] = canonical_cpu_type(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 sys.platform.startswith("sunos"):
if not conf.check(lib='socket', uselib_store="SOCKET"): if not conf.check(lib='socket', uselib_store="SOCKET"):

Loading…
Cancel
Save