diff --git a/include/transport/memoryusage.h b/include/transport/memoryusage.h index 563d0e93..605dd157 100644 --- a/include/transport/memoryusage.h +++ b/include/transport/memoryusage.h @@ -24,12 +24,10 @@ #ifndef WIN32 #include "signal.h" +#else +#define pid_t void* #endif namespace Transport { - -#ifndef WIN32 void process_mem_usage(double& shared, double& resident_set, pid_t pid = 0); -#endif - } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e49efa8..10171852 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,7 +47,7 @@ endif(PROTOBUF_FOUND) if (WIN32) include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/sqlite3") - TARGET_LINK_LIBRARIES(transport transport-plugin sqlite3 ${PQXX_LIBRARY} ${PQ_LIBRARY} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES} ${PROTOBUF_LIBRARY}) + TARGET_LINK_LIBRARIES(transport transport-plugin sqlite3 ${PQXX_LIBRARY} ${PQ_LIBRARY} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES} ${PROTOBUF_LIBRARY} psapi.lib) else() TARGET_LINK_LIBRARIES(transport transport-plugin ${PQXX_LIBRARY} ${PQ_LIBRARY} ${SQLITE3_LIBRARIES} ${MYSQL_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES} ${POPT_LIBRARY} ${PROTOBUF_LIBRARY}) endif() diff --git a/src/admininterface.cpp b/src/admininterface.cpp index 3b8a40d1..d8591c18 100644 --- a/src/admininterface.cpp +++ b/src/admininterface.cpp @@ -136,10 +136,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) { else if (message->getBody() == "res_memory") { double shared = 0; double rss = 0; -#ifndef WIN32 process_mem_usage(shared, rss); -#endif - const std::list &backends = m_server->getBackends(); BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) { rss += backend->res; @@ -150,10 +147,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) { else if (message->getBody() == "shr_memory") { double shared = 0; double rss = 0; -#ifndef WIN32 process_mem_usage(shared, rss); -#endif - const std::list &backends = m_server->getBackends(); BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) { shared += backend->shared; @@ -164,9 +158,7 @@ void AdminInterface::handleQuery(Swift::Message::ref message) { else if (message->getBody() == "used_memory") { double shared = 0; double rss = 0; -#ifndef WIN32 process_mem_usage(shared, rss); -#endif rss -= shared; const std::list &backends = m_server->getBackends(); diff --git a/src/memoryusage.cpp b/src/memoryusage.cpp index 31ef5f8c..6f94743e 100644 --- a/src/memoryusage.cpp +++ b/src/memoryusage.cpp @@ -28,6 +28,9 @@ #include #ifndef WIN32 #include +#else +#include +#include #endif #ifdef __MACH__ #include @@ -138,6 +141,15 @@ void process_mem_usage(double& shared, double& resident_set, pid_t pid) { resident_set = rss * page_size_kb; } #endif /* else BSD */ +#else +#define PSAPI_VERSION 1 +#define pid_t void* + void process_mem_usage(double& shared, double& resident_set, pid_t pid) { + PROCESS_MEMORY_COUNTERS_EX pmc; + GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)); + shared = (double)pmc.PrivateUsage; + resident_set = (double)pmc.WorkingSetSize; + } #endif /* WIN32 */ }