CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
sysinfo.h
Go to the documentation of this file.
1#pragma once
2
5
9
10#include <cx/cx.h>
11#include <cx/sys/process.h>
12
13CX_C_BEGIN
14
116
119 SYSMEM_Phys = 0x0001,
120 SYSMEM_Commit = 0x0002,
121 SYSMEM_Swap = 0x0004,
123};
124
126typedef struct SysMemInfo {
128 flags_t valid;
129
130 uint64 physTotal;
131 uint64 physAvail;
132
138
139 uint64 commitAvail;
140
144 uint64 swapTotal;
145
146 uint64 swapAvail;
147 uint64 pageSize;
149
152 SYSCPU_User = 0x0001,
153 SYSCPU_System = 0x0002,
154 SYSCPU_Idle = 0x0004,
155 SYSCPU_IOWait = 0x0008,
156 SYSCPU_IRQ = 0x0010,
157 SYSCPU_Steal = 0x0020,
158};
159
164typedef struct SysCPUTimes {
168 flags_t valid;
169
170 int64 sampled;
171 int64 busy;
172 int64 total;
173
174 int64 user;
175 int64 system;
176 int64 idle;
177 int64 iowait;
178 int64 irq;
179 int64 steal;
180
181 int32 cpus;
183
186 SYSUP_Uptime = 0x0001,
187 SYSUP_BootTime = 0x0002,
188};
189
191typedef struct SysUptime {
192 flags_t valid;
193 int64 uptime;
194 int64 boottime;
196
203
209typedef struct SysLoadAvg {
210 flags_t valid;
211 float64 load1;
212 float64 load5;
213 float64 load15;
215
225
227typedef struct ProcMemInfo {
228 flags_t valid;
229
230 uint64 resident;
231
237
242
244
249
250 uint64 swapped;
252
259
261typedef struct ProcCPUTimes {
265 flags_t valid;
266
267 int64 sampled;
268 int64 total;
269 int64 user;
270 int64 system;
271 int64 started;
273
276 PROCIO_Bytes = 0x0001,
277 PROCIO_Ops = 0x0002,
278 PROCIO_Other = 0x0004,
279};
280
285typedef struct ProcIOInfo {
286 flags_t valid;
287
288 uint64 readBytes;
289 uint64 writeBytes;
290 uint64 readOps;
291 uint64 writeOps;
292 uint64 otherBytes;
293 uint64 otherOps;
295
308bool sysMemInfo(_Out_ SysMemInfo* out);
309
324bool sysCPUTimes(_Out_ SysCPUTimes* out);
325
338bool sysUptime(_Out_ SysUptime* out);
339
353bool sysLoadAvg(_Out_ SysLoadAvg* out);
354
366float64 sysCPUUsage(_In_ const SysCPUTimes* first, _In_ const SysCPUTimes* second);
367
373
385#define sysCPUSamplerInit(s) memset((s), 0, sizeof(SysCPUSampler))
386
401bool sysCPUSample(_Inout_ SysCPUSampler* s, _Out_ float64* pct);
402
416bool procMemInfo(_Out_ ProcMemInfo* out, _In_ Process* proc);
417
430
446bool procCPUTimes(_Out_ ProcCPUTimes* out, _In_ Process* proc);
447
460
475bool procIOInfo(_Out_ ProcIOInfo* out, _In_ Process* proc);
476
489bool procIOInfoByID(_Out_ ProcIOInfo* out, ProcessID pid);
490
502float64 procCPUUsage(_In_ const ProcCPUTimes* first, _In_ const ProcCPUTimes* second);
503
511
523#define procCPUSamplerInit(s) memset((s), 0, sizeof(ProcCPUSampler))
524
540bool procCPUSample(_Inout_ ProcCPUSampler* s, _In_ Process* proc, _Out_ float64* pct);
541
542CX_C_END
543
int64 ProcessID
Operating system process id.
Definition process.h:128
bool sysCPUSample(SysCPUSampler *s, float64 *pct)
float64 sysCPUUsage(const SysCPUTimes *first, const SysCPUTimes *second)
bool procIOInfoByID(ProcIOInfo *out, ProcessID pid)
bool procCPUTimesByID(ProcCPUTimes *out, ProcessID pid)
bool procCPUSample(ProcCPUSampler *s, Process *proc, float64 *pct)
ProcCPUTimesValid
Which fields of a ProcCPUTimes the operating system reported.
Definition sysinfo.h:254
SysMemInfoValid
Which fields of a SysMemInfo the operating system reported.
Definition sysinfo.h:118
SysUptimeValid
Which fields of a SysUptime the operating system reported.
Definition sysinfo.h:185
SysCPUTimesValid
Which breakdown fields of a SysCPUTimes the operating system reported.
Definition sysinfo.h:151
float64 procCPUUsage(const ProcCPUTimes *first, const ProcCPUTimes *second)
bool sysCPUTimes(SysCPUTimes *out)
bool sysLoadAvg(SysLoadAvg *out)
bool procMemInfo(ProcMemInfo *out, Process *proc)
bool procMemInfoByID(ProcMemInfo *out, ProcessID pid)
bool procIOInfo(ProcIOInfo *out, Process *proc)
bool sysUptime(SysUptime *out)
SysLoadAvgValid
Which fields of a SysLoadAvg the operating system reported.
Definition sysinfo.h:198
bool procCPUTimes(ProcCPUTimes *out, Process *proc)
ProcMemInfoValid
Which fields of a ProcMemInfo the operating system reported.
Definition sysinfo.h:217
ProcIOInfoValid
Which fields of a ProcIOInfo the operating system reported.
Definition sysinfo.h:275
bool sysMemInfo(SysMemInfo *out)
@ PROCCPU_User
user
Definition sysinfo.h:255
@ PROCCPU_System
system
Definition sysinfo.h:256
@ PROCCPU_Started
started
Definition sysinfo.h:257
@ SYSMEM_PageSize
pageSize
Definition sysinfo.h:122
@ SYSMEM_Phys
physTotal and physAvail
Definition sysinfo.h:119
@ SYSMEM_Commit
commitTotal and commitAvail
Definition sysinfo.h:120
@ SYSMEM_Swap
swapTotal and swapAvail
Definition sysinfo.h:121
@ SYSUP_Uptime
uptime
Definition sysinfo.h:186
@ SYSUP_BootTime
boottime
Definition sysinfo.h:187
@ SYSCPU_Steal
steal
Definition sysinfo.h:157
@ SYSCPU_User
user
Definition sysinfo.h:152
@ SYSCPU_IRQ
irq
Definition sysinfo.h:156
@ SYSCPU_Idle
idle
Definition sysinfo.h:154
@ SYSCPU_System
system
Definition sysinfo.h:153
@ SYSCPU_IOWait
iowait
Definition sysinfo.h:155
@ SYSLOAD_Load15
load15
Definition sysinfo.h:201
@ SYSLOAD_Load5
load5
Definition sysinfo.h:200
@ SYSLOAD_Load1
load1
Definition sysinfo.h:199
@ PROCMEM_Virtual
virtualSize
Definition sysinfo.h:220
@ PROCMEM_PeakVirtual
peakVirtualSize
Definition sysinfo.h:221
@ PROCMEM_Swapped
swapped
Definition sysinfo.h:223
@ PROCMEM_Resident
resident
Definition sysinfo.h:218
@ PROCMEM_PeakResident
peakResident
Definition sysinfo.h:219
@ PROCMEM_Private
privateSize
Definition sysinfo.h:222
@ PROCIO_Ops
readOps and writeOps
Definition sysinfo.h:277
@ PROCIO_Other
otherBytes and otherOps
Definition sysinfo.h:278
@ PROCIO_Bytes
readBytes and writeBytes
Definition sysinfo.h:276
Launching, inspecting and controlling operating system processes.
ProcCPUTimes last
The previous reading.
Definition sysinfo.h:508
bool primed
Whether a previous reading has been taken yet.
Definition sysinfo.h:509
Processor time one process has used since it started.
Definition sysinfo.h:261
flags_t valid
ProcCPUTimesValid flags naming the fields that were reported.
Definition sysinfo.h:265
int64 sampled
When the reading was taken, from clockTimer()
Definition sysinfo.h:267
int64 user
Microseconds spent running the program's own code.
Definition sysinfo.h:269
int64 started
When the process started, as a cx time value.
Definition sysinfo.h:271
int64 system
Microseconds spent inside the operating system on its behalf.
Definition sysinfo.h:270
int64 total
Microseconds of processor time used altogether: user plus system.
Definition sysinfo.h:268
uint64 otherOps
How many such operations were made. Windows only.
Definition sysinfo.h:293
flags_t valid
ProcIOInfoValid flags naming the fields that were reported.
Definition sysinfo.h:286
uint64 readBytes
Bytes read. Not reported on FreeBSD.
Definition sysinfo.h:288
uint64 otherBytes
Bytes transferred by anything that is neither. Windows only.
Definition sysinfo.h:292
uint64 writeOps
How many separate writes were made.
Definition sysinfo.h:291
uint64 writeBytes
Bytes written. Not reported on FreeBSD.
Definition sysinfo.h:289
uint64 readOps
How many separate reads were made.
Definition sysinfo.h:290
How much memory one process is using.
Definition sysinfo.h:227
uint64 privateSize
Bytes of memory the process has asked for and nobody else can share.
Definition sysinfo.h:248
uint64 virtualSize
Bytes of address space the process has reserved.
Definition sysinfo.h:241
uint64 peakVirtualSize
The largest that has ever been. Linux only.
Definition sysinfo.h:243
uint64 peakResident
The largest that has ever been.
Definition sysinfo.h:236
uint64 swapped
Bytes of the process paged out to swap. Linux only.
Definition sysinfo.h:250
uint64 resident
Bytes of the process currently held in memory.
Definition sysinfo.h:230
flags_t valid
ProcMemInfoValid flags naming the fields that were reported.
Definition sysinfo.h:228
Remembers the previous reading so repeated polling needs only one call each time.
Definition sysinfo.h:369
bool primed
Whether a previous reading has been taken yet.
Definition sysinfo.h:371
SysCPUTimes last
The previous reading.
Definition sysinfo.h:370
int64 busy
Time accounted for as anything other than idle.
Definition sysinfo.h:171
int64 irq
Time spent servicing hardware. Not reported on Windows.
Definition sysinfo.h:178
int64 user
Time spent running program code, including at low priority.
Definition sysinfo.h:174
int64 sampled
When the reading was taken, from clockTimer()
Definition sysinfo.h:170
int64 system
Time spent inside the operating system.
Definition sysinfo.h:175
int64 total
Time accounted for altogether: busy plus idle.
Definition sysinfo.h:172
int32 cpus
How many logical processors these figures cover.
Definition sysinfo.h:181
int64 steal
Time a hypervisor gave to someone else. Linux only.
Definition sysinfo.h:179
int64 idle
Time spent with nothing to do.
Definition sysinfo.h:176
flags_t valid
SysCPUTimesValid flags naming the breakdown fields that were reported.
Definition sysinfo.h:168
int64 iowait
Time spent waiting for a disk. Linux only.
Definition sysinfo.h:177
float64 load1
Average over the last minute.
Definition sysinfo.h:211
flags_t valid
SysLoadAvgValid flags naming the fields that were reported.
Definition sysinfo.h:210
float64 load5
Average over the last five minutes.
Definition sysinfo.h:212
float64 load15
Average over the last fifteen minutes.
Definition sysinfo.h:213
How much memory the machine has and how much of it is spoken for.
Definition sysinfo.h:126
flags_t valid
SysMemInfoValid flags naming the fields that were reported.
Definition sysinfo.h:128
uint64 commitAvail
Bytes of that promise not yet handed out.
Definition sysinfo.h:139
uint64 commitTotal
Bytes of memory the system is willing to promise to programs in total.
Definition sysinfo.h:137
uint64 pageSize
Size of a memory page in bytes.
Definition sysinfo.h:147
uint64 swapAvail
Bytes of swap space still free.
Definition sysinfo.h:146
uint64 physTotal
Bytes of memory installed in the machine.
Definition sysinfo.h:130
uint64 physAvail
Bytes that can be used without paging something out first.
Definition sysinfo.h:131
uint64 swapTotal
Bytes of swap space configured.
Definition sysinfo.h:144
How long the machine has been running.
Definition sysinfo.h:191
int64 uptime
Microseconds since the machine booted.
Definition sysinfo.h:193
int64 boottime
When the machine booted, as a cx time value.
Definition sysinfo.h:194
flags_t valid
SysUptimeValid flags naming the fields that were reported.
Definition sysinfo.h:192