Team Ai
Apppublic

parthtamu/rag-code-assistant

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
profile.html721 linesDownload Raw Back to docs
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4  <head>5    <meta charset="utf-8" />6    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="profile — Pure Python profiler" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/profile.html" />10<meta property="og:site_name" content="Python documentation" />11<meta property="og:description" content="Source code: Lib/profile.py The profile module is deprecated and will be removed in Python 3.17. Use profiling.tracing instead. The profile module provides a pure Python implementation of a determi..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_profile_057310e1.png" />15<meta property="og:image:alt" content="Source code: Lib/profile.py The profile module is deprecated and will be removed in Python 3.17. Use profiling.tracing instead. The profile module provides a pure Python implementation of a determi..." />16<meta name="description" content="Source code: Lib/profile.py The profile module is deprecated and will be removed in Python 3.17. Use profiling.tracing instead. The profile module provides a pure Python implementation of a determi..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20    <title>profile — Pure Python profiler &#8212; Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21    22    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23    <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24    <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25    <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26    <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27    28    <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29    <script src="../_static/doctools.js?v=9bcbadda"></script>30    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31    <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32    33    <script src="../_static/sidebar.js"></script>34    35    <link rel="search" type="application/opensearchdescription+xml"36          title="Search within Python 3.15.0a6 documentation"37          href="../_static/opensearch.xml"/>38    <link rel="author" title="About these documents" href="../about.html" />39    <link rel="index" title="Index" href="../genindex.html" />40    <link rel="search" title="Search" href="../search.html" />41    <link rel="copyright" title="Copyright" href="../copyright.html" />42    <link rel="next" title="Removed Modules" href="removed.html" />43    <link rel="prev" title="getopt — C-style parser for command line options" href="getopt.html" />44    45      46      <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47      48      <link rel="canonical" href="https://docs.python.org/3/library/profile.html">49      50    51 52    53    <style>54      @media only screen {55        table.full-width-table {56            width: 100%;57        }58      }59    </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61    <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62            <script type="text/javascript" src="../_static/copybutton.js"></script>63            <script type="text/javascript" src="../_static/menu.js"></script>64            <script type="text/javascript" src="../_static/search-focus.js"></script>65            <script type="text/javascript" src="../_static/themetoggle.js"></script> 66            <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67            <meta name="readthedocs-addons-api-version" content="1">68 69  </head>70<body>71<div class="mobile-nav">72    <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73           aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74    <nav class="nav-content" role="navigation">75        <label for="menuToggler" class="toggler__label">76            <span></span>77        </label>78        <span class="nav-items-wrapper">79            <a href="https://www.python.org/" class="nav-logo">80                <img src="../_static/py.svg" alt="Python logo">81            </a>82            <span class="version_switcher_placeholder"></span>83            <form role="search" class="search" action="../search.html" method="get">84                <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85                    <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>86                </svg>87                <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88                <input type="submit" value="Go">89            </form>90        </span>91    </nav>92    <div class="menu-wrapper">93        <nav class="menu" role="navigation" aria-label="main navigation">94            <div class="language_switcher_placeholder"></div>95            96<label class="theme-selector-label">97    Theme98    <select class="theme-selector" oninput="activateTheme(this.value)">99        <option value="auto" selected>Auto</option>100        <option value="light">Light</option>101        <option value="dark">Dark</option>102    </select>103</label>104  <div>105    <h3><a href="../contents.html">Table of Contents</a></h3>106    <ul>107<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> — Pure Python profiler</a><ul>108<li><a class="reference internal" href="#migration">Migration</a></li>109<li><a class="reference internal" href="#profile-and-profiling-tracing-module-reference"><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code> module reference</a></li>110<li><a class="reference internal" href="#differences-from-profiling-tracing">Differences from <code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a></li>111<li><a class="reference internal" href="#what-is-deterministic-profiling">What is deterministic profiling?</a></li>112<li><a class="reference internal" href="#limitations">Limitations</a></li>113<li><a class="reference internal" href="#calibration">Calibration</a></li>114<li><a class="reference internal" href="#using-a-custom-timer">Using a custom timer</a></li>115</ul>116</li>117</ul>118 119  </div>120  <div>121    <h4>Previous topic</h4>122    <p class="topless"><a href="getopt.html"123                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">getopt</span></code> — C-style parser for command line options</a></p>124  </div>125  <div>126    <h4>Next topic</h4>127    <p class="topless"><a href="removed.html"128                          title="next chapter">Removed Modules</a></p>129  </div>130  <script>131    document.addEventListener('DOMContentLoaded', () => {132        const title = document.querySelector('meta[property="og:title"]').content;133        const elements = document.querySelectorAll('.improvepage');134        const pageurl = window.location.href.split('?')[0];135        elements.forEach(element => {136            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));137            url.searchParams.set('pagetitle', title);138            url.searchParams.set('pageurl', pageurl);139            url.searchParams.set('pagesource', "library/profile.rst");140            element.href = url.toString();141        });142    });143  </script>144  <div role="note" aria-label="source link">145    <h3>This page</h3>146    <ul class="this-page-menu">147      <li><a href="../bugs.html">Report a bug</a></li>148      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>149      <li>150        <a href="https://github.com/python/cpython/blob/main/Doc/library/profile.rst?plain=1"151            rel="nofollow">Show source152        </a>153      </li>154      155    </ul>156  </div>157        </nav>158    </div>159</div>160 161  162    <div class="related" role="navigation" aria-label="Related">163      <h3>Navigation</h3>164      <ul>165        <li class="right" style="margin-right: 10px">166          <a href="../genindex.html" title="General Index"167             accesskey="I">index</a></li>168        <li class="right" >169          <a href="../py-modindex.html" title="Python Module Index"170             >modules</a> |</li>171        <li class="right" >172          <a href="removed.html" title="Removed Modules"173             accesskey="N">next</a> |</li>174        <li class="right" >175          <a href="getopt.html" title="getopt — C-style parser for command line options"176             accesskey="P">previous</a> |</li>177 178          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>179          <li><a href="https://www.python.org/">Python</a> &#187;</li>180          <li class="switchers">181            <div class="language_switcher_placeholder"></div>182            <div class="version_switcher_placeholder"></div>183          </li>184          <li>185              186          </li>187    <li id="cpython-language-and-version">188      <a href="../index.html">3.15.0a6 Documentation</a> &#187;189    </li>190 191          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>192          <li class="nav-item nav-item-2"><a href="superseded.html" accesskey="U">Superseded modules</a> &#187;</li>193        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> — Pure Python profiler</a></li>194                <li class="right">195                    196 197    <div class="inline-search" role="search">198        <form class="inline-search" action="../search.html" method="get">199          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">200          <input type="submit" value="Go">201        </form>202    </div>203                     |204                </li>205            <li class="right">206<label class="theme-selector-label">207    Theme208    <select class="theme-selector" oninput="activateTheme(this.value)">209        <option value="auto" selected>Auto</option>210        <option value="light">Light</option>211        <option value="dark">Dark</option>212    </select>213</label> |</li>214            215      </ul>216    </div>    217 218    <div class="document">219      <div class="documentwrapper">220        <div class="bodywrapper">221          <div class="body" role="main">222            223  <section id="module-profile">224<span id="profile-pure-python-profiler"></span><span id="profile"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> — Pure Python profiler<a class="headerlink" href="#module-profile" title="Link to this heading">¶</a></h1>225<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/profile.py">Lib/profile.py</a></p>226<hr class="docutils" />227<div class="deprecated-removed">228<p><span class="versionmodified deprecated">Deprecated since version 3.15, will be removed in version 3.17.</span></p>229</div>230<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> module is deprecated and will be removed in Python 3.17.231Use <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a> instead.</p>232<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> module provides a pure Python implementation of a233deterministic profiler. While useful for understanding profiler internals or234extending profiler behavior through subclassing, its pure Python implementation235introduces significant overhead compared to the C-based <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a>236module.</p>237<p>For most profiling tasks, use:</p>238<ul class="simple">239<li><p><a class="reference internal" href="profiling.sampling.html#module-profiling.sampling" title="profiling.sampling: Statistical sampling profiler for Python processes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.sampling</span></code></a> for production debugging with zero overhead</p></li>240<li><p><a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a> for development and testing</p></li>241</ul>242<section id="migration">243<h2>Migration<a class="headerlink" href="#migration" title="Link to this heading">¶</a></h2>244<p>Migrating from <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> to <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a> is straightforward.245The APIs are compatible:</p>246<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1"># Old (deprecated)</span>247<span class="kn">import</span><span class="w"> </span><span class="nn">profile</span>248<span class="n">profile</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s1">&#39;my_function()&#39;</span><span class="p">)</span>249 250<span class="c1"># New (recommended)</span>251<span class="kn">import</span><span class="w"> </span><span class="nn">profiling.tracing</span>252<span class="n">profiling</span><span class="o">.</span><span class="n">tracing</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s1">&#39;my_function()&#39;</span><span class="p">)</span>253</pre></div>254</div>255<p>For most code, replacing <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">profile</span></code> with <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">profiling.tracing</span></code>256(and using <code class="docutils literal notranslate"><span class="pre">profiling.tracing</span></code> instead of <code class="docutils literal notranslate"><span class="pre">profile</span></code> throughout) provides257a straightforward migration path.</p>258<div class="admonition note">259<p class="admonition-title">Note</p>260<p>The <code class="docutils literal notranslate"><span class="pre">cProfile</span></code> module remains available as a backward-compatible alias261to <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a>. Existing code using <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">cProfile</span></code> will262continue to work without modification.</p>263</div>264</section>265<section id="profile-and-profiling-tracing-module-reference">266<h2><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code> module reference<a class="headerlink" href="#profile-and-profiling-tracing-module-reference" title="Link to this heading">¶</a></h2>267<p>Both the <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> and <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a> modules provide the268following functions:</p>269<dl class="py function">270<dt class="sig sig-object py" id="profile.run">271<span class="sig-prename descclassname"><span class="pre">profile.</span></span><span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">command</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sort</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#profile.run" title="Link to this definition">¶</a></dt>272<dd><p>This function takes a single argument that can be passed to the <a class="reference internal" href="functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a>273function, and an optional file name.  In all cases this routine executes:</p>274<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">exec</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">__main__</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">,</span> <span class="n">__main__</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">)</span>275</pre></div>276</div>277<p>and gathers profiling statistics from the execution. If no file name is278present, then this function automatically creates a <a class="reference internal" href="pstats.html#pstats.Stats" title="pstats.Stats"><code class="xref py py-class docutils literal notranslate"><span class="pre">Stats</span></code></a>279instance and prints a simple profiling report. If the sort value is specified,280it is passed to this <code class="xref py py-class docutils literal notranslate"><span class="pre">Stats</span></code> instance to control how the281results are sorted.</p>282</dd></dl>283 284<dl class="py function">285<dt class="sig sig-object py" id="profile.runctx">286<span class="sig-prename descclassname"><span class="pre">profile.</span></span><span class="sig-name descname"><span class="pre">runctx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">command</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sort</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#profile.runctx" title="Link to this definition">¶</a></dt>287<dd><p>This function is similar to <a class="reference internal" href="#profile.run" title="profile.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">run()</span></code></a>, with added arguments to supply the288globals and locals mappings for the <em>command</em> string. This routine289executes:</p>290<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">exec</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="nb">globals</span><span class="p">,</span> <span class="nb">locals</span><span class="p">)</span>291</pre></div>292</div>293<p>and gathers profiling statistics as in the <a class="reference internal" href="#profile.run" title="profile.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">run()</span></code></a> function above.</p>294</dd></dl>295 296<dl class="py class">297<dt class="sig sig-object py" id="profile.Profile">298<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">profile.</span></span><span class="sig-name descname"><span class="pre">Profile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">timer</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timeunit</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">subcalls</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">builtins</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile" title="Link to this definition">¶</a></dt>299<dd><p>This class is normally only used if more precise control over profiling is300needed than what the <a class="reference internal" href="profiling.tracing.html#profiling.tracing.run" title="profiling.tracing.run"><code class="xref py py-func docutils literal notranslate"><span class="pre">profiling.tracing.run()</span></code></a> function provides.</p>301<p>A custom timer can be supplied for measuring how long code takes to run via302the <em>timer</em> argument. This must be a function that returns a single number303representing the current time. If the number is an integer, the <em>timeunit</em>304specifies a multiplier that specifies the duration of each unit of time. For305example, if the timer returns times measured in thousands of seconds, the306time unit would be <code class="docutils literal notranslate"><span class="pre">.001</span></code>.</p>307<p>Directly using the <code class="xref py py-class docutils literal notranslate"><span class="pre">Profile</span></code> class allows formatting profile results308without writing the profile data to a file:</p>309<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">profiling.tracing</span>310<span class="kn">import</span><span class="w"> </span><span class="nn">pstats</span>311<span class="kn">import</span><span class="w"> </span><span class="nn">io</span>312<span class="kn">from</span><span class="w"> </span><span class="nn">pstats</span><span class="w"> </span><span class="kn">import</span> <span class="n">SortKey</span>313 314<span class="n">pr</span> <span class="o">=</span> <span class="n">profiling</span><span class="o">.</span><span class="n">tracing</span><span class="o">.</span><span class="n">Profile</span><span class="p">()</span>315<span class="n">pr</span><span class="o">.</span><span class="n">enable</span><span class="p">()</span>316<span class="c1"># ... do something ...</span>317<span class="n">pr</span><span class="o">.</span><span class="n">disable</span><span class="p">()</span>318<span class="n">s</span> <span class="o">=</span> <span class="n">io</span><span class="o">.</span><span class="n">StringIO</span><span class="p">()</span>319<span class="n">sortby</span> <span class="o">=</span> <span class="n">SortKey</span><span class="o">.</span><span class="n">CUMULATIVE</span>320<span class="n">ps</span> <span class="o">=</span> <span class="n">pstats</span><span class="o">.</span><span class="n">Stats</span><span class="p">(</span><span class="n">pr</span><span class="p">,</span> <span class="n">stream</span><span class="o">=</span><span class="n">s</span><span class="p">)</span><span class="o">.</span><span class="n">sort_stats</span><span class="p">(</span><span class="n">sortby</span><span class="p">)</span>321<span class="n">ps</span><span class="o">.</span><span class="n">print_stats</span><span class="p">()</span>322<span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">getvalue</span><span class="p">())</span>323</pre></div>324</div>325<p>The <code class="xref py py-class docutils literal notranslate"><span class="pre">Profile</span></code> class can also be used as a context manager (supported326only in <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a>, not in the deprecated <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code>327module; see <a class="reference internal" href="stdtypes.html#typecontextmanager"><span class="std std-ref">Context Manager Types</span></a>):</p>328<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">profiling.tracing</span>329 330<span class="k">with</span> <span class="n">profiling</span><span class="o">.</span><span class="n">tracing</span><span class="o">.</span><span class="n">Profile</span><span class="p">()</span> <span class="k">as</span> <span class="n">pr</span><span class="p">:</span>331    <span class="c1"># ... do something ...</span>332 333    <span class="n">pr</span><span class="o">.</span><span class="n">print_stats</span><span class="p">()</span>334</pre></div>335</div>336<div class="versionchanged">337<p><span class="versionmodified changed">Changed in version 3.8: </span>Added context manager support.</p>338</div>339<dl class="py method">340<dt class="sig sig-object py" id="profile.Profile.enable">341<span class="sig-name descname"><span class="pre">enable</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile.enable" title="Link to this definition">¶</a></dt>342<dd><p>Start collecting profiling data. Only in <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a>.</p>343</dd></dl>344 345<dl class="py method">346<dt class="sig sig-object py" id="profile.Profile.disable">347<span class="sig-name descname"><span class="pre">disable</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile.disable" title="Link to this definition">¶</a></dt>348<dd><p>Stop collecting profiling data. Only in <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a>.</p>349</dd></dl>350 351<dl class="py method">352<dt class="sig sig-object py" id="profile.Profile.create_stats">353<span class="sig-name descname"><span class="pre">create_stats</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile.create_stats" title="Link to this definition">¶</a></dt>354<dd><p>Stop collecting profiling data and record the results internally355as the current profile.</p>356</dd></dl>357 358<dl class="py method">359<dt class="sig sig-object py" id="profile.Profile.print_stats">360<span class="sig-name descname"><span class="pre">print_stats</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sort</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile.print_stats" title="Link to this definition">¶</a></dt>361<dd><p>Create a <a class="reference internal" href="pstats.html#pstats.Stats" title="pstats.Stats"><code class="xref py py-class docutils literal notranslate"><span class="pre">Stats</span></code></a> object based on the current362profile and print the results to stdout.</p>363<p>The <em>sort</em> parameter specifies the sorting order of the displayed364statistics. It accepts a single key or a tuple of keys to enable365multi-level sorting, as in <a class="reference internal" href="pstats.html#pstats.Stats.sort_stats" title="pstats.Stats.sort_stats"><code class="xref py py-meth docutils literal notranslate"><span class="pre">pstats.Stats.sort_stats()</span></code></a>.</p>366<div class="versionadded">367<p><span class="versionmodified added">Added in version 3.13: </span><code class="xref py py-meth docutils literal notranslate"><span class="pre">print_stats()</span></code> now accepts a tuple of keys.</p>368</div>369</dd></dl>370 371<dl class="py method">372<dt class="sig sig-object py" id="profile.Profile.dump_stats">373<span class="sig-name descname"><span class="pre">dump_stats</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">filename</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile.dump_stats" title="Link to this definition">¶</a></dt>374<dd><p>Write the results of the current profile to <em>filename</em>.</p>375</dd></dl>376 377<dl class="py method">378<dt class="sig sig-object py" id="profile.Profile.run">379<span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile.run" title="Link to this definition">¶</a></dt>380<dd><p>Profile the cmd via <a class="reference internal" href="functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a>.</p>381</dd></dl>382 383<dl class="py method">384<dt class="sig sig-object py" id="profile.Profile.runctx">385<span class="sig-name descname"><span class="pre">runctx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cmd</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">globals</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">locals</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile.runctx" title="Link to this definition">¶</a></dt>386<dd><p>Profile the cmd via <a class="reference internal" href="functions.html#exec" title="exec"><code class="xref py py-func docutils literal notranslate"><span class="pre">exec()</span></code></a> with the specified global and387local environment.</p>388</dd></dl>389 390<dl class="py method">391<dt class="sig sig-object py" id="profile.Profile.runcall">392<span class="sig-name descname"><span class="pre">runcall</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="positional-only-separator o"><abbr title="Positional-only parameter separator (PEP 570)"><span class="pre">/</span></abbr></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#profile.Profile.runcall" title="Link to this definition">¶</a></dt>393<dd><p>Profile <code class="docutils literal notranslate"><span class="pre">func(*args,</span> <span class="pre">**kwargs)</span></code></p>394</dd></dl>395 396</dd></dl>397 398<p>Note that profiling will only work if the called command/function actually399returns.  If the interpreter is terminated (e.g. via a <a class="reference internal" href="sys.html#sys.exit" title="sys.exit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.exit()</span></code></a> call400during the called command/function execution) no profiling results will be401printed.</p>402</section>403<section id="differences-from-profiling-tracing">404<h2>Differences from <code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code><a class="headerlink" href="#differences-from-profiling-tracing" title="Link to this heading">¶</a></h2>405<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> module differs from <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a> in several406ways:</p>407<p><strong>Higher overhead.</strong> The pure Python implementation is significantly slower408than the C implementation, making it unsuitable for profiling long-running409programs or performance-sensitive code.</p>410<p><strong>Calibration support.</strong> The <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> module supports calibration to411compensate for profiling overhead. This is not needed in <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a>412because the C implementation has negligible overhead.</p>413<p><strong>Custom timers.</strong> Both modules support custom timers, but <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code>414accepts timer functions that return tuples (like <a class="reference internal" href="os.html#os.times" title="os.times"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.times()</span></code></a>), while415<a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a> requires a function returning a single number.</p>416<p><strong>Subclassing.</strong> The pure Python implementation is easier to subclass and417extend for custom profiling behavior.</p>418</section>419<section id="what-is-deterministic-profiling">420<span id="deterministic-profiling"></span><h2>What is deterministic profiling?<a class="headerlink" href="#what-is-deterministic-profiling" title="Link to this heading">¶</a></h2>421<p><em class="dfn">Deterministic profiling</em> is meant to reflect the fact that all <em>function422call</em>, <em>function return</em>, and <em>exception</em> events are monitored, and precise423timings are made for the intervals between these events (during which time the424user’s code is executing).  In contrast, <em class="dfn">statistical profiling</em> (which is425provided by the <a class="reference internal" href="profiling.sampling.html#module-profiling.sampling" title="profiling.sampling: Statistical sampling profiler for Python processes."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.sampling</span></code></a> module) periodically samples the426effective instruction pointer, and deduces where time is being spent.  The427latter technique traditionally involves less overhead (as the code does not428need to be instrumented), but provides only relative indications of where time429is being spent.</p>430<p>In Python, since there is an interpreter active during execution, the presence431of instrumented code is not required in order to do deterministic profiling.432Python automatically provides a <em class="dfn">hook</em> (optional callback) for each event.433In addition, the interpreted nature of Python tends to add so much overhead to434execution, that deterministic profiling tends to only add small processing435overhead in typical applications.  The result is that deterministic profiling is436not that expensive, yet provides extensive run time statistics about the437execution of a Python program.</p>438<p>Call count statistics can be used to identify bugs in code (surprising counts),439and to identify possible inline-expansion points (high call counts).  Internal440time statistics can be used to identify “hot loops” that should be carefully441optimized.  Cumulative time statistics should be used to identify high level442errors in the selection of algorithms.  Note that the unusual handling of443cumulative times in this profiler allows statistics for recursive444implementations of algorithms to be directly compared to iterative445implementations.</p>446</section>447<section id="limitations">448<span id="profile-limitations"></span><h2>Limitations<a class="headerlink" href="#limitations" title="Link to this heading">¶</a></h2>449<p>One limitation has to do with accuracy of timing information. There is a450fundamental problem with deterministic profilers involving accuracy.  The most451obvious restriction is that the underlying “clock” is only ticking at a rate452(typically) of about .001 seconds.  Hence no measurements will be more accurate453than the underlying clock.  If enough measurements are taken, then the “error”454will tend to average out. Unfortunately, removing this first error induces a455second source of error.</p>456<p>The second problem is that it “takes a while” from when an event is dispatched457until the profiler’s call to get the time actually <em>gets</em> the state of the458clock.  Similarly, there is a certain lag when exiting the profiler event459handler from the time that the clock’s value was obtained (and then squirreled460away), until the user’s code is once again executing.  As a result, functions461that are called many times, or call many functions, will typically accumulate462this error. The error that accumulates in this fashion is typically less than463the accuracy of the clock (less than one clock tick), but it <em>can</em> accumulate464and become very significant.</p>465<p>The problem is more important with the deprecated <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> module than466with the lower-overhead <a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a>.  For this reason,467<code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> provides a means of calibrating itself for a given platform so468that this error can be probabilistically (on the average) removed. After the469profiler is calibrated, it will be more accurate (in a least square sense), but470it will sometimes produce negative numbers (when call counts are exceptionally471low, and the gods of probability work against you :-). )  Do <em>not</em> be alarmed472by negative numbers in the profile.  They should <em>only</em> appear if you have473calibrated your profiler, and the results are actually better than without474calibration.</p>475</section>476<section id="calibration">477<span id="profile-calibration"></span><h2>Calibration<a class="headerlink" href="#calibration" title="Link to this heading">¶</a></h2>478<p>The profiler of the <code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> module subtracts a constant from each event479handling time to compensate for the overhead of calling the time function, and480socking away the results.  By default, the constant is 0. The following481procedure can be used to obtain a better constant for a given platform (see482<a class="reference internal" href="#profile-limitations"><span class="std std-ref">Limitations</span></a>).</p>483<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">profile</span>484<span class="n">pr</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">Profile</span><span class="p">()</span>485<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">):</span>486    <span class="nb">print</span><span class="p">(</span><span class="n">pr</span><span class="o">.</span><span class="n">calibrate</span><span class="p">(</span><span class="mi">10000</span><span class="p">))</span>487</pre></div>488</div>489<p>The method executes the number of Python calls given by the argument, directly490and again under the profiler, measuring the time for both. It then computes the491hidden overhead per profiler event, and returns that as a float.  For example,492on a 1.8Ghz Intel Core i5 running macOS, and using Python’s time.process_time() as493the timer, the magical number is about 4.04e-6.</p>494<p>The object of this exercise is to get a fairly consistent result. If your495computer is <em>very</em> fast, or your timer function has poor resolution, you might496have to pass 100000, or even 1000000, to get consistent results.</p>497<p>When you have a consistent answer, there are three ways you can use it:</p>498<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">profile</span>499 500<span class="c1"># 1. Apply computed bias to all Profile instances created hereafter.</span>501<span class="n">profile</span><span class="o">.</span><span class="n">Profile</span><span class="o">.</span><span class="n">bias</span> <span class="o">=</span> <span class="n">your_computed_bias</span>502 503<span class="c1"># 2. Apply computed bias to a specific Profile instance.</span>504<span class="n">pr</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">Profile</span><span class="p">()</span>505<span class="n">pr</span><span class="o">.</span><span class="n">bias</span> <span class="o">=</span> <span class="n">your_computed_bias</span>506 507<span class="c1"># 3. Specify computed bias in instance constructor.</span>508<span class="n">pr</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">Profile</span><span class="p">(</span><span class="n">bias</span><span class="o">=</span><span class="n">your_computed_bias</span><span class="p">)</span>509</pre></div>510</div>511<p>If you have a choice, you are better off choosing a smaller constant, and then512your results will “less often” show up as negative in profile statistics.</p>513</section>514<section id="using-a-custom-timer">515<span id="profile-timers"></span><h2>Using a custom timer<a class="headerlink" href="#using-a-custom-timer" title="Link to this heading">¶</a></h2>516<p>If you want to change how current time is determined (for example, to force use517of wall-clock time or elapsed process time), pass the timing function you want518to the <a class="reference internal" href="#profile.Profile" title="profile.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">Profile</span></code></a> class constructor:</p>519<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">pr</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">Profile</span><span class="p">(</span><span class="n">your_time_func</span><span class="p">)</span>520</pre></div>521</div>522<p>The resulting profiler will then call <code class="docutils literal notranslate"><span class="pre">your_time_func</span></code>. Depending on whether523you are using <a class="reference internal" href="#profile.Profile" title="profile.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">profile.Profile</span></code></a> or <a class="reference internal" href="profiling.tracing.html#profiling.tracing.Profile" title="profiling.tracing.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">profiling.tracing.Profile</span></code></a>,524<code class="docutils literal notranslate"><span class="pre">your_time_func</span></code>’s return value will be interpreted differently:</p>525<dl>526<dt><a class="reference internal" href="#profile.Profile" title="profile.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">profile.Profile</span></code></a></dt><dd><p><code class="docutils literal notranslate"><span class="pre">your_time_func</span></code> should return a single number, or a list of numbers whose527sum is the current time (like what <a class="reference internal" href="os.html#os.times" title="os.times"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.times()</span></code></a> returns).  If the528function returns a single time number, or the list of returned numbers has529length 2, then you will get an especially fast version of the dispatch530routine.</p>531<p>Be warned that you should calibrate the profiler class for the timer function532that you choose (see <a class="reference internal" href="#profile-calibration"><span class="std std-ref">Calibration</span></a>).  For most machines, a timer533that returns a lone integer value will provide the best results in terms of534low overhead during profiling.  (<a class="reference internal" href="os.html#os.times" title="os.times"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.times()</span></code></a> is <em>pretty</em> bad, as it535returns a tuple of floating-point values).  If you want to substitute a536better timer in the cleanest fashion, derive a class and hardwire a537replacement dispatch method that best handles your timer call, along with the538appropriate calibration constant.</p>539</dd>540<dt><a class="reference internal" href="profiling.tracing.html#profiling.tracing.Profile" title="profiling.tracing.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">profiling.tracing.Profile</span></code></a></dt><dd><p><code class="docutils literal notranslate"><span class="pre">your_time_func</span></code> should return a single number.  If it returns integers,541you can also invoke the class constructor with a second argument specifying542the real duration of one unit of time.  For example, if543<code class="docutils literal notranslate"><span class="pre">your_integer_time_func</span></code> returns times measured in thousands of seconds,544you would construct the <a class="reference internal" href="#profile.Profile" title="profile.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">Profile</span></code></a> instance as follows:</p>545<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">pr</span> <span class="o">=</span> <span class="n">profiling</span><span class="o">.</span><span class="n">tracing</span><span class="o">.</span><span class="n">Profile</span><span class="p">(</span><span class="n">your_integer_time_func</span><span class="p">,</span> <span class="mf">0.001</span><span class="p">)</span>546</pre></div>547</div>548<p>As the <a class="reference internal" href="profiling.tracing.html#profiling.tracing.Profile" title="profiling.tracing.Profile"><code class="xref py py-class docutils literal notranslate"><span class="pre">profiling.tracing.Profile</span></code></a> class cannot be calibrated, custom549timer functions should be used with care and should be as fast as possible.550For the best results with a custom timer, it might be necessary to hard-code551it in the C source of the internal <code class="xref py py-mod docutils literal notranslate"><span class="pre">_lsprof</span></code> module.</p>552</dd>553</dl>554<p>Python 3.3 adds several new functions in <a class="reference internal" href="time.html#module-time" title="time: Time access and conversions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">time</span></code></a> that can be used to make555precise measurements of process or wall-clock time. For example, see556<a class="reference internal" href="time.html#time.perf_counter" title="time.perf_counter"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.perf_counter()</span></code></a>.</p>557<div class="admonition seealso">558<p class="admonition-title">See also</p>559<dl class="simple">560<dt><a class="reference internal" href="profiling.html#module-profiling" title="profiling: Python profiling tools for performance analysis."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling</span></code></a></dt><dd><p>Overview of Python profiling tools.</p>561</dd>562<dt><a class="reference internal" href="profiling.tracing.html#module-profiling.tracing" title="profiling.tracing: Deterministic tracing profiler for Python programs."><code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a></dt><dd><p>Recommended replacement for this module.</p>563</dd>564<dt><a class="reference internal" href="pstats.html#module-pstats" title="pstats: Statistics object for analyzing profiler output."><code class="xref py py-mod docutils literal notranslate"><span class="pre">pstats</span></code></a></dt><dd><p>Statistical analysis and formatting for profile data.</p>565</dd>566</dl>567</div>568</section>569</section>570 571 572            <div class="clearer"></div>573          </div>574        </div>575      </div>576      <div class="sphinxsidebar" role="navigation" aria-label="Main">577        <div class="sphinxsidebarwrapper">578  <div>579    <h3><a href="../contents.html">Table of Contents</a></h3>580    <ul>581<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> — Pure Python profiler</a><ul>582<li><a class="reference internal" href="#migration">Migration</a></li>583<li><a class="reference internal" href="#profile-and-profiling-tracing-module-reference"><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> and <code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code> module reference</a></li>584<li><a class="reference internal" href="#differences-from-profiling-tracing">Differences from <code class="xref py py-mod docutils literal notranslate"><span class="pre">profiling.tracing</span></code></a></li>585<li><a class="reference internal" href="#what-is-deterministic-profiling">What is deterministic profiling?</a></li>586<li><a class="reference internal" href="#limitations">Limitations</a></li>587<li><a class="reference internal" href="#calibration">Calibration</a></li>588<li><a class="reference internal" href="#using-a-custom-timer">Using a custom timer</a></li>589</ul>590</li>591</ul>592 593  </div>594  <div>595    <h4>Previous topic</h4>596    <p class="topless"><a href="getopt.html"597                          title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">getopt</span></code> — C-style parser for command line options</a></p>598  </div>599  <div>600    <h4>Next topic</h4>601    <p class="topless"><a href="removed.html"602                          title="next chapter">Removed Modules</a></p>603  </div>604  <script>605    document.addEventListener('DOMContentLoaded', () => {606        const title = document.querySelector('meta[property="og:title"]').content;607        const elements = document.querySelectorAll('.improvepage');608        const pageurl = window.location.href.split('?')[0];609        elements.forEach(element => {610            const url = new URL(element.href.split('?')[0].replace("-nojs", ""));611            url.searchParams.set('pagetitle', title);612            url.searchParams.set('pageurl', pageurl);613            url.searchParams.set('pagesource', "library/profile.rst");614            element.href = url.toString();615        });616    });617  </script>618  <div role="note" aria-label="source link">619    <h3>This page</h3>620    <ul class="this-page-menu">621      <li><a href="../bugs.html">Report a bug</a></li>622      <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>623      <li>624        <a href="https://github.com/python/cpython/blob/main/Doc/library/profile.rst?plain=1"625            rel="nofollow">Show source626        </a>627      </li>628      629    </ul>630  </div>631        </div>632<div id="sidebarbutton" title="Collapse sidebar">633<span>«</span>634</div>635 636      </div>637      <div class="clearer"></div>638    </div>  639    <div class="related" role="navigation" aria-label="Related">640      <h3>Navigation</h3>641      <ul>642        <li class="right" style="margin-right: 10px">643          <a href="../genindex.html" title="General Index"644             >index</a></li>645        <li class="right" >646          <a href="../py-modindex.html" title="Python Module Index"647             >modules</a> |</li>648        <li class="right" >649          <a href="removed.html" title="Removed Modules"650             >next</a> |</li>651        <li class="right" >652          <a href="getopt.html" title="getopt — C-style parser for command line options"653             >previous</a> |</li>654 655          <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>656          <li><a href="https://www.python.org/">Python</a> &#187;</li>657          <li class="switchers">658            <div class="language_switcher_placeholder"></div>659            <div class="version_switcher_placeholder"></div>660          </li>661          <li>662              663          </li>664    <li id="cpython-language-and-version">665      <a href="../index.html">3.15.0a6 Documentation</a> &#187;666    </li>667 668          <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>669          <li class="nav-item nav-item-2"><a href="superseded.html" >Superseded modules</a> &#187;</li>670        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">profile</span></code> — Pure Python profiler</a></li>671                <li class="right">672                    673 674    <div class="inline-search" role="search">675        <form class="inline-search" action="../search.html" method="get">676          <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">677          <input type="submit" value="Go">678        </form>679    </div>680                     |681                </li>682            <li class="right">683<label class="theme-selector-label">684    Theme685    <select class="theme-selector" oninput="activateTheme(this.value)">686        <option value="auto" selected>Auto</option>687        <option value="light">Light</option>688        <option value="dark">Dark</option>689    </select>690</label> |</li>691            692      </ul>693    </div>  694    <div class="footer">695    &copy; <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.696    <br>697    This page is licensed under the Python Software Foundation License Version 2.698    <br>699    Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.700    <br>701    702      See <a href="/license.html">History and License</a> for more information.<br>703    704    705    <br>706 707    The Python Software Foundation is a non-profit corporation.708<a href="https://www.python.org/psf/donations/">Please donate.</a>709<br>710    <br>711      Last updated on Mar 10, 2026 (08:58 UTC).712    713      <a href="/bugs.html">Found a bug</a>?714    715    <br>716 717    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.718    </div>719 720  </body>721</html>