Last active
April 18, 2018 20:33
-
-
Save nfisher/3b2ff6f0467343c507e666ec8a0ad582 to your computer and use it in GitHub Desktop.
Python: sampling for top referrers to a type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def teardown(self): | |
# other stuff... | |
gc.collect() | |
parents = {} | |
for o in gc.get_objects(): | |
if not isinstance(o, list): | |
continue | |
c = c + 1 | |
if c % 1000 == 0: | |
print("c", c) | |
p = random.randint(1, 10) | |
if p != 1: | |
continue | |
for p in gc.get_referrers(o): | |
t = str(type(p)) | |
parents[t] = parents.get(t, 0) + 1 | |
import operator | |
off = sorted(parents.items(), key=operator.itemgetter(1), reverse=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment