Skip to content

Instantly share code, notes, and snippets.

@leifj
Created July 16, 2020 10:54
Show Gist options
  • Select an option

  • Save leifj/828ba0887d0660466bf7683ac8d97a9d to your computer and use it in GitHub Desktop.

Select an option

Save leifj/828ba0887d0660466bf7683ac8d97a9d to your computer and use it in GitHub Desktop.
def heapy(trace=False):
def decorating(func):
def new_func(*args, **kwargs):
from gc import collect
collect()
from guppy import hpy
hp = hpy()
before = hp.heap()
r = func(*args, **kwargs)
after = hp.heap()
leftover = after - before
print("-----------------------------")
print(args)
print(kwargs)
print(leftover)
print("+++++++++++++++++++++++++++++")
if trace:
import pdb
pdb.set_trace()
return r
return new_func
return decorating
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment