:
Kind+) -> (
:
(index:
notnegative+):
iterable+) -> IdentitySet:
Any+) -> IdentitySet:
loadablefilenamestring+ or fn:
loadableiterableofstrings+] [use_readline
= boolean+]) -> Stat:
profilefilename+]):
UniSet+]):
UniSet+]):
UniSet+]):
Kind:
IdentitySet:
(
:
( alt:[tc:
typeexceptdict+ or dictof
= typeoremptytuple+]) -> Kind:
(
:
(address:
objectaddress+) -> Kind:
(
:
( draw:[name
= modulename+ , at
= moduleaddress+]) -> Kind:
(
:
() -> KindOfProdFamily:
(path_prefix:
string+) -> Kind:
(scope:
Any+) -> Kind:
(filename:
string+, lineno:
positive+) -> KindOfProdFamily:
(
:
( 0..*: alt:[kind:
ClodoKind+ or sok:
SetOfClodoKind+]) -> KindOfRetClaSetFamily:
RootStateType:
(
:
(size:
notnegative+) -> KindOfSizeFamily:
(
:
(type:
type+) -> KindOfTypeFamily:
(
:
() -> Kind:
(
:
( 0..*:rel:
relationname+) -> KindOfInViaFamily:
anything:
Kind+) -> (
:
(index:
notnegative+)
:
notnegative+For each kind in the sequence, check whether the object is an element of that kind. If it is, the classification is the index of that kind in the sequence. If the end of the sequence is reached, the classification is the length of the sequence.
:
Kind+:
iterable+) -> IdentitySet
:
iterable+:
Any+) -> IdentitySet
:
Any+>>> from guppy import hpy >>> hpy().iso(1, 1, 1.0, [], [], {}) Partition of a set of 5 objects. Total size = 444 bytes. Index Count % Size % Cumulative % Kind (class / dict of class) 0 1 20 248 56 248 56 dict (no owner) 1 2 40 144 32 392 88 list 2 1 20 28 6 420 95 int 3 1 20 24 5 444 100 float >>>
:
loadablefilenamestring+ or fn:
loadableiterableofstrings+] [use_readline
= boolean+]) -> Stat
:
loadablefilenamestring+:
loadableiterableofstrings+use_readline
= boolean+This can be used to get information about the state, in particular the memory usage, of separately running Python processes. It can connect to such processes, and bring up an interactive console in each process in which Python can be used much as it is normally used, while the target process under observation continues to execute as usual, typically under user control in another window. By observing and comparing the content of the heap of the target process at different times it is possible to find problems such as memory leaks, and then investigate the reasons for the alleged misbehaviours. It is sometimes also possible to test a fix in the running target process before updating its source code and restarting it.
The target process needs to be enabled to accept remote monitoring. This is implemented via a thread that tries to connect to a particular socket. This thread can be started in the following way:
import guppy.heapy.RM
It is possible to put that command in the
sitecustomize.py
file of the installation. This may be practical so that all
Python processes can be monitored, but there may be security issues to
consider since any process with access to the monitoring socket can
take over the processes that accept remote monitoring.
A process may disable remote monitoring of itself in the following way:
from guppy.heapy.Remote import off; off()
nicosys [175] solitaire.py & [1] 25928 nicosys [176] python -c "from guppy import hpy;hpy().monitor()" <Monitor> *** Connection 1 opened *** <Monitor> h Documented commands (type help <topic>): ======================================== exit h help int lc q sc <Monitor> lc CID PID ARGV 1 25928 ['/home/nilsson/bin/solitaire.py'] <Monitor> sc 1 Remote connection 1. To return to Monitor, type <Ctrl-C> or .<RETURN> <Annex> h Documented commands (type help <topic>): ======================================== close h help int isolatest q reset stat <Annex> stat Target overview ------------------------------------ target.sys.executable = /usr/local/bin/python target.sys.argv = ['/home/nilsson/bin/solitaire.py'] target.wd = /var/tmp target.pid = 25928 <Annex> int Interactive console. To return to Annex, type '-'. >>> hp.heap() Partition of a set of 21919 objects. Total size = 1558688 bytes. Index Count % Size % Cumulative % Kind (class / dict of class) 0 11467 52 739904 47 739904 47 str ... 9 52 0 27040 2 1436516 92 dict of __main__.Card <62 more rows. Type e.g. '_.more' to view.> >>> . <Monitor> exit
:
profilefilename+])
:
profilefilename+>> from guppy import hpy >> hpy().heap().stat.dump(filename)The dump method appends a sample to the end of the file, containing a summary description of the current heap contents. The sequence of such samples can be browsed in the Profile Browser window.
:
UniSet+])
:
UniSet+:
UniSet+])
:
UniSet+])
:
Kind:
IdentitySet:
(
:
( alt:[tc:
typeexceptdict+ or dictof
= typeoremptytuple+]) -> Kind
:
typeexceptdict+dictof
= typeoremptytuple+:
(
:
(address:
objectaddress+) -> Kind
:
objectaddress+:
(
:
( draw:[name
= modulename+ , at
= moduleaddress+]) -> Kind
name
= modulename+at
= moduleaddress+:
(
:
() -> KindOfProdFamily
:
(path_prefix:
string+) -> Kind
:
string+:
(scope:
Any+) -> Kind
:
Any+:
(filename:
string+, lineno:
positive+) -> KindOfProdFamily
:
string+:
positive+:
(
:
( 0..*: alt:[kind:
ClodoKind+ or sok:
SetOfClodoKind+]) -> KindOfRetClaSetFamily
:
ClodoKind+:
SetOfClodoKind+:
RootStateType:
(
:
(size:
notnegative+) -> KindOfSizeFamily
:
(
:
(type:
type+) -> KindOfTypeFamily
:
type+:
(
:
() -> Kind
:
(
:
( 0..*:rel:
relationname+) -> KindOfInViaFamily
:
relationname+ [expression] |
Indexing of a dict, list, tuple (etc). The expression must be a Python expression that can be evaluated in a local environment. The environment will contain the builtins and a name 'hp' that is bound to the current Use instance. |
---|---|
.attribute |
Getting an attribute from a builtin type or a slot of a slotted type. (I.E. not an attribute that is in a dict of an object.) |
.f_locals["name"] |
A local variable of a frame. |
.f_locals ["name"] |
A variable in a CELL of a frame.
Note the space between f_locals and [
. This is
to distinguish it from ordinary locals, and still
use a syntax that could be used to access those variables directly from Python. |
.keys()[integer] |
A key in a dictionary, at the indicated place in its keys(). |
:
anything>>> hp.doc.heapgives 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]