Skip to content

Instantly share code, notes, and snippets.

@hartred
Created August 16, 2016 08:49
Show Gist options
  • Save hartred/34e94524ad03684454b7901a72b708df to your computer and use it in GitHub Desktop.
Save hartred/34e94524ad03684454b7901a72b708df to your computer and use it in GitHub Desktop.
custom decorator for writing profiling information to a file
def profile_memory(output):
if isinstance(output, str):
output = open(output, 'w')
def decorator(func):
@profile(stream=output)
@functools.wraps(func)
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return result
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment