JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
MemoryUtility.h
Go to the documentation of this file.
1 //
2 // Created by Nico Schäfer on 5/16/17.
3 //
4 
5 #ifndef JODA_MEMORYUTILITY_H
6 #define JODA_MEMORYUTILITY_H
7 #include <cstdio>
8 #include <cstdlib>
9 #include <string>
10 #include "sys/sysinfo.h"
11 #include "sys/types.h"
12 
18  public:
19  typedef unsigned long long MemoryT;
25  class MemorySize {
26  public:
30  enum SIZE { B = 0, KB = 1, MB = 2, GB = 3, TB = 4, PB = 5, EB = 6 };
31 
36  MemorySize(const MemoryT bytes);
37 
45  static MemoryT convertToBytes(const MemoryT xbytes,
46  const int powerOfThousand = SIZE::B);
47 
55  static MemoryT convertToBytesSI(const MemoryT xbytes,
56  const int powerOfThousand = SIZE::B);
57 
61  MemoryT getBytes() const;
62 
69  MemoryT getBase(const int base = SIZE::B) const;
70 
77  MemoryT getBaseSI(const int base = SIZE::B) const;
78 
85  double getFBase(const int base = SIZE::B) const;
86 
93  double getFBaseSI(const int base = SIZE::B) const;
94 
100  std::string getHumanReadable() const;
101 
107  std::string getHumanReadableSI() const;
108 
109  private:
110  // 0 to 18,446,744,073,709,551,615 => supports up to 18 exabyte
111  MemoryT bytes;
112  };
113 
118  static MemorySize totalRam();
119 
124  static MemorySize sysRamUsage();
125 
130  static MemorySize procRamUsage();
131 
136  static MemorySize remainingRam();
137 
142  static double getFreeRam();
143 
148  static std::string getRamUsage();
149 
155  static std::string humanReadablePercent(double num);
156 
157  private:
158  static int parseLine(char* line);
159 };
160 
161 #endif // JODA_MEMORYUTILITY_H
Definition: MemoryUtility.h:25
MemoryT getBase(const int base=SIZE::B) const
Definition: MemoryUtility.cpp:31
std::string getHumanReadable() const
Definition: MemoryUtility.cpp:49
MemoryT getBaseSI(const int base=SIZE::B) const
Definition: MemoryUtility.cpp:36
MemorySize(const MemoryT bytes)
Definition: MemoryUtility.cpp:15
SIZE
Definition: MemoryUtility.h:30
@ PB
Definition: MemoryUtility.h:30
@ EB
Definition: MemoryUtility.h:30
@ TB
Definition: MemoryUtility.h:30
@ KB
Definition: MemoryUtility.h:30
@ MB
Definition: MemoryUtility.h:30
@ GB
Definition: MemoryUtility.h:30
@ B
Definition: MemoryUtility.h:30
MemoryT getBytes() const
Definition: MemoryUtility.cpp:27
static MemoryT convertToBytesSI(const MemoryT xbytes, const int powerOfThousand=SIZE::B)
Definition: MemoryUtility.cpp:22
std::string getHumanReadableSI() const
Definition: MemoryUtility.cpp:67
double getFBaseSI(const int base=SIZE::B) const
Definition: MemoryUtility.cpp:45
double getFBase(const int base=SIZE::B) const
Definition: MemoryUtility.cpp:41
static MemoryT convertToBytes(const MemoryT xbytes, const int powerOfThousand=SIZE::B)
Definition: MemoryUtility.cpp:17
Definition: MemoryUtility.h:17
static double getFreeRam()
Definition: MemoryUtility.cpp:146
static MemorySize remainingRam()
Definition: MemoryUtility.cpp:101
static MemorySize procRamUsage()
Definition: MemoryUtility.cpp:123
static std::string humanReadablePercent(double num)
Definition: MemoryUtility.cpp:151
static std::string getRamUsage()
Definition: MemoryUtility.cpp:139
unsigned long long MemoryT
Definition: MemoryUtility.h:19
static MemorySize totalRam()
Definition: MemoryUtility.cpp:81
static MemorySize sysRamUsage()
Definition: MemoryUtility.cpp:91