Get resource usage of process

AUTHORS:

  • William Stein (2006-03-04): initial version

  • Jeroen Demeyer (2016-11-14): implement as thin wrapper over psutil package

sage.misc.getusage.get_memory_usage(t=None)

Return the memory usage of the current process in megabytes.

INPUT:

  • t – a float (default: None); output of an earlier call. If this is given, return the current usage minus \(t\).

OUTPUT: a float representing the number of megabytes used.

EXAMPLES:

sage: t = get_memory_usage(); t  # random
873.98046875
sage: type(t)
<... 'float'>
sage.misc.getusage.virtual_memory_limit()

Return the upper limit for virtual memory usage.

This is the value set by ulimit -v at the command line or a practical limit if no limit is set. In any case, the value is bounded by sys.maxsize.

OUTPUT:

Integer. The virtual memory limit in bytes.

EXAMPLES:

sage: from sage.misc.getusage import virtual_memory_limit
sage: virtual_memory_limit() > 0
True
sage: virtual_memory_limit() <= sys.maxsize
True