summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Common/Backends/FileLogger.h2
-rw-r--r--src/Common/Backends/SystemBackendProc.cpp25
-rw-r--r--src/Common/Backends/SystemBackendProc.h11
-rw-r--r--src/Common/SystemBackend.h4
4 files changed, 23 insertions, 19 deletions
diff --git a/src/Common/Backends/FileLogger.h b/src/Common/Backends/FileLogger.h
index 8a72bec..09946df 100644
--- a/src/Common/Backends/FileLogger.h
+++ b/src/Common/Backends/FileLogger.h
@@ -36,7 +36,7 @@ class FileLogger : public Logger {
public:
FileLogger(const std::string &filename)
- : file(filename.c_str(), std::ios_base::out|std::ios_base::app) {}
+ : file(filename.c_str(), std::ios::out|std::ios::app) {}
};
}
diff --git a/src/Common/Backends/SystemBackendProc.cpp b/src/Common/Backends/SystemBackendProc.cpp
index 3a3f283..f2d9152 100644
--- a/src/Common/Backends/SystemBackendProc.cpp
+++ b/src/Common/Backends/SystemBackendProc.cpp
@@ -19,30 +19,29 @@
#include "SystemBackendProc.h"
-#include <fstream>
#include <pcrecpp.h>
namespace Mad {
namespace Common {
namespace Backends {
-SystemBackend::UptimeInfo SystemBackendProc::getUptimeInfo() const {
+SystemBackend::UptimeInfo SystemBackendProc::getUptimeInfo() {
UptimeInfo uptime = {0, 0};
- std::ifstream file("/proc/uptime");
+ uptimeFile.seekg(0, std::ios::beg);
- if(!file.good())
+ if(!uptimeFile.good())
return uptime;
float f;
- file >> f;
- if(!file.good())
+ uptimeFile >> f;
+ if(!uptimeFile.good())
return uptime;
uptime.uptime = (unsigned long)f;
- file >> f;
- if(!file.good())
+ uptimeFile >> f;
+ if(!uptimeFile.good())
return uptime;
uptime.idleTime = (unsigned long)f;
@@ -50,19 +49,19 @@ SystemBackend::UptimeInfo SystemBackendProc::getUptimeInfo() const {
return uptime;
}
-SystemBackend::MemoryInfo SystemBackendProc::getMemoryInfo() const {
+SystemBackend::MemoryInfo SystemBackendProc::getMemoryInfo() {
MemoryInfo memInfo = {0, 0, 0, 0};
- std::ifstream file("/proc/meminfo");
+ meminfoFile.seekg(0, std::ios::beg);
- if(!file.good())
+ if(!meminfoFile.good())
return memInfo;
pcrecpp::RE re("(.+):\\s*(\\d+).*");
- while(!file.eof() && file.good()) {
+ while(!meminfoFile.eof() && meminfoFile.good()) {
std::string line;
- std::getline(file, line);
+ std::getline(meminfoFile, line);
std::string name;
unsigned long value;
diff --git a/src/Common/Backends/SystemBackendProc.h b/src/Common/Backends/SystemBackendProc.h
index 2a85b86..fb9ecf5 100644
--- a/src/Common/Backends/SystemBackendProc.h
+++ b/src/Common/Backends/SystemBackendProc.h
@@ -22,21 +22,26 @@
#include "../SystemBackend.h"
+#include <fstream>
+
namespace Mad {
namespace Common {
namespace Backends {
class SystemBackendProc : public SystemBackend {
private:
- SystemBackendProc() {}
+ std::ifstream uptimeFile;
+ std::ifstream meminfoFile;
+
+ SystemBackendProc() : uptimeFile("/proc/uptime"), meminfoFile("/proc/meminfo") {}
public:
static void useBackend() {
setBackend(std::auto_ptr<SystemBackend>(new SystemBackendProc()));
}
- virtual UptimeInfo getUptimeInfo() const;
- virtual MemoryInfo getMemoryInfo() const;
+ virtual UptimeInfo getUptimeInfo();
+ virtual MemoryInfo getMemoryInfo();
};
}
diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h
index 8942ff0..9157e07 100644
--- a/src/Common/SystemBackend.h
+++ b/src/Common/SystemBackend.h
@@ -52,12 +52,12 @@ class SystemBackend {
virtual ~SystemBackend() {}
- virtual UptimeInfo getUptimeInfo() const {
+ virtual UptimeInfo getUptimeInfo() {
UptimeInfo ret = {0, 0};
return ret;
}
- virtual MemoryInfo getMemoryInfo() const {
+ virtual MemoryInfo getMemoryInfo() {
MemoryInfo ret = {0, 0, 0, 0};
return ret;
}