-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControl.cpp
74 lines (55 loc) · 1.73 KB
/
Control.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <fstream>
#include <unistd.h>
#include "sys/types.h"
#include "sys/sysinfo.h"
#include "inc/Control.hpp"
using namespace std;
bool ctr_debug = false;
Control::Control(){
init();
}
void Control::init(){
pages = sysconf(_SC_PHYS_PAGES);
page_size = sysconf(_SC_PAGE_SIZE);
}
long Control::getTotalSystemMemory(){
getValues();
return pages * page_size;
}
long Control::getFreeMemory(){
getValues();
return freeMemory;
}
long Control::getAvailableMemory(){
getValues();
return availableMemory;
}
long Control::getUsedMemory(){
getValues();
return usedMemory;
}
void Control::getValues(){
struct sysinfo memInfo;
sysinfo (&memInfo);
long long totalVirtualMem = memInfo.totalram;
//Add other values in next statement to avoid int overflow on right hand side...
totalVirtualMem += memInfo.totalswap;
totalVirtualMem *= memInfo.mem_unit;
//usedMemory = totalVirtualMem; https://stackoverflow.com/questions/8085830/how-to-remove-deleted-files-from-showing-up-in-my-local-git-status
//long long physMemUsed = memInfo.totalram - memInfo.freeram;
long long physMemUsed = memInfo.totalram - memInfo.freeram;
usedMemory = physMemUsed;
/*
int tSize = 0, resident = 0, share = 0;
ifstream buffer("/proc/self/statm");
buffer >> tSize >> resident >> share;
buffer.close();
long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
double rss = resident * page_size_kb;
//cout << "RSS - " << rss << " kB\n";
double shared_mem = share * page_size_kb;
//cout << "Shared Memory - " << shared_mem << " kB\n";
//cout << "Private Memory - " << rss - shared_mem << "kB\n";
*/
}