Changeset - f4996ab8d305
[Not reviewed]
0 4 0
Vitaly Takmazov - 13 years ago 2013-02-04 11:40:15
vitalyster@gmail.com
memory usage on Windows
4 files changed with 15 insertions and 13 deletions:
0 comments (0 inline, 0 general)
include/transport/memoryusage.h
Show inline comments
 
@@ -21,15 +21,13 @@
 
#pragma once
 

	
 
#include <vector>
 

	
 
#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
 

	
 
}
src/CMakeLists.txt
Show inline comments
 
@@ -44,13 +44,13 @@ endif(PROTOBUF_FOUND)
 
		ADD_DEFINITIONS(-fPIC)
 
	endif()
 
# endif()
 

	
 
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()
 

	
 
SET_TARGET_PROPERTIES(transport PROPERTIES
 
      VERSION ${TRANSPORT_VERSION} SOVERSION ${TRANSPORT_VERSION}
src/admininterface.cpp
Show inline comments
 
@@ -133,43 +133,35 @@ void AdminInterface::handleQuery(Swift::Message::ref message) {
 
		int backends = m_server->getBackendCount();
 
		message->setBody(boost::lexical_cast<std::string>(backends));
 
	}
 
	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;
 
		}
 

	
 
		message->setBody(boost::lexical_cast<std::string>(rss));
 
	}
 
	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;
 
		}
 

	
 
		message->setBody(boost::lexical_cast<std::string>(shared));
 
	}
 
	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();
 
		BOOST_FOREACH(NetworkPluginServer::Backend * backend, backends) {
 
			rss += backend->res - backend->shared;
 
		}
src/memoryusage.cpp
Show inline comments
 
@@ -25,12 +25,15 @@
 
#include <sstream>
 
#include <fstream>
 
#include <algorithm>
 
#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>
 
#elif BSD
 
#include <sys/types.h>
 
#include <sys/sysctl.h>
 
@@ -135,9 +138,18 @@ void process_mem_usage(double& shared, double& resident_set, pid_t pid) {
 

	
 
	long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
 
	shared     = shared_ * page_size_kb;
 
	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 */
 

	
 
}
0 comments (0 inline, 0 general)