The top-level heapprof package¶
-
heapprof.
start
(filebase: str, samplingRate: Optional[Dict[int, float]] = None) → None¶ Start heapprof in profiling (normal) mode.
- Parameters
filebase – The outputs will be written to filebase.{hpm, hpd}, a pair of local files which can later be read using the HeapProfile class. NB that these must be local files for performance reasons.
samplingRate – A dict from byte size to sampling probability. Each byte size is interpreted as the upper bound of the range, and the sampling probability for byte sizes larger than the largest range given is always 1; thus the default value means to profile allocations of 1-127 bytes at 1 in 10,000, to profile allocations of 128-8,191 bytes at 1 in 10, and to profile all allocations of 8,192 bytes or more.
- Raises
TypeError – If samplingRate is not a mapping of the appropriate type.
ValueError – If samplingRate contains repeated entries.
RuntimeError – If the profiler is already running.
-
heapprof.
gatherStats
() → None¶ Start heapprof in stats gathering mode.
When the profiler is stopped, this will print out statistics on the size distribution of memory allocations. This can be useful for choosing sampling rates for profiling.
-
heapprof.
stop
() → None¶ Stop the heap profiler.
NB that if the program exits, this will be implicitly called.
-
heapprof.
isProfiling
() → bool¶ Test if the heap profiler is currently running.
-
heapprof.
read
(filebase: str, timeInterval: float = 60, precision: float = 0.01) → heapprof.reader.Reader¶ Open a reader, and create a digest for it if needed.
- Parameters
filebase – The name of the file to open; the same as the argument passed to start().
- Args which apply only if you’re creating the digest (i.e., opening it for the first time):
- timeInterval: The time interval between successive snapshots to store in the digest,
in seconds.
- precision: At each snapshot, stack traces totalling up to this fraction of total
memory used at that frame may be dropped into the “other stack trace” bucket. This can greatly shrink the size of the digest at no real cost in usefulness. Must be in [0, 1); a value of zero means nothing is dropped.