improver.memprofile module

Module containing maximum memory profiling utilities.

memory_monitor(queue, outfile_prefix)[source]

Function to track memory usage, should be run in a separate thread to the main program.

Samples max_rss every 0.1s, if the max_rss is higher than the previous max_rss, then creates a tracemalloc snapshot. There is a performance overhead when using this.

Parameters:
  • queue (Queue) – Active queue instance to communicate with the thread.

  • outfile_prefix (str) – Prefix for the generated output. 2 files will be generated: *_SNAPSHOT and *_MAX_TRACKER.

Return type:

None

memory_profile_decorator(func, outfile_prefix)[source]

A decorator for convenience of running.

Parameters:
  • func (Callable) – function to track the maximum memory of.

  • outfile_prefix (str) – Prefix for the generated output. 2 files will be generated: *_SNAPSHOT and *_MAX_TRACKER.

Return type:

Callable

Returns:

The wrapper

memory_profile_end(queue, thread)[source]

Ends the memory tracking profiler.

Parameters:
  • queue (Queue) – Active queue instance to communicate with active thread.

  • thread (Thread) – Active thread instance running memory tracking.

Return type:

None

memory_profile_start(outfile_prefix)[source]

Starts the memory tracking profiler.

Parameters:

outfile_prefix (str) – Prefix for the generated output. 2 files will be generated: *_SNAPSHOT and *_MAX_TRACKER.

Return type:

Tuple[Thread, Queue]

Returns:

  • Active Thread tracking the memory.

  • Active Queue for communication to the thread.