-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_usage.h
36 lines (30 loc) · 1.02 KB
/
cpu_usage.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
#ifndef _CPU_USAGE_H_
#define _CPU_USAGE_H_
struct pstat {
long unsigned int utime_ticks;
long int cutime_ticks;
long unsigned int stime_ticks;
long int cstime_ticks;
long unsigned int vsize; // virtual memory size in bytes
long unsigned int rss; //Resident Set Size in bytes
long unsigned int cpu_total_time;
};
/*
* read /proc data into the passed struct pstat
* returns 0 on success, -1 on error
*/
int get_usage(const pid_t pid, struct pstat* result);
/*
* calculates the elapsed CPU usage between 2 measuring points. in percent
*/
void calc_cpu_usage_pct(const struct pstat* cur_usage,
const struct pstat* last_usage,
double* ucpu_usage, double* scpu_usage);
/*
* calculates the elapsed CPU usage between 2 measuring points in ticks
*/
void calc_cpu_usage(const struct pstat* cur_usage,
const struct pstat* last_usage,
long unsigned int* ucpu_usage,
long unsigned int* scpu_usage);
#endif