Memory
Module to measure memory.
class Memory
dataclass
#
A timer for measuring the time between two events.
| ATTRIBUTE | DESCRIPTION |
|---|---|
start_vms |
The virtual memory size at the start of the interval.
TYPE:
|
start_rss |
The resident set size at the start of the interval.
TYPE:
|
unit |
The unit of the memory.
TYPE:
|
class Interval
dataclass
#
A class for representing a time interval.
| ATTRIBUTE | DESCRIPTION |
|---|---|
start_vms |
The virtual memory size at the start of the interval.
TYPE:
|
start_rss |
The resident set size at the start of the interval.
TYPE:
|
end_vms |
The virtual memory size at the end of the interval.
TYPE:
|
end_rss |
The resident set size at the end of the interval.
TYPE:
|
unit |
The unit of memory.
TYPE:
|
vms_used: float
prop
#
The amount of vms memory used in the interval.
Warning
This does not track peak memory usage. This will only give the difference between the start and end of the interval.
rss_used: float
prop
#
The amount of rss memory used in the interval.
Warning
This does not track peak memory usage. This will only give the difference between the start and end of the interval.
def to_unit(unit)
#
Return the memory used in a different unit.
| PARAMETER | DESCRIPTION |
|---|---|
unit |
The unit to convert to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Interval
|
The memory used in the new unit. |
Source code in src/amltk/profiling/memory.py
def to_dict(*, prefix='')
#
Convert the time interval to a dictionary.
Source code in src/amltk/profiling/memory.py
class Unit
#
An enum for the units of time.
def from_str(s)
classmethod
#
Convert a string to a unit.
Source code in src/amltk/profiling/memory.py
def from_dict(d)
classmethod
#
Create a memory interval from a dictionary.
| PARAMETER | DESCRIPTION |
|---|---|
d |
The dictionary to create from. |
| RETURNS | DESCRIPTION |
|---|---|
Interval
|
The memory interval. |
Source code in src/amltk/profiling/memory.py
def na()
classmethod
#
Create a memory interval that represents NA.
def convert(x, frm='B', to='B')
classmethod
#
Convert a value from one unit to another.
| PARAMETER | DESCRIPTION |
|---|---|
x |
The value to convert.
TYPE:
|
frm |
The unit of the value.
TYPE:
|
to |
The unit to convert to.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
float
|
The converted value. |
Source code in src/amltk/profiling/memory.py
def measure(unit='B')
classmethod
#
Measure the memory used by a block of code.
| PARAMETER | DESCRIPTION |
|---|---|
unit |
The unit of memory to use. |
| YIELDS | DESCRIPTION |
|---|---|
Interval
|
The Memory Interval. The start and end memory will not be |
Interval
|
valid until the context manager is exited. |
Source code in src/amltk/profiling/memory.py
def start(unit='B')
classmethod
#
Start a memory tracker.
| PARAMETER | DESCRIPTION |
|---|---|
unit |
The unit of memory to use (bytes). |
| RETURNS | DESCRIPTION |
|---|---|
Memory
|
The Memory tracker. |
Source code in src/amltk/profiling/memory.py
def stop()
#
Stop the memory tracker.
| RETURNS | DESCRIPTION |
|---|---|
Interval
|
The memory interval. |
Source code in src/amltk/profiling/memory.py
def usage(kind='vms', unit='B')
classmethod
#
Get the memory used.
| PARAMETER | DESCRIPTION |
|---|---|
kind |
The type of memory to measure.
TYPE:
|
unit |
The unit of memory to use. |
| RETURNS | DESCRIPTION |
|---|---|
float
|
The memory used. |