summaryrefslogtreecommitdiffstats
path: root/src/Common/Backends/SystemBackendProc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/Backends/SystemBackendProc.cpp')
-rw-r--r--src/Common/Backends/SystemBackendProc.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/Common/Backends/SystemBackendProc.cpp b/src/Common/Backends/SystemBackendProc.cpp
index 51e14f8..e8c7357 100644
--- a/src/Common/Backends/SystemBackendProc.cpp
+++ b/src/Common/Backends/SystemBackendProc.cpp
@@ -19,8 +19,8 @@
#include "SystemBackendProc.h"
-#include <pcrecpp.h>
#include <cstdio>
+#include <cstring>
namespace Mad {
namespace Common {
@@ -58,26 +58,25 @@ SystemBackend::MemoryInfo SystemBackendProc::getMemoryInfo() {
if(!meminfoFile.good())
return memInfo;
- pcrecpp::RE re("(.+):\\s*(\\d+).*");
-
while(!meminfoFile.eof() && meminfoFile.good()) {
std::string line;
std::getline(meminfoFile, line);
- std::string name;
+ char *name = new char[line.length()+1]; // is always long enough
unsigned long value;
- if(!re.FullMatch(line, &name, &value))
- continue;
-
- if(name == "MemTotal")
- memInfo.totalMem = value;
- else if(name == "MemFree")
- memInfo.freeMem = value;
- else if(name == "SwapTotal")
- memInfo.totalSwap = value;
- else if(name == "SwapFree")
- memInfo.freeSwap = value;
+ if(std::sscanf(line.c_str(), "%s %lu", name, &value) == 2) {
+ if(std::strcmp(name, "MemTotal:") == 0)
+ memInfo.totalMem = value;
+ else if(std::strcmp(name, "MemFree:") == 0)
+ memInfo.freeMem = value;
+ else if(std::strcmp(name, "SwapTotal:") == 0)
+ memInfo.totalSwap = value;
+ else if(std::strcmp(name, "SwapFree:") == 0)
+ memInfo.freeSwap = value;
+ }
+
+ delete [] name;
if(memInfo.totalMem && memInfo.freeMem && memInfo.totalSwap && memInfo.freeSwap)
break;