-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproc_utils.h
More file actions
66 lines (53 loc) · 2.21 KB
/
proc_utils.h
File metadata and controls
66 lines (53 loc) · 2.21 KB
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
/**
* Cross platform process information, Copyright (c) 2024, Jorma Rebane
* Distributed under MIT Software License
*/
#pragma once
#include "config.h"
namespace rpp
{
/**
* Process memory usage information - for profiling stats.
*/
struct proc_mem_info
{
/// @brief Total virtual memory reserved for this process.
// Includes all memory mapped files, swap, etc.
uint64 virtual_size = 0;
/// @brief Resident set size (RSS) is the actual physical memory
// currently mapped to the process.
uint64 physical_mem = 0;
double virtual_size_kb() const noexcept { return virtual_size / 1'000.0; }
double physical_mem_kb() const noexcept { return physical_mem / 1'000.0; }
double virtual_size_mb() const noexcept { return virtual_size / 1'000'000.0; }
double physical_mem_mb() const noexcept { return physical_mem / 1'000'000.0; }
};
/**
* @return Current physical memory usage in bytes.
*/
proc_mem_info proc_current_mem_used() noexcept;
/**
* CPU usage information - for profiling stats.
*/
struct cpu_usage_info
{
/// @brief Total CPU time used in microseconds.
/// User + Kernel.
int64 cpu_time_us = 0;
/// @brief Total CPU time used in user mode in microseconds.
int64 user_time_us = 0;
/// @brief Total CPU time used in kernel mode in microseconds.
int64 kernel_time_us = 0;
double cpu_time_ms() const noexcept { return cpu_time_us / 1'000.0; }
double user_time_ms() const noexcept { return user_time_us / 1'000.0; }
double kernel_time_ms() const noexcept { return kernel_time_us / 1'000.0; }
double cpu_time_sec() const noexcept { return cpu_time_us / 1'000'000.0; }
double user_time_sec() const noexcept { return user_time_us / 1'000'000.0; }
double kernel_time_sec() const noexcept { return kernel_time_us / 1'000'000.0; }
};
/**
* @return Total CPU time used by this PROCESS in microseconds.
* @brief To calculate CPU usage %, call this function twice over a known time interval.
*/
cpu_usage_info proc_total_cpu_usage() noexcept;
} // namespace rpp