ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/docs/sg_get_cpu_stats.xml
Revision: 1.7
Committed: Mon Apr 25 11:25:47 2005 UTC (19 years ago) by tdb
Content type: text/xml
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +2 -2 lines
State: FILE REMOVED
Log Message:
Move by repocopy the libstatgrab docs in to a subdirectory. This is so
I can create separate directories for statgrab/saidar docs.

File Contents

# Content
1 <?xml version="1.0"?>
2
3 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
4 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
5
6 <refentry id="sg_get_cpu_stats">
7
8 <refentryinfo>
9 <date>$Date: 2004/05/02 17:39:19 $</date>
10 <releaseinfo>$Id: sg_get_cpu_stats.xml,v 1.6 2004/05/02 17:39:19 tdb Exp $</releaseinfo>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sg_get_cpu_stats</refentrytitle>
15 <manvolnum>3</manvolnum>
16 <refmiscinfo>i-scream</refmiscinfo>
17 </refmeta>
18
19 <refnamediv>
20 <refname>sg_get_cpu_stats</refname>
21 <refname>sg_get_cpu_stats_diff</refname>
22 <refname>sg_get_cpu_percents</refname>
23 <refpurpose>get cpu usage</refpurpose>
24 </refnamediv>
25
26 <refsynopsisdiv>
27 <funcsynopsis>
28 <funcsynopsisinfo>#include &lt;statgrab.h&gt;</funcsynopsisinfo>
29 <funcprototype>
30 <funcdef>sg_cpu_percents *<function>sg_get_cpu_percents</function></funcdef>
31 <void/>
32 </funcprototype>
33 <funcprototype>
34 <funcdef>sg_cpu_stats *<function>sg_get_cpu_stats</function></funcdef>
35 <void/>
36 </funcprototype>
37 <funcprototype>
38 <funcdef>sg_cpu_stats *<function>sg_get_cpu_stats_diff</function></funcdef>
39 <void/>
40 </funcprototype>
41 </funcsynopsis>
42 </refsynopsisdiv>
43
44 <refsect1>
45 <title>Description</title>
46 <para>
47 <function>sg_get_cpu_stats()</function> and
48 <function>sg_get_cpu_stats_diff()</function> both return static pointers
49 of type <structname>sg_cpu_stats</structname>.
50 <function>sg_get_cpu_stats()</function> returns the total amount of
51 "ticks" the operating system has spent in each of the different
52 states. <function>sg_get_cpu_stats_diff()</function> returns the
53 difference in "ticks" for each of the states since last time
54 <function>sg_get_cpu_stats_diff()</function> or
55 <function>sg_get_cpu_stats()</function> was called. If it has never
56 been called, it will return the result of
57 <function>sg_get_cpu_stats()</function>.
58 </para>
59 <para>
60 The value stored (the "ticks") will vary between operating
61 systems. For example Solaris has a total of 100 per second,
62 while Linux has substantially more. Also, different operating
63 systems store different information - you won't find nice cpu on
64 Solaris for example.
65 </para>
66 <para>
67 Because of this, you will ideally always want to work on a scale
68 against the total, or in percentages.
69 </para>
70 <para>
71 <function>sg_get_cpu_percents()</function> returns a pointer to a
72 static <structname>sg_cpu_percents</structname>. The function
73 calls <function>sg_get_cpu_stats_diff()</function> and changes the values
74 into percentages. If it has never been called before (and nor has
75 <function>sg_get_cpu_stats()</function> or
76 <function>sg_get_cpu_stats_diff()</function>), the returned percentages
77 will be the systems total ever since its uptime. (Unless the
78 counters have cycled)
79 </para>
80 </refsect1>
81
82 <refsect1>
83 <title>Return Values</title>
84
85 <para>
86 There are two structures returned by the CPU statistics
87 functions.
88 </para>
89
90 <programlisting>
91 typedef struct{
92 long long user;
93 long long kernel;
94 long long idle;
95 long long iowait;
96 long long swap;
97 long long nice;
98 long long total;
99 time_t systime;
100 }sg_cpu_stats;
101 </programlisting>
102
103 <programlisting>
104 typedef struct{
105 float user;
106 float kernel;
107 float idle;
108 float iowait;
109 float swap;
110 float nice;
111 time_t time_taken;
112 }sg_cpu_percents;
113 </programlisting>
114
115 <variablelist>
116 <varlistentry>
117 <term>
118 <structfield>user</structfield>
119 <structfield>kernel</structfield>
120 <structfield>idle</structfield>
121 <structfield>iowait</structfield>
122 <structfield>swap</structfield>
123 <structfield>nice</structfield>
124 </term>
125 <listitem>
126 <para>
127 The different CPU states.
128 </para>
129 </listitem>
130 </varlistentry>
131 <varlistentry>
132 <term>
133 <structfield>systime</structfield>
134 <structfield>time_taken</structfield>
135 </term>
136 <listitem>
137 <para>
138 The time taken in seconds since the last call of the
139 function, or the system time.
140 </para>
141 </listitem>
142 </varlistentry>
143 </variablelist>
144 </refsect1>
145
146 <refsect1>
147 <title>See Also</title>
148
149 <simplelist type="inline">
150 <member>
151 <citerefentry>
152 <refentrytitle>statgrab</refentrytitle>
153 <manvolnum>3</manvolnum>
154 </citerefentry>
155 </member>
156 </simplelist>
157 </refsect1>
158
159 <refsect1>
160 <title>Website</title>
161
162 <simplelist type="vert">
163 <member>
164 <ulink url="http://www.i-scream.org/libstatgrab/">
165 http://www.i-scream.org/libstatgrab/
166 </ulink>
167 </member>
168 </simplelist>
169 </refsect1>
170
171 </refentry>