Skip to content

Instantly share code, notes, and snippets.

@tuulos
Created February 2, 2021 05:32
Show Gist options
  • Save tuulos/ba22e18ea51f31fbfb36158f2788255a to your computer and use it in GitHub Desktop.
Save tuulos/ba22e18ea51f31fbfb36158f2788255a to your computer and use it in GitHub Desktop.
Profile memory in Metaflow
from metaflow import FlowSpec, step
from functools import wraps
def profile_memory(f):
@wraps(f)
def func(self):
from memory_profiler import memory_usage
self.mem_usage = memory_usage((f, (self,), {}), timeout=6000000, interval=1)
return func
class ProfileFlow(FlowSpec):
@profile_memory
@step
def start(self):
import time
arr = []
for i in range(5):
arr.append('a' * int((100 * 1024**2)))
time.sleep(1)
self.next(self.end)
@step
def end(self):
print('memory usage over time (in MB):', self.mem_usage)
if __name__ == '__main__':
ProfileFlow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment