pyrand.Memory#

class pyrand.Memory#

Measures resident memory size or its change for the Python process.

Notes

Resident Memory:

The resident set size (or RSS) is the occupied memory of the current python process which resides on the RAM. If the memory of the current process overflows onto the disk’s swap space, only the memory residing on RAM is measured by RSS.

How to Use:

Examples

The following example tracks the resident memory acquired during the computation of the log-determinant of a matrix. In particular, the pyrand.Memory.read() in this example reads the difference between the resident memory of the two lines highlighted below.

>>> # Create an object of Memory class
>>> from pyrand import Memory
>>> mem = Memory()

>>> # Create a matrix
>>> from pyrand import toeplitz, logdet
>>> A = toeplitz(2, 1, size=1000, gram=True)

>>> # Start tracking memory change from here
>>> mem.start()

>>> # Compute the log-determinant of the matrix
>>> ld = logdet(A)

>>> # Read acquired memory is acquired from start to this point
>>> mem.read()
(679936, 'b')

>>> # Or, read acquired memory in human-readable format
>>> mem.read(human_readable=True)
(664.0, 'Kb')

The following example shows the current resident memory of the process as is at the current reading on the hardware.

>>> # Load Memory module
>>> from pyrand import Memory

>>> # Get resident memory in bytes
>>> Memory.get_resident_memory()
(92954624, 'b')

>>> # Get resident memory in human-readable format
>>> Memory.get_resident_memory(human_readable=True)
(88.6484375, 'Mb')
Attributes:
ini_mem_useddefault=0

The initial resident memory when pyrand.Memory.start() is called.

memint default=0

The difference between the current resident memory when pyrand.Memory.read() is called and the initial resident memory.

Methods

start()

Sets the start points to track the memory change.

read([human_readable])

Returns the memory used in the current process.

get_resident_memory([human_readable])

Returns the resident memory of the current process.