pythonprofilers / memory_profiler

Monitor Memory usage of Python code
http://pypi.python.org/pypi/memory_profiler
Other
4.39k stars 380 forks source link

Benchmark memory in CI #301

Open danilito19 opened 3 years ago

danilito19 commented 3 years ago

I know memory_profiler is more of a debugging / profiling while in development, but is there thought on adding functionality to help benchmark memory in CI or testing? For example, calling memory_usage or @profile with an arg such as max_mem would stop execution via raising an exception if a specified max memory usage is reached.

I've implemented this for my project by doing something like this

MEM_USAGE_THRESHOLD = 6 # arbitrary

nums = memory_usage((func, (self, *args), kwargs))
initial_mem = nums[0]
max_mem = max(nums)

used_startup_mem = max_mem - initial_mem

if used_startup_mem > MEM_USAGE_THRESHOLD:
    raise Exception(...)