<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <link rel="STYLESHEET" href="lib.css" type='text/css' /> <link rel="SHORTCUT ICON" href="../icons/pyfav.gif" /> <link rel='start' href='../index.html' title='Python Documentation Index' /> <link rel="first" href="lib.html" title='Python Library Reference' /> <link rel='contents' href='contents.html' title="Contents" /> <link rel='index' href='genindex.html' title='Index' /> <link rel='last' href='about.html' title='About this document...' /> <link rel='help' href='about.html' title='About this document...' /> <LINK rel="prev" href="node373.html"> <LINK rel="parent" href="module-resource.html"> <LINK rel="next" href="module-nis.html"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta name='aesop' content='information' /> <META name="description" content="Resource Usage"> <META name="keywords" content="lib"> <META name="resource-type" content="document"> <META name="distribution" content="global"> <title>8.15.2 Resource Usage</title> </head> <body> <DIV CLASS="navigation"> <div id='top-navigation-panel'> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="8.15.1 Resource Limits" href="node373.html"><img src='../icons/previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="8.15 resource " href="module-resource.html"><img src='../icons/up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="8.16 nis " href="module-nis.html"><img src='../icons/next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Python Library Reference</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" href="contents.html"><img src='../icons/contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' border='0' height='32' alt='Module Index' width='32' /></a></td> <td class='online-navigation'><a rel="index" title="Index" href="genindex.html"><img src='../icons/index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="node373.html">8.15.1 Resource Limits</A> <b class="navlabel">Up:</b> <a class="sectref" rel="parent" href="module-resource.html">8.15 resource </A> <b class="navlabel">Next:</b> <a class="sectref" rel="next" href="module-nis.html">8.16 nis </A> </div> <hr /></div> </DIV> <!--End of Navigation Panel--> <H2><A NAME="SECTION00101520000000000000000"> 8.15.2 Resource Usage</A> </H2> <P> These functions are used to retrieve resource usage information: <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-2872' class="function">getrusage</tt></b>(</nobr></td> <td><var>who</var>)</td></tr></table></dt> <dd> This function returns an object that describes the resources consumed by either the current process or its children, as specified by the <var>who</var> parameter. The <var>who</var> parameter should be specified using one of the <tt class="constant">RUSAGE_*</tt> constants described below. <P> The fields of the return value each describe how a particular system resource has been used, e.g. amount of time spent running is user mode or number of times the process was swapped out of main memory. Some values are dependent on the clock tick internal, e.g. the amount of memory the process is using. <P> For backward compatibility, the return value is also accessible as a tuple of 16 elements. <P> The fields <tt class="member">ru_utime</tt> and <tt class="member">ru_stime</tt> of the return value are floating point values representing the amount of time spent executing in user mode and the amount of time spent executing in system mode, respectively. The remaining values are integers. Consult the <span class="manpage"><i>getrusage</i>(2)</span> man page for detailed information about these values. A brief summary is presented here: <P> <table border align="center" style="border-collapse: collapse"> <thead> <tr class="tableheader"> <th align="right"><b>Index</b> </th> <th align="left"><b>Field</b> </th> <th align="left"><b>Resource</b> </th> </tr> </thead> <tbody valign="baseline"> <tr><td align="right" valign="baseline"><code>0</code> </td> <td align="left"><tt class="member">ru_utime</tt></td> <td align="left">time in user mode (float)</td> <tr><td align="right" valign="baseline"><code>1</code> </td> <td align="left"><tt class="member">ru_stime</tt></td> <td align="left">time in system mode (float)</td> <tr><td align="right" valign="baseline"><code>2</code> </td> <td align="left"><tt class="member">ru_maxrss</tt></td> <td align="left">maximum resident set size</td> <tr><td align="right" valign="baseline"><code>3</code> </td> <td align="left"><tt class="member">ru_ixrss</tt></td> <td align="left">shared memory size</td> <tr><td align="right" valign="baseline"><code>4</code> </td> <td align="left"><tt class="member">ru_idrss</tt></td> <td align="left">unshared memory size</td> <tr><td align="right" valign="baseline"><code>5</code> </td> <td align="left"><tt class="member">ru_isrss</tt></td> <td align="left">unshared stack size</td> <tr><td align="right" valign="baseline"><code>6</code> </td> <td align="left"><tt class="member">ru_minflt</tt></td> <td align="left">page faults not requiring I/O</td> <tr><td align="right" valign="baseline"><code>7</code> </td> <td align="left"><tt class="member">ru_majflt</tt></td> <td align="left">page faults requiring I/O</td> <tr><td align="right" valign="baseline"><code>8</code> </td> <td align="left"><tt class="member">ru_nswap</tt></td> <td align="left">number of swap outs</td> <tr><td align="right" valign="baseline"><code>9</code> </td> <td align="left"><tt class="member">ru_inblock</tt></td> <td align="left">block input operations</td> <tr><td align="right" valign="baseline"><code>10</code> </td> <td align="left"><tt class="member">ru_oublock</tt></td> <td align="left">block output operations</td> <tr><td align="right" valign="baseline"><code>11</code> </td> <td align="left"><tt class="member">ru_msgsnd</tt></td> <td align="left">messages sent</td> <tr><td align="right" valign="baseline"><code>12</code> </td> <td align="left"><tt class="member">ru_msgrcv</tt></td> <td align="left">messages received</td> <tr><td align="right" valign="baseline"><code>13</code> </td> <td align="left"><tt class="member">ru_nsignals</tt></td> <td align="left">signals received</td> <tr><td align="right" valign="baseline"><code>14</code> </td> <td align="left"><tt class="member">ru_nvcsw</tt></td> <td align="left">voluntary context switches</td> <tr><td align="right" valign="baseline"><code>15</code> </td> <td align="left"><tt class="member">ru_nivcsw</tt></td> <td align="left">involuntary context switches</td></tbody> </table> <P> This function will raise a <tt class="exception">ValueError</tt> if an invalid <var>who</var> parameter is specified. It may also raise <tt class="exception">error</tt> exception in unusual circumstances. <P> <span class="versionnote">Changed in version 2.3: Added access to values as attributes of the returned object.</span> </dl> <P> <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> <td><nobr><b><tt id='l2h-2873' class="function">getpagesize</tt></b>(</nobr></td> <td>)</td></tr></table></dt> <dd> Returns the number of bytes in a system page. (This need not be the same as the hardware page size.) This function is useful for determining the number of bytes of memory a process is using. The third element of the tuple returned by <tt class="function">getrusage()</tt> describes memory usage in pages; multiplying by page size produces number of bytes. </dl> <P> The following <tt class="constant">RUSAGE_*</tt> symbols are passed to the <tt class="function">getrusage()</tt> function to specify which processes information should be provided for. <P> <dl><dt><b><tt id='l2h-2874'>RUSAGE_SELF</tt></b></dt> <dd> <tt class="constant">RUSAGE_SELF</tt> should be used to request information pertaining only to the process itself. </dd></dl> <P> <dl><dt><b><tt id='l2h-2875'>RUSAGE_CHILDREN</tt></b></dt> <dd> Pass to <tt class="function">getrusage()</tt> to request resource information for child processes of the calling process. </dd></dl> <P> <dl><dt><b><tt id='l2h-2876'>RUSAGE_BOTH</tt></b></dt> <dd> Pass to <tt class="function">getrusage()</tt> to request resources consumed by both the current process and child processes. May not be available on all systems. </dd></dl> <DIV CLASS="navigation"> <div class='online-navigation'><hr /> <table align="center" width="100%" cellpadding="0" cellspacing="2"> <tr> <td class='online-navigation'><a rel="prev" title="8.15.1 Resource Limits" rel="prev" title="8.15.1 Resource Limits" href="node373.html"><img src='../icons/previous.png' border='0' height='32' alt='Previous Page' width='32' /></A></td> <td class='online-navigation'><a rel="parent" title="8.15 resource " rel="parent" title="8.15 resource " href="module-resource.html"><img src='../icons/up.png' border='0' height='32' alt='Up One Level' width='32' /></A></td> <td class='online-navigation'><a rel="next" title="8.16 nis " rel="next" title="8.16 nis " href="module-nis.html"><img src='../icons/next.png' border='0' height='32' alt='Next Page' width='32' /></A></td> <td align="center" width="100%">Python Library Reference</td> <td class='online-navigation'><a rel="contents" title="Table of Contents" rel="contents" title="Table of Contents" href="contents.html"><img src='../icons/contents.png' border='0' height='32' alt='Contents' width='32' /></A></td> <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' border='0' height='32' alt='Module Index' width='32' /></a></td> <td class='online-navigation'><a rel="index" title="Index" rel="index" title="Index" href="genindex.html"><img src='../icons/index.png' border='0' height='32' alt='Index' width='32' /></A></td> </tr></table> <div class='online-navigation'> <b class="navlabel">Previous:</b> <a class="sectref" rel="prev" href="node373.html">8.15.1 Resource Limits</A> <b class="navlabel">Up:</b> <a class="sectref" rel="parent" href="module-resource.html">8.15 resource </A> <b class="navlabel">Next:</b> <a class="sectref" rel="next" href="module-nis.html">8.16 nis </A> </div> </div> <hr /> <span class="release-info">Release 2.3.4, documentation updated on May 20, 2004.</span> </DIV> <!--End of Navigation Panel--> <ADDRESS> See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. </ADDRESS> </BODY> </HTML>