utils.debug

Utilities for debugging memory usage, blocking calls, etc.

Module Contents

Functions

_on_blocking(signum,frame)
blockdetection(timeout) Context that raises an exception if process is blocking.
sample_mem() Sample RSS memory usage.
_memdump(samples=10)
memdump(samples=10,file=None) Dump memory statistics.
sample(x,n,k=0) Given a list x a sample of length n of that list is returned.
hfloat(f,p=5) Convert float to value suitable for humans.
humanbytes(s) Convert bytes to human-readable form (e.g., KB, MB).
mem_rss() Return RSS memory usage as a humanized string.
ps() Return the global psutil.Process instance.
_process_memory_info(process)
cry(out=None,sepchr=”=”,seplen=49) Return stack-trace of all active threads.
_on_blocking(signum, frame)
blockdetection(timeout)

Context that raises an exception if process is blocking.

Uses SIGALRM to detect blocking functions.

sample_mem()

Sample RSS memory usage.

Statistics can then be output by calling memdump().

_memdump(samples=10)
memdump(samples=10, file=None)

Dump memory statistics.

Will print a sample of all RSS memory samples added by calling sample_mem(), and in addition print used RSS memory after gc.collect().

sample(x, n, k=0)

Given a list x a sample of length n of that list is returned.

For example, if n is 10, and x has 100 items, a list of every tenth. item is returned.

k can be used as offset.

hfloat(f, p=5)

Convert float to value suitable for humans.

Arguments:
f (float): The floating point number. p (int): Floating point precision (default is 5).
humanbytes(s)

Convert bytes to human-readable form (e.g., KB, MB).

mem_rss()

Return RSS memory usage as a humanized string.

ps()

Return the global psutil.Process instance.

Note:
Returns None if :pypi:`psutil` is not installed.
_process_memory_info(process)
cry(out=None, sepchr="=", seplen=49)

Return stack-trace of all active threads.

See Also:
Taken from https://gist.github.com/737056.