1sg_get_cpu_stats(3)                                        sg_get_cpu_stats(3)
2
3
4

NAME

6       sg_get_cpu_stats,       sg_get_cpu_stats_r,      sg_get_cpu_stats_diff,
7       sg_get_cpu_stats_diff_between,   sg_get_cpu_percents,   sg_get_cpu_per‐
8       cents_of, sg_get_cpu_percents_r, sg_free_cpu_stats - get cpu usage
9

SYNOPSIS

11       #include <statgrab.h>
12
13
14       sg_cpu_percents *sg_get_cpu_percents (size_t *entries);
15
16       sg_cpu_percents *sg_get_cpu_percents_of (sg_cpu_percent_source cps,
17                       size_t *entries);
18
19       sg_cpu_percents *sg_get_cpu_percents_r (const sg_cpu_stats *whereof,
20                                              size_t *entries);
21
22       void sg_free_cpu_percents (sg_cpu_percents *data);
23
24       sg_cpu_stats *sg_get_cpu_stats (size_t *entries);
25
26       sg_cpu_stats *sg_get_cpu_stats_diff (size_t *entries);
27
28       sg_cpu_stats *sg_get_cpu_stats_r (size_t *entries);
29
30       sg_cpu_stats *sg_get_cpu_stats_diff_between (const sg_cpu_stats
31                       *cpu_now, const sg_cpu_stats *cpu_last, size_t
32                       *entries);
33
34       sg_error sg_free_cpu_stats (sg_cpu_stats *data);
35

DESCRIPTION

37       These  are  the  categories  of data delivered by the cpu stats module:
38       sg_get_cpu_stats() and sg_get_cpu_stats_r() deliver native cpu counters
39       since   the  machine  has  been  started,  sg_get_cpu_stats_diff()  and
40       sg_get_cpu_stats_diff_between() deliver native cpu counters between two
41       sg_get_cpu_stats()     calls     and    sg_get_cpu_percents_of()    and
42       sg_get_cpu_percents_r() deliver correlated relative cpu counters (where
43       total is 100%).
44
45       API Shortcut
46
47       ┌──────────────────────────┬───────────────────┬─────────────────────┐
48       │function                  │ returns           │ data owner          │
49       ├──────────────────────────┼───────────────────┼─────────────────────┤
50       │sg_get_cpu_stats          │ sg_cpu_stats *    │ libstatgrab (thread │
51       │                          │                   │ local)              │
52       ├──────────────────────────┼───────────────────┼─────────────────────┤
53       │sg_get_cpu_stats_r        │ sg_cpu_stats *    │ caller              │
54       ├──────────────────────────┼───────────────────┼─────────────────────┤
55       │sg_get_cpu_stats_diff     │ sg_cpu_stats *    │ libstatgrab (thread │
56       │                          │                   │ local)              │
57       ├──────────────────────────┼───────────────────┼─────────────────────┤
58       │sg_get_cpu_stats_diff_be‐ │ sg_cpu_stats *    │ caller              │
59       │tween                     │                   │                     │
60       ├──────────────────────────┼───────────────────┼─────────────────────┤
61       │sg_get_cpu_percents_of    │ sg_cpu_percents * │ libstatgrab (thread │
62       │                          │                   │ local)              │
63       ├──────────────────────────┼───────────────────┼─────────────────────┤
64       │sg_get_cpu_percents_r     │ sg_cpu_percents * │ caller              │
65       └──────────────────────────┴───────────────────┴─────────────────────┘
66       The sg_cpu_stats buffer  received  from  sg_get_cpu_stats_r()  and  the
67       sg_get_cpu_stats_diff_between()  as  well as the sg_cpu_percents buffer
68       received   from   sg_get_cpu_percents_r()   must   be    freed    using
69       sg_free_cpu_stats()  or  the sg_free_cpu_percents(), respectively, when
70       not needed any more. The caller is responsible for doing it.
71
72       The value stored (the "ticks") will vary between operating systems. For
73       example Solaris has a total of 100 per second, while Linux has substan‐
74       tially more. Also, different operating systems store different informa‐
75       tion - you won't find nice cpu on Solaris for example.
76
77       Modern  systems  shall provide information about the clock tick resolu‐
78       tion by invoking sysconf(_SC_CLK_TCK).
79

RETURN VALUES

81       There are two structures returned by the CPU statistics functions.
82
83       typedef struct {
84               unsigned long long user;
85               unsigned long long kernel;
86               unsigned long long idle;
87               unsigned long long iowait;
88               unsigned long long swap;
89               unsigned long long nice;
90               unsigned long long total;
91
92               unsigned long long context_switches;
93               unsigned long long voluntary_context_switches;
94               unsigned long long involuntary_context_switches;
95               unsigned long long syscalls;
96               unsigned long long interrupts;
97               unsigned long long soft_interrupts;
98
99               time_t systime;
100       } sg_cpu_stats;
101
102
103       typedef struct {
104               double user;
105               double kernel;
106               double idle;
107               double iowait;
108               double swap;
109               double nice;
110               time_t time_taken;
111       } sg_cpu_percents;
112
113
114       user kernel idle iowait swap nice total
115              The different CPU states.
116
117       context_switches voluntary_context_switches involuntary_context_switch‐
118       es syscalls interrupts soft_interrupts
119              The different program actions on CPU.
120
121       systime time_taken
122              The  time  taken in seconds since the last call of the function,
123              or the system time.
124

SEE ALSO

126       statgrab(3)
127

WEBSITE

129http://www.i-scream.org/libstatgrab/
130
131
132
133i-scream                          2013-06-17               sg_get_cpu_stats(3)
Impressum