imate.Memory#

class imate.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:

  • To measure the resident memory in the current Python process, call imate.Memory.get_resident_memory() function. For this, the class imate.Memory() does not needed to be instantiated.

  • To measure the acquired memory between two points of the code (that is, finding the difference of the resident memory), first instantiate the imate.Memory class. Then call the two functions imate.Memory.start() and imate.Memory.read() of the instantiated object on the two points where the memory difference should be measured.

Examples

The following example tracks the resident memory acquired during the computation of the log-determinant of a matrix. In particular, the imate.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 imate import Memory
>>> mem = Memory()

>>> # Create a matrix
>>> from imate 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 imate 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 imate.Memory.start() is called.

memint default=0

The difference between the current resident memory when imate.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.