Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="prev" href="node441.html" /> | |
13 | <link rel="parent" href="module-resource.html" /> | |
14 | <link rel="next" href="module-nis.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>8.14.2 Resource Usage</title> | |
17 | </head> | |
18 | <body> | |
19 | <DIV CLASS="navigation"> | |
20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
22 | <tr> | |
23 | <td class='online-navigation'><a rel="prev" title="8.14.1 Resource Limits" | |
24 | href="node441.html"><img src='../icons/previous.png' | |
25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
26 | <td class='online-navigation'><a rel="parent" title="8.14 resource " | |
27 | href="module-resource.html"><img src='../icons/up.png' | |
28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
29 | <td class='online-navigation'><a rel="next" title="8.15 nis " | |
30 | href="module-nis.html"><img src='../icons/next.png' | |
31 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
32 | <td align="center" width="100%">Python Library Reference</td> | |
33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
34 | href="contents.html"><img src='../icons/contents.png' | |
35 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
37 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
38 | <td class='online-navigation'><a rel="index" title="Index" | |
39 | href="genindex.html"><img src='../icons/index.png' | |
40 | border='0' height='32' alt='Index' width='32' /></A></td> | |
41 | </tr></table> | |
42 | <div class='online-navigation'> | |
43 | <b class="navlabel">Previous:</b> | |
44 | <a class="sectref" rel="prev" href="node441.html">8.14.1 Resource Limits</A> | |
45 | <b class="navlabel">Up:</b> | |
46 | <a class="sectref" rel="parent" href="module-resource.html">8.14 resource </A> | |
47 | <b class="navlabel">Next:</b> | |
48 | <a class="sectref" rel="next" href="module-nis.html">8.15 nis </A> | |
49 | </div> | |
50 | <hr /></div> | |
51 | </DIV> | |
52 | <!--End of Navigation Panel--> | |
53 | ||
54 | <H2><A NAME="SECTION00101420000000000000000"> | |
55 | 8.14.2 Resource Usage</A> | |
56 | </H2> | |
57 | ||
58 | <P> | |
59 | These functions are used to retrieve resource usage information: | |
60 | ||
61 | <P> | |
62 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
63 | <td><nobr><b><tt id='l2h-3071' xml:id='l2h-3071' class="function">getrusage</tt></b>(</nobr></td> | |
64 | <td><var>who</var>)</td></tr></table></dt> | |
65 | <dd> | |
66 | This function returns an object that describes the resources | |
67 | consumed by either the current process or its children, as specified | |
68 | by the <var>who</var> parameter. The <var>who</var> parameter should be | |
69 | specified using one of the <tt class="constant">RUSAGE_*</tt> constants described | |
70 | below. | |
71 | ||
72 | <P> | |
73 | The fields of the return value each describe how a particular system | |
74 | resource has been used, e.g. amount of time spent running is user mode | |
75 | or number of times the process was swapped out of main memory. Some | |
76 | values are dependent on the clock tick internal, e.g. the amount of | |
77 | memory the process is using. | |
78 | ||
79 | <P> | |
80 | For backward compatibility, the return value is also accessible as | |
81 | a tuple of 16 elements. | |
82 | ||
83 | <P> | |
84 | The fields <tt class="member">ru_utime</tt> and <tt class="member">ru_stime</tt> of the return value | |
85 | are floating point values representing the amount of time spent | |
86 | executing in user mode and the amount of time spent executing in system | |
87 | mode, respectively. The remaining values are integers. Consult the | |
88 | <span class="manpage"><i>getrusage</i>(2)</span> man page for detailed information about these | |
89 | values. A brief summary is presented here: | |
90 | ||
91 | <P> | |
92 | <div class="center"><table class="realtable"> | |
93 | <thead> | |
94 | <tr> | |
95 | <th class="right" >Index</th> | |
96 | <th class="left" >Field</th> | |
97 | <th class="left" >Resource</th> | |
98 | </tr> | |
99 | </thead> | |
100 | <tbody> | |
101 | <tr><td class="right" valign="baseline"><code>0</code></td> | |
102 | <td class="left" ><tt class="member">ru_utime</tt></td> | |
103 | <td class="left" >time in user mode (float)</td></tr> | |
104 | <tr><td class="right" valign="baseline"><code>1</code></td> | |
105 | <td class="left" ><tt class="member">ru_stime</tt></td> | |
106 | <td class="left" >time in system mode (float)</td></tr> | |
107 | <tr><td class="right" valign="baseline"><code>2</code></td> | |
108 | <td class="left" ><tt class="member">ru_maxrss</tt></td> | |
109 | <td class="left" >maximum resident set size</td></tr> | |
110 | <tr><td class="right" valign="baseline"><code>3</code></td> | |
111 | <td class="left" ><tt class="member">ru_ixrss</tt></td> | |
112 | <td class="left" >shared memory size</td></tr> | |
113 | <tr><td class="right" valign="baseline"><code>4</code></td> | |
114 | <td class="left" ><tt class="member">ru_idrss</tt></td> | |
115 | <td class="left" >unshared memory size</td></tr> | |
116 | <tr><td class="right" valign="baseline"><code>5</code></td> | |
117 | <td class="left" ><tt class="member">ru_isrss</tt></td> | |
118 | <td class="left" >unshared stack size</td></tr> | |
119 | <tr><td class="right" valign="baseline"><code>6</code></td> | |
120 | <td class="left" ><tt class="member">ru_minflt</tt></td> | |
121 | <td class="left" >page faults not requiring I/O</td></tr> | |
122 | <tr><td class="right" valign="baseline"><code>7</code></td> | |
123 | <td class="left" ><tt class="member">ru_majflt</tt></td> | |
124 | <td class="left" >page faults requiring I/O</td></tr> | |
125 | <tr><td class="right" valign="baseline"><code>8</code></td> | |
126 | <td class="left" ><tt class="member">ru_nswap</tt></td> | |
127 | <td class="left" >number of swap outs</td></tr> | |
128 | <tr><td class="right" valign="baseline"><code>9</code></td> | |
129 | <td class="left" ><tt class="member">ru_inblock</tt></td> | |
130 | <td class="left" >block input operations</td></tr> | |
131 | <tr><td class="right" valign="baseline"><code>10</code></td> | |
132 | <td class="left" ><tt class="member">ru_oublock</tt></td> | |
133 | <td class="left" >block output operations</td></tr> | |
134 | <tr><td class="right" valign="baseline"><code>11</code></td> | |
135 | <td class="left" ><tt class="member">ru_msgsnd</tt></td> | |
136 | <td class="left" >messages sent</td></tr> | |
137 | <tr><td class="right" valign="baseline"><code>12</code></td> | |
138 | <td class="left" ><tt class="member">ru_msgrcv</tt></td> | |
139 | <td class="left" >messages received</td></tr> | |
140 | <tr><td class="right" valign="baseline"><code>13</code></td> | |
141 | <td class="left" ><tt class="member">ru_nsignals</tt></td> | |
142 | <td class="left" >signals received</td></tr> | |
143 | <tr><td class="right" valign="baseline"><code>14</code></td> | |
144 | <td class="left" ><tt class="member">ru_nvcsw</tt></td> | |
145 | <td class="left" >voluntary context switches</td></tr> | |
146 | <tr><td class="right" valign="baseline"><code>15</code></td> | |
147 | <td class="left" ><tt class="member">ru_nivcsw</tt></td> | |
148 | <td class="left" >involuntary context switches</td></tr></tbody> | |
149 | </table></div> | |
150 | ||
151 | <P> | |
152 | This function will raise a <tt class="exception">ValueError</tt> if an invalid | |
153 | <var>who</var> parameter is specified. It may also raise | |
154 | <tt class="exception">error</tt> exception in unusual circumstances. | |
155 | ||
156 | <P> | |
157 | ||
158 | <span class="versionnote">Changed in version 2.3: | |
159 | Added access to values as attributes of the | |
160 | returned object.</span> | |
161 | ||
162 | </dl> | |
163 | ||
164 | <P> | |
165 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
166 | <td><nobr><b><tt id='l2h-3072' xml:id='l2h-3072' class="function">getpagesize</tt></b>(</nobr></td> | |
167 | <td><var></var>)</td></tr></table></dt> | |
168 | <dd> | |
169 | Returns the number of bytes in a system page. (This need not be the | |
170 | same as the hardware page size.) This function is useful for | |
171 | determining the number of bytes of memory a process is using. The | |
172 | third element of the tuple returned by <tt class="function">getrusage()</tt> describes | |
173 | memory usage in pages; multiplying by page size produces number of | |
174 | bytes. | |
175 | </dl> | |
176 | ||
177 | <P> | |
178 | The following <tt class="constant">RUSAGE_*</tt> symbols are passed to the | |
179 | <tt class="function">getrusage()</tt> function to specify which processes information | |
180 | should be provided for. | |
181 | ||
182 | <P> | |
183 | <dl><dt><b><tt id='l2h-3073' xml:id='l2h-3073'>RUSAGE_SELF</tt></b></dt> | |
184 | <dd> | |
185 | <tt class="constant">RUSAGE_SELF</tt> should be used to | |
186 | request information pertaining only to the process itself. | |
187 | </dd></dl> | |
188 | ||
189 | <P> | |
190 | <dl><dt><b><tt id='l2h-3074' xml:id='l2h-3074'>RUSAGE_CHILDREN</tt></b></dt> | |
191 | <dd> | |
192 | Pass to <tt class="function">getrusage()</tt> to request resource information for | |
193 | child processes of the calling process. | |
194 | </dd></dl> | |
195 | ||
196 | <P> | |
197 | <dl><dt><b><tt id='l2h-3075' xml:id='l2h-3075'>RUSAGE_BOTH</tt></b></dt> | |
198 | <dd> | |
199 | Pass to <tt class="function">getrusage()</tt> to request resources consumed by both | |
200 | the current process and child processes. May not be available on all | |
201 | systems. | |
202 | </dd></dl> | |
203 | ||
204 | <DIV CLASS="navigation"> | |
205 | <div class='online-navigation'> | |
206 | <p></p><hr /> | |
207 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
208 | <tr> | |
209 | <td class='online-navigation'><a rel="prev" title="8.14.1 Resource Limits" | |
210 | href="node441.html"><img src='../icons/previous.png' | |
211 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
212 | <td class='online-navigation'><a rel="parent" title="8.14 resource " | |
213 | href="module-resource.html"><img src='../icons/up.png' | |
214 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
215 | <td class='online-navigation'><a rel="next" title="8.15 nis " | |
216 | href="module-nis.html"><img src='../icons/next.png' | |
217 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
218 | <td align="center" width="100%">Python Library Reference</td> | |
219 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
220 | href="contents.html"><img src='../icons/contents.png' | |
221 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
222 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
223 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
224 | <td class='online-navigation'><a rel="index" title="Index" | |
225 | href="genindex.html"><img src='../icons/index.png' | |
226 | border='0' height='32' alt='Index' width='32' /></A></td> | |
227 | </tr></table> | |
228 | <div class='online-navigation'> | |
229 | <b class="navlabel">Previous:</b> | |
230 | <a class="sectref" rel="prev" href="node441.html">8.14.1 Resource Limits</A> | |
231 | <b class="navlabel">Up:</b> | |
232 | <a class="sectref" rel="parent" href="module-resource.html">8.14 resource </A> | |
233 | <b class="navlabel">Next:</b> | |
234 | <a class="sectref" rel="next" href="module-nis.html">8.15 nis </A> | |
235 | </div> | |
236 | </div> | |
237 | <hr /> | |
238 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
239 | </DIV> | |
240 | <!--End of Navigation Panel--> | |
241 | <ADDRESS> | |
242 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
243 | </ADDRESS> | |
244 | </BODY> | |
245 | </HTML> |