diff --git a/src/node_os.cc b/src/node_os.cc index 35f55836115..7e3e0896b7f 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -117,7 +117,7 @@ static Handle GetCPUInfo(const Arguments& args) { static Handle GetFreeMemory(const Arguments& args) { HandleScope scope; - double amount = Platform::GetFreeMemory(); + double amount = uv_get_free_memory(); if (amount < 0) { return Undefined(); @@ -128,7 +128,7 @@ static Handle GetFreeMemory(const Arguments& args) { static Handle GetTotalMemory(const Arguments& args) { HandleScope scope; - double amount = Platform::GetTotalMemory(); + double amount = uv_get_total_memory(); if (amount < 0) { return Undefined(); @@ -150,13 +150,18 @@ static Handle GetUptime(const Arguments& args) { static Handle GetLoadAvg(const Arguments& args) { HandleScope scope; - Local loads = Array::New(3); - int r = Platform::GetLoadAvg(&loads); + double loadavg[3]; + uv_loadavg(loadavg); - if (r < 0) { + if (loadavg[0] < 0) { return Undefined(); } + Local loads = Array::New(3); + loads->Set(0, Number::New(loadavg[0])); + loads->Set(1, Number::New(loadavg[1])); + loads->Set(2, Number::New(loadavg[2])); + return scope.Close(loads); } diff --git a/src/platform.h b/src/platform.h index 408d4781c56..8284bc188df 100644 --- a/src/platform.h +++ b/src/platform.h @@ -34,13 +34,10 @@ class Platform { static int GetMemory(size_t *rss, size_t *vsize); static int GetCPUInfo(v8::Local *cpus); - static double GetFreeMemory(); - static double GetTotalMemory(); static double GetUptime(bool adjusted = false) { return adjusted ? GetUptimeImpl() - prog_start_time : GetUptimeImpl(); } - static int GetLoadAvg(v8::Local *loads); static v8::Handle GetInterfaceAddresses(); private: static double GetUptimeImpl(); diff --git a/src/platform_cygwin.cc b/src/platform_cygwin.cc index 359fe920cd1..d53e476a506 100644 --- a/src/platform_cygwin.cc +++ b/src/platform_cygwin.cc @@ -321,20 +321,6 @@ int Platform::GetCPUInfo(Local *cpus) { return 0; } -double Platform::GetFreeMemory() { - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - double pages = static_cast(sysconf(_SC_AVPHYS_PAGES)); - - return static_cast(pages * pagesize); -} - -double Platform::GetTotalMemory() { - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - double pages = static_cast(sysconf(_SC_PHYS_PAGES)); - - return pages * pagesize; -} - double Platform::GetUptimeImpl() { double amount; char line[512]; @@ -352,12 +338,6 @@ double Platform::GetUptimeImpl() { return amount; } -int Platform::GetLoadAvg(Local *loads) { - // Unsupported as of cygwin 1.7.7 - return -1; -} - - Handle Platform::GetInterfaceAddresses() { HandleScope scope; return scope.Close(Object::New()); diff --git a/src/platform_darwin.cc b/src/platform_darwin.cc index a64597c88ed..49a34c41918 100644 --- a/src/platform_darwin.cc +++ b/src/platform_darwin.cc @@ -140,31 +140,6 @@ int Platform::GetCPUInfo(Local *cpus) { return 0; } -double Platform::GetFreeMemory() { - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - vm_statistics_data_t info; - mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t); - - if (host_statistics(mach_host_self(), HOST_VM_INFO, - (host_info_t)&info, &count) != KERN_SUCCESS) { - return -1; - } - - return (static_cast(info.free_count)) * pagesize; -} - -double Platform::GetTotalMemory() { - uint64_t info; - static int which[] = {CTL_HW, HW_MEMSIZE}; - size_t size = sizeof(info); - - if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { - return -1; - } - - return static_cast(info); -} - double Platform::GetUptimeImpl() { time_t now; struct timeval info; @@ -179,24 +154,6 @@ double Platform::GetUptimeImpl() { return static_cast(now - info.tv_sec); } -int Platform::GetLoadAvg(Local *loads) { - struct loadavg info; - size_t size = sizeof(info); - static int which[] = {CTL_VM, VM_LOADAVG}; - - if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { - return -1; - } - (*loads)->Set(0, Number::New(static_cast(info.ldavg[0]) - / static_cast(info.fscale))); - (*loads)->Set(1, Number::New(static_cast(info.ldavg[1]) - / static_cast(info.fscale))); - (*loads)->Set(2, Number::New(static_cast(info.ldavg[2]) - / static_cast(info.fscale))); - - return 0; -} - v8::Handle Platform::GetInterfaceAddresses() { HandleScope scope; diff --git a/src/platform_freebsd.cc b/src/platform_freebsd.cc index 7e60281418b..e5822729cae 100644 --- a/src/platform_freebsd.cc +++ b/src/platform_freebsd.cc @@ -154,31 +154,6 @@ int Platform::GetCPUInfo(Local *cpus) { return 0; } -double Platform::GetFreeMemory() { - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - unsigned int info = 0; - size_t size = sizeof(info); - - if (sysctlbyname("vm.stats.vm.v_free_count", &info, &size, NULL, 0) < 0) { - return -1; - } - - return (static_cast(info)) * pagesize; -} - -double Platform::GetTotalMemory() { - unsigned long info; - static int which[] = {CTL_HW, HW_PHYSMEM}; - - size_t size = sizeof(info); - - if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { - return -1; - } - - return static_cast(info); -} - double Platform::GetUptimeImpl() { time_t now; struct timeval info; @@ -193,24 +168,6 @@ double Platform::GetUptimeImpl() { return static_cast(now - info.tv_sec); } -int Platform::GetLoadAvg(Local *loads) { - struct loadavg info; - size_t size = sizeof(info); - static int which[] = {CTL_VM, VM_LOADAVG}; - - if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { - return -1; - } - (*loads)->Set(0, Number::New(static_cast(info.ldavg[0]) - / static_cast(info.fscale))); - (*loads)->Set(1, Number::New(static_cast(info.ldavg[1]) - / static_cast(info.fscale))); - (*loads)->Set(2, Number::New(static_cast(info.ldavg[2]) - / static_cast(info.fscale))); - - return 0; -} - Handle Platform::GetInterfaceAddresses() { HandleScope scope; diff --git a/src/platform_linux.cc b/src/platform_linux.cc index f8454eba72d..da78bda139b 100644 --- a/src/platform_linux.cc +++ b/src/platform_linux.cc @@ -25,8 +25,6 @@ #include #include // for MAXPATHLEN -#include -#include #include // getpagesize, sysconf #include // sscanf, snprintf @@ -257,20 +255,6 @@ int Platform::GetCPUInfo(Local *cpus) { return 0; } -double Platform::GetFreeMemory() { - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - double pages = static_cast(sysconf(_SC_AVPHYS_PAGES)); - - return static_cast(pages * pagesize); -} - -double Platform::GetTotalMemory() { - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - double pages = static_cast(sysconf(_SC_PHYS_PAGES)); - - return pages * pagesize; -} - double Platform::GetUptimeImpl() { #if HAVE_MONOTONIC_CLOCK struct timespec now; @@ -289,19 +273,6 @@ double Platform::GetUptimeImpl() { #endif } -int Platform::GetLoadAvg(Local *loads) { - struct sysinfo info; - - if (sysinfo(&info) < 0) { - return -1; - } - (*loads)->Set(0, Number::New(static_cast(info.loads[0]) / 65536.0)); - (*loads)->Set(1, Number::New(static_cast(info.loads[1]) / 65536.0)); - (*loads)->Set(2, Number::New(static_cast(info.loads[2]) / 65536.0)); - - return 0; -} - bool IsInternal(struct ifaddrs* addr) { return addr->ifa_flags & IFF_UP && diff --git a/src/platform_openbsd.cc b/src/platform_openbsd.cc index 50b4cac9bea..13395585345 100644 --- a/src/platform_openbsd.cc +++ b/src/platform_openbsd.cc @@ -153,36 +153,6 @@ int Platform::GetCPUInfo(Local *cpus) { return 0; } -double Platform::GetFreeMemory() { - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - struct uvmexp info; - size_t size = sizeof(info); - static int which[] = {CTL_VM, VM_UVMEXP}; - - if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { - return -1; - } - - return static_cast(info.free) * pagesize; -} - -double Platform::GetTotalMemory() { -#if defined(HW_PHYSMEM64) - uint64_t info; - static int which[] = {CTL_HW, HW_PHYSMEM64}; -#else - unsigned int info; - static int which[] = {CTL_HW, HW_PHYSMEM}; -#endif - size_t size = sizeof(info); - - if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { - return -1; - } - - return static_cast(info); -} - double Platform::GetUptimeImpl() { time_t now; struct timeval info; @@ -197,24 +167,6 @@ double Platform::GetUptimeImpl() { return static_cast(now - info.tv_sec); } -int Platform::GetLoadAvg(Local *loads) { - struct loadavg info; - size_t size = sizeof(info); - static int which[] = {CTL_VM, VM_LOADAVG}; - - if (sysctl(which, 2, &info, &size, NULL, 0) < 0) { - return -1; - } - (*loads)->Set(0, Number::New(static_cast(info.ldavg[0]) - / static_cast(info.fscale))); - (*loads)->Set(1, Number::New(static_cast(info.ldavg[1]) - / static_cast(info.fscale))); - (*loads)->Set(2, Number::New(static_cast(info.ldavg[2]) - / static_cast(info.fscale))); - - return 0; -} - Handle Platform::GetInterfaceAddresses() { HandleScope scope; diff --git a/src/platform_sunos.cc b/src/platform_sunos.cc index 1897b0d7144..03450a545fe 100644 --- a/src/platform_sunos.cc +++ b/src/platform_sunos.cc @@ -207,40 +207,6 @@ int Platform::GetCPUInfo(Local *cpus) { } -double Platform::GetFreeMemory() { - kstat_ctl_t *kc; - kstat_t *ksp; - kstat_named_t *knp; - - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - ulong_t freemem; - - if((kc = kstat_open()) == NULL) - throw "could not open kstat"; - - ksp = kstat_lookup(kc, (char *)"unix", 0, (char *)"system_pages"); - - if(kstat_read(kc, ksp, NULL) == -1){ - throw "could not read kstat"; - } - else { - knp = (kstat_named_t *) kstat_data_lookup(ksp, (char *)"freemem"); - freemem = knp->value.ul; - } - - kstat_close(kc); - - return static_cast(freemem)*pagesize; -} - - -double Platform::GetTotalMemory() { - double pagesize = static_cast(sysconf(_SC_PAGESIZE)); - double pages = static_cast(sysconf(_SC_PHYS_PAGES)); - - return pagesize*pages; -} - double Platform::GetUptimeImpl() { kstat_ctl_t *kc; kstat_t *ksp; @@ -266,18 +232,6 @@ double Platform::GetUptimeImpl() { return static_cast( clk_intr / hz ); } -int Platform::GetLoadAvg(Local *loads) { - HandleScope scope; - double loadavg[3]; - - (void) getloadavg(loadavg, 3); - (*loads)->Set(0, Number::New(loadavg[LOADAVG_1MIN])); - (*loads)->Set(1, Number::New(loadavg[LOADAVG_5MIN])); - (*loads)->Set(2, Number::New(loadavg[LOADAVG_15MIN])); - - return 0; -} - Handle Platform::GetInterfaceAddresses() { HandleScope scope; diff --git a/src/platform_win32.cc b/src/platform_win32.cc index dbc71355632..e840bfee146 100644 --- a/src/platform_win32.cc +++ b/src/platform_win32.cc @@ -214,34 +214,6 @@ int Platform::GetMemory(size_t *rss, size_t *vsize) { return 0; } - -double Platform::GetFreeMemory() { - - MEMORYSTATUSEX memory_status; - memory_status.dwLength = sizeof(memory_status); - - if(!GlobalMemoryStatusEx(&memory_status)) - { - winapi_perror("GlobalMemoryStatusEx"); - } - - return (double)memory_status.ullAvailPhys; -} - -double Platform::GetTotalMemory() { - - MEMORYSTATUSEX memory_status; - memory_status.dwLength = sizeof(memory_status); - - if(!GlobalMemoryStatusEx(&memory_status)) - { - winapi_perror("GlobalMemoryStatusEx"); - } - - return (double)memory_status.ullTotalPhys; -} - - int Platform::GetCPUInfo(Local *cpus) { return -1; } @@ -251,11 +223,6 @@ double Platform::GetUptimeImpl() { return (double)GetTickCount()/1000.0; } -int Platform::GetLoadAvg(Local *loads) { - return -1; -} - - Handle Platform::GetInterfaceAddresses() { HandleScope scope; return scope.Close(Object::New());