From ccad33b21d33d1a564f631b8708b1c3bcc165f3d Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Fri, 20 Dec 2013 12:12:36 +0100 Subject: [PATCH] added getTotalSystemMemory() function --- include/mitsuba/core/util.h | 3 +++ src/libcore/util.cpp | 13 +++++++++++++ src/libpython/core.cpp | 1 + 3 files changed, 17 insertions(+) diff --git a/include/mitsuba/core/util.h b/include/mitsuba/core/util.h index 49b00a98..0401adee 100644 --- a/include/mitsuba/core/util.h +++ b/include/mitsuba/core/util.h @@ -114,6 +114,9 @@ extern MTS_EXPORT_CORE std::string getHostName(); /// Return the process private memory usage in bytes extern MTS_EXPORT_CORE size_t getPrivateMemoryUsage(); +/// Returns the total amount of memory available to the OS +extern MTS_EXPORT_CORE size_t getTotalSystemMemory(); + /// Return the fully qualified domain name of this machine extern MTS_EXPORT_CORE std::string getFQDN(); diff --git a/src/libcore/util.cpp b/src/libcore/util.cpp index 3d321cd4..8c584c29 100644 --- a/src/libcore/util.cpp +++ b/src/libcore/util.cpp @@ -159,6 +159,19 @@ int getCoreCount() { #endif } +size_t getTotalSystemMemory() { +#if defined(__WINDOWS__) + MEMORYSTATUSEX status; + status.dwLength = sizeof(status); + GlobalMemoryStatusEx(&status); + return (size_t) status.ullTotalPhys; +#else + size_t pages = sysconf(_SC_PHYS_PAGES); + size_t page_size = sysconf(_SC_PAGE_SIZE); + return pages * page_size; +#endif +} + size_t getPrivateMemoryUsage() { #if defined(__WINDOWS__) PROCESS_MEMORY_COUNTERS_EX pmc; diff --git a/src/libpython/core.cpp b/src/libpython/core.cpp index fae751c2..7ec50060 100644 --- a/src/libpython/core.cpp +++ b/src/libpython/core.cpp @@ -2079,6 +2079,7 @@ void export_core() { bp::def("getCoreCount", &getCoreCount); bp::def("getHostName", &getHostName); bp::def("getPrivateMemoryUsage", &getPrivateMemoryUsage); + bp::def("getTotalSystemMemory", &getTotalSystemMemory); bp::def("getFQDN", &getFQDN); bp::def("rdtsc", &rdtsc); bp::def("hypot2", &hypot2);