/usr/share/doc/python-objgraph-doc/html/objgraph.html is in python-objgraph-doc 2.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>objgraph — objgraph 2.0.1 documentation</title>
<link rel="stylesheet" href="_static/mg.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '2.0.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="objgraph 2.0.1 documentation" href="index.html" />
<link rel="next" title="Too many references" href="references.html" />
<link rel="prev" title="Python Object Graphs" href="index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="py-modindex.html" title="Python Module Index"
>modules</a></li>
<li class="right" >
<a href="references.html" title="Too many references"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="Python Object Graphs"
accesskey="P">previous</a> |</li>
<li><a href="index.html">home</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-objgraph">
<span id="objgraph"></span><h1><a class="reference internal" href="#module-objgraph" title="objgraph"><tt class="xref py py-mod docutils literal"><span class="pre">objgraph</span></tt></a><a class="headerlink" href="#module-objgraph" title="Permalink to this headline">¶</a></h1>
<p>Tools for drawing Python object reference graphs with graphviz.</p>
<p>You can find documentation online at <a class="reference external" href="http://mg.pov.lt/objgraph/">http://mg.pov.lt/objgraph/</a></p>
<p>Copyright (c) 2008-2015 Marius Gedminas <<a class="reference external" href="mailto:marius%40pov.lt">marius<span>@</span>pov<span>.</span>lt</a>> and contributors</p>
<p>Released under the MIT licence.</p>
<div class="section" id="statistics">
<h2>Statistics<a class="headerlink" href="#statistics" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="objgraph.count">
<tt class="descclassname">objgraph.</tt><tt class="descname">count</tt><big>(</big><em>typename</em><span class="optional">[</span>, <em>objects</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.count" title="Permalink to this definition">¶</a></dt>
<dd><p>Count objects tracked by the garbage collector with a given class name.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">count</span><span class="p">(</span><span class="s">'dict'</span><span class="p">)</span>
<span class="go">42</span>
<span class="gp">>>> </span><span class="n">count</span><span class="p">(</span><span class="s">'MyClass'</span><span class="p">,</span> <span class="n">get_leaking_objects</span><span class="p">())</span>
<span class="go">3</span>
<span class="gp">>>> </span><span class="n">count</span><span class="p">(</span><span class="s">'mymodule.MyClass'</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
<p>Note that the GC does not track simple objects like int or str.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.7: </span>New parameter: <tt class="docutils literal"><span class="pre">objects</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>Accepts fully-qualified type names (i.e. ‘package.module.ClassName’)
as well as short type names (i.e. ‘ClassName’).</p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.typestats">
<tt class="descclassname">objgraph.</tt><tt class="descname">typestats</tt><big>(</big><span class="optional">[</span><em>objects</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.typestats" title="Permalink to this definition">¶</a></dt>
<dd><p>Count the number of instances for each type tracked by the GC.</p>
<p>Note that the GC does not track simple objects like int or str.</p>
<p>Note that classes with the same name but defined in different modules
will be lumped together if <tt class="docutils literal"><span class="pre">shortnames</span></tt> is True.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">typestats</span><span class="p">()</span>
<span class="go">{'list': 12041, 'tuple': 10245, ...}</span>
<span class="gp">>>> </span><span class="n">typestats</span><span class="p">(</span><span class="n">get_leaking_objects</span><span class="p">())</span>
<span class="go">{'MemoryError': 1, 'tuple': 2795, 'RuntimeError': 1, 'list': 47, ...}</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.7: </span>New parameter: <tt class="docutils literal"><span class="pre">objects</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>New parameter: <tt class="docutils literal"><span class="pre">shortnames</span></tt>.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.most_common_types">
<tt class="descclassname">objgraph.</tt><tt class="descname">most_common_types</tt><big>(</big><span class="optional">[</span><em>limit=10</em>, <em>objects</em>, <em>shortnames=True</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.most_common_types" title="Permalink to this definition">¶</a></dt>
<dd><p>Count the names of types with the most instances.</p>
<p>Returns a list of (type_name, count), sorted most-frequent-first.</p>
<p>Limits the return value to at most <tt class="docutils literal"><span class="pre">limit</span></tt> items. You may set <tt class="docutils literal"><span class="pre">limit</span></tt>
to None to avoid that.</p>
<p>The caveats documented in <a class="reference internal" href="#objgraph.typestats" title="objgraph.typestats"><tt class="xref py py-func docutils literal"><span class="pre">typestats()</span></tt></a> apply.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">most_common_types</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="go">[('list', 12041), ('tuple', 10245)]</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.4.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.7: </span>New parameter: <tt class="docutils literal"><span class="pre">objects</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>New parameter: <tt class="docutils literal"><span class="pre">shortnames</span></tt>.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.show_most_common_types">
<tt class="descclassname">objgraph.</tt><tt class="descname">show_most_common_types</tt><big>(</big><span class="optional">[</span><em>limit=10</em>, <em>objects</em>, <em>shortnames=True</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.show_most_common_types" title="Permalink to this definition">¶</a></dt>
<dd><p>Print the table of types of most common instances.</p>
<p>The caveats documented in <a class="reference internal" href="#objgraph.typestats" title="objgraph.typestats"><tt class="xref py py-func docutils literal"><span class="pre">typestats()</span></tt></a> apply.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">show_most_common_types</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="go">tuple 8959</span>
<span class="go">function 2442</span>
<span class="go">wrapper_descriptor 1048</span>
<span class="go">dict 953</span>
<span class="go">builtin_function_or_method 800</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.7: </span>New parameter: <tt class="docutils literal"><span class="pre">objects</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>New parameter: <tt class="docutils literal"><span class="pre">shortnames</span></tt>.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.show_growth">
<tt class="descclassname">objgraph.</tt><tt class="descname">show_growth</tt><big>(</big><span class="optional">[</span><em>limit=10</em>, <em>peak_stats={}</em>, <em>shortnames=True</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.show_growth" title="Permalink to this definition">¶</a></dt>
<dd><p>Show the increase in peak object counts since last call.</p>
<p>Limits the output to <tt class="docutils literal"><span class="pre">limit</span></tt> largest deltas. You may set <tt class="docutils literal"><span class="pre">limit</span></tt> to
None to see all of them.</p>
<p>Uses and updates <tt class="docutils literal"><span class="pre">peak_stats</span></tt>, a dictionary from type names to previously
seen peak object counts. Usually you don’t need to pay attention to this
argument.</p>
<p>The caveats documented in <a class="reference internal" href="#objgraph.typestats" title="objgraph.typestats"><tt class="xref py py-func docutils literal"><span class="pre">typestats()</span></tt></a> apply.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">show_growth</span><span class="p">()</span>
<span class="go">wrapper_descriptor 970 +14</span>
<span class="go">tuple 12282 +10</span>
<span class="go">dict 1922 +7</span>
<span class="gp">...</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.5.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>New parameter: <tt class="docutils literal"><span class="pre">shortnames</span></tt>.</p>
</div>
</dd></dl>
</div>
<div class="section" id="locating-and-filtering-objects">
<h2>Locating and Filtering Objects<a class="headerlink" href="#locating-and-filtering-objects" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="objgraph.get_leaking_objects">
<tt class="descclassname">objgraph.</tt><tt class="descname">get_leaking_objects</tt><big>(</big><span class="optional">[</span><em>objects</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.get_leaking_objects" title="Permalink to this definition">¶</a></dt>
<dd><p>Return objects that do not have any referents.</p>
<p>These could indicate reference-counting bugs in C code. Or they could
be legitimate.</p>
<p>Note that the GC does not track simple objects like int or str.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.7.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.by_type">
<tt class="descclassname">objgraph.</tt><tt class="descname">by_type</tt><big>(</big><em>typename</em><span class="optional">[</span>, <em>objects</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.by_type" title="Permalink to this definition">¶</a></dt>
<dd><p>Return objects tracked by the garbage collector with a given class name.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">by_type</span><span class="p">(</span><span class="s">'MyClass'</span><span class="p">)</span>
<span class="go">[<mymodule.MyClass object at 0x...>]</span>
</pre></div>
</div>
<p>Note that the GC does not track simple objects like int or str.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.7: </span>New parameter: <tt class="docutils literal"><span class="pre">objects</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>Accepts fully-qualified type names (i.e. ‘package.module.ClassName’)
as well as short type names (i.e. ‘ClassName’).</p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.at">
<tt class="descclassname">objgraph.</tt><tt class="descname">at</tt><big>(</big><em>addr</em><big>)</big><a class="headerlink" href="#objgraph.at" title="Permalink to this definition">¶</a></dt>
<dd><p>Return an object at a given memory address.</p>
<p>The reverse of id(obj):</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">at</span><span class="p">(</span><span class="nb">id</span><span class="p">(</span><span class="n">obj</span><span class="p">))</span> <span class="ow">is</span> <span class="n">obj</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Note that this function does not work on objects that are not tracked by
the GC (e.g. ints or strings).</p>
</dd></dl>
<dl class="function">
<dt id="objgraph.is_proper_module">
<tt class="descclassname">objgraph.</tt><tt class="descname">is_proper_module</tt><big>(</big><em>obj</em><big>)</big><a class="headerlink" href="#objgraph.is_proper_module" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <tt class="docutils literal"><span class="pre">True</span></tt> if <tt class="docutils literal"><span class="pre">obj</span></tt> can be treated like a garbage collector root.</p>
<p>That is, if <tt class="docutils literal"><span class="pre">obj</span></tt> is a module that is in <tt class="docutils literal"><span class="pre">sys.modules</span></tt>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">types</span>
<span class="gp">>>> </span><span class="n">is_proper_module</span><span class="p">([])</span>
<span class="go">False</span>
<span class="gp">>>> </span><span class="n">is_proper_module</span><span class="p">(</span><span class="n">types</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">>>> </span><span class="n">is_proper_module</span><span class="p">(</span><span class="n">types</span><span class="o">.</span><span class="n">ModuleType</span><span class="p">(</span><span class="s">'foo'</span><span class="p">))</span>
<span class="go">False</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.8.</span></p>
</div>
</dd></dl>
</div>
<div class="section" id="traversing-and-displaying-object-graphs">
<h2>Traversing and Displaying Object Graphs<a class="headerlink" href="#traversing-and-displaying-object-graphs" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="objgraph.find_ref_chain">
<tt class="descclassname">objgraph.</tt><tt class="descname">find_ref_chain</tt><big>(</big><em>obj</em>, <em>predicate</em><span class="optional">[</span>, <em>max_depth=20</em>, <em>extra_ignore=()</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.find_ref_chain" title="Permalink to this definition">¶</a></dt>
<dd><p>Find a shortest chain of references leading from obj.</p>
<p>The end of the chain will be some object that matches your predicate.</p>
<p><tt class="docutils literal"><span class="pre">predicate</span></tt> is a function taking one argument and returning a boolean.</p>
<p><tt class="docutils literal"><span class="pre">max_depth</span></tt> limits the search depth.</p>
<p><tt class="docutils literal"><span class="pre">extra_ignore</span></tt> can be a list of object IDs to exclude those objects from
your search.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">find_ref_chain</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">MyClass</span><span class="p">))</span>
<span class="go">[obj, ..., <MyClass object at ...>]</span>
</pre></div>
</div>
<p>Returns <tt class="docutils literal"><span class="pre">[obj]</span></tt> if such a chain could not be found.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.7.</span></p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.find_backref_chain">
<tt class="descclassname">objgraph.</tt><tt class="descname">find_backref_chain</tt><big>(</big><em>obj</em>, <em>predicate</em><span class="optional">[</span>, <em>max_depth=20</em>, <em>extra_ignore=()</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.find_backref_chain" title="Permalink to this definition">¶</a></dt>
<dd><p>Find a shortest chain of references leading to obj.</p>
<p>The start of the chain will be some object that matches your predicate.</p>
<p><tt class="docutils literal"><span class="pre">predicate</span></tt> is a function taking one argument and returning a boolean.</p>
<p><tt class="docutils literal"><span class="pre">max_depth</span></tt> limits the search depth.</p>
<p><tt class="docutils literal"><span class="pre">extra_ignore</span></tt> can be a list of object IDs to exclude those objects from
your search.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">find_backref_chain</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">is_proper_module</span><span class="p">)</span>
<span class="go">[<module ...>, ..., obj]</span>
</pre></div>
</div>
<p>Returns <tt class="docutils literal"><span class="pre">[obj]</span></tt> if such a chain could not be found.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.5: </span>Returns <tt class="docutils literal"><span class="pre">obj</span></tt> instead of <tt class="docutils literal"><span class="pre">None</span></tt> when a chain could not be found.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.show_chain">
<tt class="descclassname">objgraph.</tt><tt class="descname">show_chain</tt><big>(</big><em>chain</em><span class="optional">[</span>, <em>...</em>, <em>highlight=None</em>, <em>filename=None</em>, <em>extra_info=None</em>, <em>refcounts=False</em>, <em>shortnames=True</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.show_chain" title="Permalink to this definition">¶</a></dt>
<dd><p>Show a chain (or several chains) of object references.</p>
<p>Useful in combination with <a class="reference internal" href="#objgraph.find_ref_chain" title="objgraph.find_ref_chain"><tt class="xref py py-func docutils literal"><span class="pre">find_ref_chain()</span></tt></a> or
<a class="reference internal" href="#objgraph.find_backref_chain" title="objgraph.find_backref_chain"><tt class="xref py py-func docutils literal"><span class="pre">find_backref_chain()</span></tt></a>, e.g.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">show_chain</span><span class="p">(</span><span class="n">find_backref_chain</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">is_proper_module</span><span class="p">))</span>
</pre></div>
</div>
<p>You can specify if you want that chain traced backwards or forwards
by passing a <tt class="docutils literal"><span class="pre">backrefs</span></tt> keyword argument, e.g.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">show_chain</span><span class="p">(</span><span class="n">find_ref_chain</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">is_proper_module</span><span class="p">),</span>
<span class="gp">... </span> <span class="n">backrefs</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
</pre></div>
</div>
<p>Ideally this shouldn’t matter, but for some objects
<tt class="xref py py-func docutils literal"><span class="pre">gc.get_referrers()</span></tt> and <tt class="xref py py-func docutils literal"><span class="pre">gc.get_referents()</span></tt> are not perfectly
symmetrical.</p>
<p>You can specify <tt class="docutils literal"><span class="pre">highlight</span></tt>, <tt class="docutils literal"><span class="pre">extra_info</span></tt>, <tt class="docutils literal"><span class="pre">refcounts</span></tt>,
<tt class="docutils literal"><span class="pre">shortnames</span></tt>,``filename`` or <tt class="docutils literal"><span class="pre">output</span></tt> arguments like for
<a class="reference internal" href="#objgraph.show_backrefs" title="objgraph.show_backrefs"><tt class="xref py py-func docutils literal"><span class="pre">show_backrefs()</span></tt></a> or <a class="reference internal" href="#objgraph.show_refs" title="objgraph.show_refs"><tt class="xref py py-func docutils literal"><span class="pre">show_refs()</span></tt></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.5.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.7: </span>New parameter: <tt class="docutils literal"><span class="pre">backrefs</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.0: </span>New parameter: <tt class="docutils literal"><span class="pre">output</span></tt>.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.show_backrefs">
<tt class="descclassname">objgraph.</tt><tt class="descname">show_backrefs</tt><big>(</big><em>objs</em><span class="optional">[</span>, <em>max_depth=3</em>, <em>extra_ignore=()</em>, <em>filter=None</em>, <em>too_many=10</em>, <em>highlight=None</em>, <em>filename=None</em>, <em>extra_info=None</em>, <em>refcounts=False</em>, <em>shortnames=True</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.show_backrefs" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate an object reference graph ending at <tt class="docutils literal"><span class="pre">objs</span></tt>.</p>
<p>The graph will show you what objects refer to <tt class="docutils literal"><span class="pre">objs</span></tt>, directly and
indirectly.</p>
<p><tt class="docutils literal"><span class="pre">objs</span></tt> can be a single object, or it can be a list of objects. If
unsure, wrap the single object in a new list.</p>
<p><tt class="docutils literal"><span class="pre">filename</span></tt> if specified, can be the name of a .dot or a image
file, whose extension indicates the desired output format; note
that output to a specific format is entirely handled by GraphViz:
if the desired format is not supported, you just get the .dot
file. If <tt class="docutils literal"><span class="pre">filename</span></tt> and <tt class="docutils literal"><span class="pre">output</span></tt> is not specified, <tt class="docutils literal"><span class="pre">show_backrefs</span></tt>
will try to produce a .dot file and spawn a viewer (xdot). If xdot is
not available, <tt class="docutils literal"><span class="pre">show_backrefs</span></tt> will convert the .dot file to a
.png and print its name.</p>
<p><tt class="docutils literal"><span class="pre">output</span></tt> if specified, the GraphViz output will be written to this
file object. <tt class="docutils literal"><span class="pre">output</span></tt> and <tt class="docutils literal"><span class="pre">filename</span></tt> should not both be specified.</p>
<p>Use <tt class="docutils literal"><span class="pre">max_depth</span></tt> and <tt class="docutils literal"><span class="pre">too_many</span></tt> to limit the depth and breadth of the
graph.</p>
<p>Use <tt class="docutils literal"><span class="pre">filter</span></tt> (a predicate) and <tt class="docutils literal"><span class="pre">extra_ignore</span></tt> (a list of object IDs) to
remove undesired objects from the graph.</p>
<p>Use <tt class="docutils literal"><span class="pre">highlight</span></tt> (a predicate) to highlight certain graph nodes in blue.</p>
<p>Use <tt class="docutils literal"><span class="pre">extra_info</span></tt> (a function taking one argument and returning a
string) to report extra information for objects.</p>
<p>Specify <tt class="docutils literal"><span class="pre">refcounts=True</span></tt> if you want to see reference counts.
These will mostly match the number of arrows pointing to an object,
but can be different for various reasons.</p>
<p>Specify <tt class="docutils literal"><span class="pre">shortnames=False</span></tt> if you want to see fully-qualified type
names (‘package.module.ClassName’). By default you get to see only the
class name part.</p>
<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">show_backrefs</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">show_backrefs</span><span class="p">([</span><span class="n">obj1</span><span class="p">,</span> <span class="n">obj2</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">show_backrefs</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">max_depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">show_backrefs</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">filter</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">inspect</span><span class="o">.</span><span class="n">isclass</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">show_backrefs</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">highlight</span><span class="o">=</span><span class="n">inspect</span><span class="o">.</span><span class="n">isclass</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">show_backrefs</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">extra_ignore</span><span class="o">=</span><span class="p">[</span><span class="nb">id</span><span class="p">(</span><span class="nb">locals</span><span class="p">())])</span>
</pre></div>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.3: </span>New parameters: <tt class="docutils literal"><span class="pre">filename</span></tt>, <tt class="docutils literal"><span class="pre">extra_info</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.5: </span>New parameter: <tt class="docutils literal"><span class="pre">refcounts</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>New parameter: <tt class="docutils literal"><span class="pre">shortnames</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.0: </span>New parameter: <tt class="docutils literal"><span class="pre">output</span></tt>.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="objgraph.show_refs">
<tt class="descclassname">objgraph.</tt><tt class="descname">show_refs</tt><big>(</big><em>objs</em><span class="optional">[</span>, <em>max_depth=3</em>, <em>extra_ignore=()</em>, <em>filter=None</em>, <em>too_many=10</em>, <em>highlight=None</em>, <em>filename=None</em>, <em>extra_info=None</em>, <em>refcounts=False</em>, <em>shortnames=True</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#objgraph.show_refs" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate an object reference graph starting at <tt class="docutils literal"><span class="pre">objs</span></tt>.</p>
<p>The graph will show you what objects are reachable from <tt class="docutils literal"><span class="pre">objs</span></tt>, directly
and indirectly.</p>
<p><tt class="docutils literal"><span class="pre">objs</span></tt> can be a single object, or it can be a list of objects. If
unsure, wrap the single object in a new list.</p>
<p><tt class="docutils literal"><span class="pre">filename</span></tt> if specified, can be the name of a .dot or a image
file, whose extension indicates the desired output format; note
that output to a specific format is entirely handled by GraphViz:
if the desired format is not supported, you just get the .dot
file. If <tt class="docutils literal"><span class="pre">filename</span></tt> and <tt class="docutils literal"><span class="pre">output</span></tt> is not specified, <tt class="docutils literal"><span class="pre">show_refs</span></tt> will
try to produce a .dot file and spawn a viewer (xdot). If xdot is
not available, <tt class="docutils literal"><span class="pre">show_refs</span></tt> will convert the .dot file to a
.png and print its name.</p>
<p><tt class="docutils literal"><span class="pre">output</span></tt> if specified, the GraphViz output will be written to this
file object. <tt class="docutils literal"><span class="pre">output</span></tt> and <tt class="docutils literal"><span class="pre">filename</span></tt> should not both be specified.</p>
<p>Use <tt class="docutils literal"><span class="pre">max_depth</span></tt> and <tt class="docutils literal"><span class="pre">too_many</span></tt> to limit the depth and breadth of the
graph.</p>
<p>Use <tt class="docutils literal"><span class="pre">filter</span></tt> (a predicate) and <tt class="docutils literal"><span class="pre">extra_ignore</span></tt> (a list of object IDs) to
remove undesired objects from the graph.</p>
<p>Use <tt class="docutils literal"><span class="pre">highlight</span></tt> (a predicate) to highlight certain graph nodes in blue.</p>
<p>Use <tt class="docutils literal"><span class="pre">extra_info</span></tt> (a function returning a string) to report extra
information for objects.</p>
<p>Specify <tt class="docutils literal"><span class="pre">refcounts=True</span></tt> if you want to see reference counts.</p>
<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">show_refs</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">show_refs</span><span class="p">([</span><span class="n">obj1</span><span class="p">,</span> <span class="n">obj2</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">show_refs</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">max_depth</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">show_refs</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">filter</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="ow">not</span> <span class="n">inspect</span><span class="o">.</span><span class="n">isclass</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">show_refs</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">highlight</span><span class="o">=</span><span class="n">inspect</span><span class="o">.</span><span class="n">isclass</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">show_refs</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="n">extra_ignore</span><span class="o">=</span><span class="p">[</span><span class="nb">id</span><span class="p">(</span><span class="nb">locals</span><span class="p">())])</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.3: </span>New parameters: <tt class="docutils literal"><span class="pre">filename</span></tt>, <tt class="docutils literal"><span class="pre">extra_info</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.5: </span>Follows references from module objects instead of stopping.
New parameter: <tt class="docutils literal"><span class="pre">refcounts</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>New parameter: <tt class="docutils literal"><span class="pre">shortnames</span></tt>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 2.0: </span>New parameter: <tt class="docutils literal"><span class="pre">output</span></tt>.</p>
</div>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#"><tt class="docutils literal"><span class="pre">objgraph</span></tt></a><ul>
<li><a class="reference internal" href="#statistics">Statistics</a></li>
<li><a class="reference internal" href="#locating-and-filtering-objects">Locating and Filtering Objects</a></li>
<li><a class="reference internal" href="#traversing-and-displaying-object-graphs">Traversing and Displaying Object Graphs</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">Python Object Graphs</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="references.html"
title="next chapter">Too many references</a></p>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="py-modindex.html" title="Python Module Index"
>modules</a></li>
<li class="right" >
<a href="references.html" title="Too many references"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="Python Object Graphs"
>previous</a> |</li>
<li><a href="index.html">home</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2015, Marius Gedminas and contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3.
</div>
</body>
</html>
|