Changeset - 098a8d4c944c
[Not reviewed]
Merge
0 4 0
Jan Kaluza - 12 years ago 2013-02-04 19:46:32
hanzz.k@gmail.com
Merge pull request #26 from vitalyster/win32_memusage

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
 
@@ -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
 

	
 
}
src/CMakeLists.txt
Show inline comments
 
@@ -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()
src/admininterface.cpp
Show inline comments
 
@@ -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();
src/memoryusage.cpp
Show inline comments
 
@@ -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 */
 

	
 
}
0 comments (0 inline, 0 general)