memory usage on Windows
This commit is contained in:
parent
1aba0d0d2e
commit
f4996ab8d3
4 changed files with 15 additions and 13 deletions
|
@ -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
|
||||
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 <NetworkPluginServer::Backend *> &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 <NetworkPluginServer::Backend *> &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 <NetworkPluginServer::Backend *> &backends = m_server->getBackends();
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
#include <boost/lexical_cast.hpp>
|
||||
#ifndef WIN32
|
||||
#include <sys/param.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
#endif
|
||||
#ifdef __MACH__
|
||||
#include <mach/mach.h>
|
||||
|
@ -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 */
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue