glearn.Memory#
- class glearn.Memory#
Measures resident memory size or its change for the Python process.
See also
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
glearn.Memory.get_resident_memory()
function. For this, the classglearn.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
glearn.Memory
class. Then call the two functionsglearn.Memory.start()
andglearn.Memory.stop()
of the instantiated object on the two points where the memory difference should be measured. The increase of resident memory between these two points can be read byglearn.Memory.get_mem()
function.
Examples
The following example tracks the resident memory acquired during the computation of the log-determinant of a matrix. In particular, the
glearn.Memory.get_mem()
in this example reads the difference between the resident memory of the two lines highlighted below.>>> # Create an object of Memory class >>> from glearn 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) >>> # Stop tracking memory change from here >>> mem.stop() >>> # Read acquired memory is acquired from start to this point >>> mem.get_mem() (679936, 'b') >>> # Or, read acquired memory in human-readable format >>> mem.get_mem(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 glearn 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
glearn.Memory.start()
is called.- memint default=0
The difference between the current resident memory when
glearn.Memory.stop()
is called and the initial resident memory.
Methods
start
()Sets the start points to track the memory change.
stop
()Stops recording memory change in the current process.
get_mem
([human_readable])Reads recorded memory change of the current process.
get_resident_memory
([human_readable])Returns the resident memory of the current process.