-
Notifications
You must be signed in to change notification settings - Fork 0
/
AFreeMemory.hpp
76 lines (65 loc) · 1.36 KB
/
AFreeMemory.hpp
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
75
76
#ifndef __SIX_AFREEMEMORY__
#define __SIX_AFREEMEMORY__
#include <map>
#include <string>
#include <vector>
#include <utility>
#include <iomanip>
#include <boost/log/trivial.hpp>
#include "FreeException.hpp"
#include "FreeUtils.hh"
namespace SixFree
{
class AFreeMemory
{
public:
AFreeMemory(bool swap=true)
{
_swap = swap;
}
virtual ~AFreeMemory() {}
virtual int run(size_t mem_perc)
{
float used;
float total;
try
{
check_files();
}
catch (const SixFree::FreeException& err)
{
BOOST_LOG_TRIVIAL(error) << err.what();
return (1);
}
show_status(used, total);
if ((used * 100) / total <= mem_perc)
{
free();
show_status(used, total);
}
else
BOOST_LOG_TRIVIAL(info) << "RAM OK";
return (0);
}
void printMemory(const std::string& mess,
const std::string& val)
{
std::pair<float, int> value = getHumanValue(_values[val]);
BOOST_LOG_TRIVIAL(info) << mess << std::setprecision(2)
<< value.first << *(_units.begin() + value.second);
}
virtual void show_status(float&, float&) = 0;
virtual void fillValues() = 0;
virtual void free() = 0;
protected:
bool _swap;
std::map<std::string, float> _values;
const std::vector<std::string> _units = {
"kB",
"mB",
"gB",
"tB",
};
};
}
#endif