teachcompute.memory_peak

get_memory_rss

teachcompute.memory_peak.get_memory_rss(pid: int) int[source][source]

Returns the physical memory used by a process.

Paramètres:

pid – process id, current one is os.getpid()

Renvoie:

physical memory

It relies on the module psutil.

MemorySpy

class teachcompute.memory_peak.MemorySpy(pid: int, delay: float = 0.01, cuda: bool = False)[source][source]

Information about the spy. It class method start. Method stop can be called to end the measure.

Paramètres:
  • pid – process id of the process to spy on

  • delay – spy on every delay seconds

  • cuda – enable cuda monitoring

start() MemorySpy[source][source]

Starts another process and tells it to spy.

stop()[source][source]

Stops spying on.

start_spying_on

teachcompute.memory_peak.start_spying_on(pid: int | None = None, delay: float = 0.01, cuda: bool = False) MemorySpy[source][source]

Starts the memory spy. The function starts another process spying on the one sent as an argument.

Paramètres:
  • pid – process id to spy or the the current one.

  • delay – delay between two measures.

  • cuda – True or False to get memory for cuda devices

Example:

.. code-block:: python

from teachcompute.memory_peak import start_spying_on

p = start_spying_on() # … # code to measure # … stat = p.stop() print(stat)