1sg_get_cpu_stats(3)        Library Functions Manual        sg_get_cpu_stats(3)
2
3
4

NAME

6       sg_get_cpu_stats,  sg_get_cpu_stats_diff, sg_get_cpu_percents - get cpu
7       usage
8

SYNOPSIS

10       #include <statgrab.h>
11
12
13       sg_cpu_percents *sg_get_cpu_percents(void);
14
15       sg_cpu_stats *sg_get_cpu_stats(void);
16
17       sg_cpu_stats *sg_get_cpu_stats_diff(void);
18

DESCRIPTION

20       sg_get_cpu_stats()  and  sg_get_cpu_stats_diff()  both  return   static
21       pointers  of  type  sg_cpu_stats.  sg_get_cpu_stats() returns the total
22       amount of "ticks" the operating system has spent in each of the differ‐
23       ent  states.  sg_get_cpu_stats_diff() returns the difference in "ticks"
24       for each of the  states  since  last  time  sg_get_cpu_stats_diff()  or
25       sg_get_cpu_stats()  was  called.  If  it has never been called, it will
26       return the result of sg_get_cpu_stats().
27
28       The value stored (the "ticks") will vary between operating systems. For
29       example Solaris has a total of 100 per second, while Linux has substan‐
30       tially more. Also, different operating systems store different informa‐
31       tion - you won't find nice cpu on Solaris for example.
32
33       Because  of  this,  you  will  ideally  always  want to work on a scale
34       against the total, or in percentages.
35
36       sg_get_cpu_percents() returns a pointer to  a  static  sg_cpu_percents.
37       The  function calls sg_get_cpu_stats_diff() and changes the values into
38       percentages.  If  it  has  never  been  called  before  (and  nor   has
39       sg_get_cpu_stats()  or  sg_get_cpu_stats_diff()), the returned percent‐
40       ages will be the systems total ever since its uptime. (Unless the coun‐
41       ters have cycled)
42

RETURN VALUES

44       There are two structures returned by the CPU statistics functions.
45
46       typedef struct{
47               long long user;
48               long long kernel;
49               long long idle;
50               long long iowait;
51               long long swap;
52               long long nice;
53               long long total;
54               time_t systime;
55       }sg_cpu_stats;
56
57
58       typedef struct{
59               float user;
60               float kernel;
61               float idle;
62               float iowait;
63               float swap;
64               float nice;
65               time_t time_taken;
66       }sg_cpu_percents;
67
68
69       user  kernel  idle  iowait  swap  nice
70              The different CPU states.
71
72       systime  time_taken
73              The  time  taken in seconds since the last call of the function,
74              or the system time.
75

SEE ALSO

77       statgrab(3)
78

WEBSITE

80       http://www.i-scream.org/libstatgrab/
81
82
83
84i-scream                 $Date: 2005/04/25 11:25:45 $      sg_get_cpu_stats(3)
Impressum