-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystemInfo.h
85 lines (69 loc) · 1.87 KB
/
SystemInfo.h
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
77
78
79
80
81
82
83
84
85
#ifndef PROCESS_DISPATCHER_H
#define PROCESS_DISPATCHER_H
#include <string>
#include <iostream>
#include <vector>
#include <csignal>
#include <cstring>
#include <dirent.h>
#include <sys/types.h>
#include <fstream>
#include <cstdio>
#include <unistd.h>
#include <thread>
#include <chrono>
#include <tuple>
#include <sstream>
#include <algorithm>
#include "Types.h"
#define CP_USER 0
#define CP_NICE 1
#define CP_SYS 2
#define CP_IDLE 3
#define CP_STATES 4
enum BYTE_UNITS
{
BYTES = 0,
KILOBYTES = 1,
MEGABYTES = 2,
GIGABYTES = 3
};
struct MemoryStatus
{
float usedMem;
float totalMem;
float memUsage;
};
template <class T>
inline T convert_unit( T num, int to, int from = BYTES)
{
for( ; from < to; from++)
{
num /= 1024;
}
return num;
}
class SystemInfo {
private:
static bool charStartsWith(const char *a, const char *b);
static std::string parseProcessFileLine(std::string lineToParse);
static int getUsage(pid_t pid, struct ProcessStat* result);
static void calcCpuUsagePct(const struct ProcessStat* cur_usage,
const struct ProcessStat* last_usage,
double* ucpu_usage, double* scpu_usage);
static void processMemUsage(int pId, double& vm_usage, double& resident_set);
static int getTotalMemKb();
static void calcCpuUsage(ProcessList &processList);
static void calcMemUsage(ProcessList &processList);
static std::string getProcessName(int PID);
static Process getProcessInfo(int PID);
static const std::string PROC_DIR;
static const std::string PROC_STAT_FILE;
static const std::string PROC_STATUS_FILE;
public:
static ProcessList getListOfProcesses();
static float getCpuLoad(unsigned cpu_usage_delay);
static void getMemStatus(MemoryStatus & status);
static bool killProcess(int PID);
};
#endif //PROCESS_DISPATCHER_H