Report also skype process memory usage
This commit is contained in:
parent
3949b84ed0
commit
4c9f82cb35
3 changed files with 39 additions and 18 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "transport/config.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/memoryusage.h"
|
||||
#include "transport/logger.h"
|
||||
#include "transport/sqlite3backend.h"
|
||||
#include "transport/userregistration.h"
|
||||
|
@ -97,6 +98,10 @@ class Skype {
|
|||
bool createDBusProxy();
|
||||
bool loadSkypeBuddies();
|
||||
|
||||
int getPid() {
|
||||
return (int) m_pid;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_username;
|
||||
std::string m_password;
|
||||
|
@ -134,6 +139,19 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
|
|||
skype->login();
|
||||
}
|
||||
|
||||
void handleMemoryUsage(double &res, double &shared) {
|
||||
res = 0;
|
||||
shared = 0;
|
||||
for(std::map<std::string, Skype *>::const_iterator it = m_sessions.begin(); it != m_sessions.end(); it++) {
|
||||
Skype *skype = it->second;
|
||||
double r;
|
||||
double s;
|
||||
process_mem_usage(s, r, skype->getPid());
|
||||
res += r;
|
||||
shared += s;
|
||||
}
|
||||
}
|
||||
|
||||
void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
|
||||
Skype *skype = m_sessions[user];
|
||||
if (skype) {
|
||||
|
@ -834,17 +852,7 @@ int main(int argc, char **argv) {
|
|||
log4cxx::helpers::FileInputStream *istream = new log4cxx::helpers::FileInputStream(CONFIG_STRING(&config, "logging.backend_config"));
|
||||
|
||||
p.load(istream);
|
||||
|
||||
LogString pid, jid;
|
||||
log4cxx::helpers::Transcoder::decode(boost::lexical_cast<std::string>(getpid()), pid);
|
||||
log4cxx::helpers::Transcoder::decode(CONFIG_STRING(&config, "service.jid"), jid);
|
||||
#ifdef _MSC_VER
|
||||
p.setProperty(L"pid", pid);
|
||||
p.setProperty(L"jid", jid);
|
||||
#else
|
||||
p.setProperty("pid", pid);
|
||||
p.setProperty("jid", jid);
|
||||
#endif
|
||||
p.setProperty("pid", boost::lexical_cast<std::string>(getpid()));
|
||||
log4cxx::PropertyConfigurator::configure(p);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,14 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#ifndef WIN32
|
||||
#include "signal.h"
|
||||
#endif
|
||||
|
||||
namespace Transport {
|
||||
|
||||
#ifndef WIN32
|
||||
void process_mem_usage(double& shared, double& resident_set);
|
||||
void process_mem_usage(double& shared, double& resident_set, pid_t pid = 0);
|
||||
#endif
|
||||
|
||||
}
|
|
@ -25,6 +25,7 @@
|
|||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#ifndef WIN32
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
@ -41,13 +42,18 @@ namespace Transport {
|
|||
|
||||
#ifndef WIN32
|
||||
#ifdef BSD
|
||||
void process_mem_usage(double& vm_usage, double& resident_set) {
|
||||
void process_mem_usage(double& vm_usage, double& resident_set, pid_t pid) {
|
||||
int mib[4];
|
||||
size_t size;
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_PID;
|
||||
mib[3] = getpid();
|
||||
if (pid == 0) {
|
||||
mib[3] = getpid();
|
||||
}
|
||||
else {
|
||||
mib[3] = pid;
|
||||
}
|
||||
struct kinfo_proc proc;
|
||||
|
||||
size = sizeof(struct kinfo_proc);
|
||||
|
@ -75,7 +81,7 @@ void process_mem_usage(double& vm_usage, double& resident_set) {
|
|||
vm_usage = (double) proc.ki_size;
|
||||
}
|
||||
#else /* BSD */
|
||||
void process_mem_usage(double& shared, double& resident_set) {
|
||||
void process_mem_usage(double& shared, double& resident_set, pid_t pid) {
|
||||
using std::ios_base;
|
||||
using std::ifstream;
|
||||
using std::string;
|
||||
|
@ -84,8 +90,11 @@ void process_mem_usage(double& shared, double& resident_set) {
|
|||
resident_set = 0.0;
|
||||
|
||||
// 'file' stat seems to give the most reliable results
|
||||
//
|
||||
ifstream stat_stream("/proc/self/statm",ios_base::in);
|
||||
std::string f = "/proc/self/statm";
|
||||
if (pid != 0) {
|
||||
f = "/proc/" + boost::lexical_cast<std::string>(pid) + "/statm";
|
||||
}
|
||||
ifstream stat_stream(f.c_str(), ios_base::in);
|
||||
if (!stat_stream.is_open()) {
|
||||
shared = 0;
|
||||
resident_set = 0;
|
||||
|
@ -94,7 +103,7 @@ void process_mem_usage(double& shared, double& resident_set) {
|
|||
|
||||
// dummy vars for leading entries in stat that we don't care about
|
||||
//
|
||||
string pid, comm, state, ppid, pgrp, session, tty_nr;
|
||||
string pid1, comm, state, ppid, pgrp, session, tty_nr;
|
||||
string tpgid, flags, minflt, cminflt, majflt, cmajflt;
|
||||
string utime, stime, cutime, cstime, priority, nice;
|
||||
string O, itrealvalue, starttime;
|
||||
|
|
Loading…
Add table
Reference in a new issue