diff options
author | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2017-02-14 22:48:43 +0100 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2017-02-14 23:31:37 +0100 |
commit | a12c3d3f8ea255dd03bb7e993fa85eb00f47ab29 (patch) | |
tree | 82595e20d3fbbbb568de9178b7645a40fb7b0923 /test/helper_tools/memoryleak.py | |
parent | 04748e6f3f654733afafea3701d4ed03b08b8167 (diff) | |
download | mitmproxy-a12c3d3f8ea255dd03bb7e993fa85eb00f47ab29.tar.gz mitmproxy-a12c3d3f8ea255dd03bb7e993fa85eb00f47ab29.tar.bz2 mitmproxy-a12c3d3f8ea255dd03bb7e993fa85eb00f47ab29.zip |
restructure and move test files
add empty test files to satisfy linter
Diffstat (limited to 'test/helper_tools/memoryleak.py')
-rw-r--r-- | test/helper_tools/memoryleak.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/helper_tools/memoryleak.py b/test/helper_tools/memoryleak.py new file mode 100644 index 00000000..c03230da --- /dev/null +++ b/test/helper_tools/memoryleak.py @@ -0,0 +1,38 @@ +import gc +import threading +from pympler import muppy, refbrowser +from OpenSSL import SSL +# import os +# os.environ["TK_LIBRARY"] = r"C:\Python27\tcl\tcl8.5" +# os.environ["TCL_LIBRARY"] = r"C:\Python27\tcl\tcl8.5" + +# Also noteworthy: guppy, objgraph + +step = 0 +__memory_locals__ = True + + +def str_fun(obj): + if isinstance(obj, dict): + if "__memory_locals__" in obj: + return "(-locals-)" + if "self" in obj and isinstance(obj["self"], refbrowser.InteractiveBrowser): + return "(-browser-)" + return str(id(obj)) + ": " + str(obj)[:100].replace("\r\n", "\\r\\n").replace("\n", "\\n") + + +def request(ctx, flow): + global step, ssl + print("==========") + print("GC: {}".format(gc.collect())) + print("Threads: {}".format(threading.active_count())) + + step += 1 + if step == 1: + all_objects = muppy.get_objects() + ssl = muppy.filter(all_objects, SSL.Connection)[0] + if step == 2: + ib = refbrowser.InteractiveBrowser(ssl, 2, str_fun, repeat=False) + del ssl # do this to unpollute view + ib.main(True) + # print("\r\n".join(str(x)[:100] for x in gc.get_referrers(ssl))) |