10 #include <fmt/format.h> 16 namespace process_info
26 g_kernel_hz = sysconf(_SC_CLK_TCK);
29 fmt::print(stderr,
"Warning: Could not obtain value of USER_HZ." 30 "CPU load measurements might be inaccurate.\n" 41 if(g_page_size == (std::size_t)-1)
43 g_page_size = sysconf(_SC_PAGESIZE);
44 if(g_page_size == (std::size_t)-1)
46 fmt::print(stderr,
"Warning: Could not obtain page size.");
56 FILE*
f = fopen(filename,
"r");
61 int ret = fread(buf, 1,
sizeof(buf)-1, f);
69 unsigned long pid = 0;
70 if(sscanf(buf,
"%lu", &pid) != 1)
74 char*
start = strrchr(buf,
')');
76 if(start - buf > (
int)strlen(buf) - 4)
82 unsigned long pgrp = 0;
83 long long unsigned int user_jiffies = 0;
84 long long unsigned int kernel_jiffies = 0;
85 long long unsigned int rss_pages = 0;
123 stat->
utime = user_jiffies;
124 stat->
stime = kernel_jiffies;
jiffies_t stime
Total time spent in kernel space.
bool readStatFile(const char *filename, ProcessStat *stat)
std::size_t page_size()
Kernel page size.
static std::size_t g_page_size
unsigned long jiffies_t
A time value counted in kernel jiffies.
jiffies_t utime
Total time spent in userspace.
static jiffies_t g_kernel_hz
jiffies_t kernel_hz()
Number of kernel jiffies per second.
std::size_t mem_rss
Resident memory size in bytes.
unsigned long pgrp
Process group ID.