Getting started with Heapy

Usage example

The following example shows

  1. How to create the session context: hp=hpy()
  2. How to use the interactive help: hp.doc, hp.doc.doc
  3. How to show the reachable objects in the heap: hp.heap()
  4. How to create and show a set of objects: hp.iso(1,[],{})
  5. How to show the shortest paths from the root to x: hp.iso(x).sp
>>> from guppy import hpy; hp=hpy()
>>> hp
Top level interface to Heapy.
Use eg: hp.doc for more info on hp.
>>> hp.doc
Top level interface to Heapy. Available attributes:
Anything            Rcs                 doc                 load
Clodo               Root                findex              monitor
Id                  Size                heap                pb
Idset               Type                heapu               setref
Module              Unity               idset               test
Nothing             Via                 iso
Use eg: hp.doc.<attribute> for info on <attribute>.
>>> hp.doc.doc
Overview documentation for top level Heapy object.
Provides a listing of the available attributes.
Accessing the attribute name on the doc objects gives further info, eg:

    >>> hp.doc.heap

gives doc for the heap method when hp is the top level Heapy object.

References may be embedded in the documentations. To access a
reference, opening up a web browser with the doc for it one can do eg:

    >>> hp.doc.heap[1]

The reference number 0 is special. If it is provided, it is the
reference to the html doc for the described object itself. So to see
in the web browser the doc for the heap method one can do:

    >>> hp.doc.heap[0]

References
    [0] heapy_Use.html#heapykinds.Use.doc
>>> hp.heap()
Partition of a set of 36671 objects. Total size = 4285591 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0  10234  28   902960  21    902960  21 str
     1   8964  24   727944  17   1630904  38 tuple
     2   2367   6   342184   8   1973088  46 types.CodeType
     3   4723  13   333951   8   2307039  54 bytes
     4    435   1   333064   8   2640103  62 type
     5   2179   6   313776   7   2953879  69 function
     6    435   1   245640   6   3199519  75 dict of type
     7    502   1   193376   5   3392895  79 dict (no owner)
     8     91   0   161352   4   3554247  83 dict of module
     9   1061   3    93368   2   3647615  85 types.WrapperDescriptorType
<133 more rows. Type e.g. '_.more' to view.>
>>> hp.iso(1,[],{})
Partition of a set of 3 objects. Total size = 348 bytes.
 Index  Count   %     Size   % Cumulative  % Kind (class / dict of class)
     0      1  33      248  71       248  71 dict (no owner)
     1      1  33       72  21       320  92 list
     2      1  33       28   8       348 100 int
>>> x=[]
>>> hp.iso(x).sp
 0: hp.Root.i0_modules['__main__'].__dict__['x']
>>> 

Generated by GSL-HTML 3.1.4.post1 on Tue Oct 24 11:59:30 2023