From fcf5b8b5a0db92e27c04de8c3dc1715cb7e66454 Mon Sep 17 00:00:00 2001 From: Philip Jenvey Date: Wed, 1 Mar 2017 10:41:10 -0800 Subject: [PATCH] feat: also include pypyjit's get_stats_asmmemmgr issue #802 --- autopush/memusage.py | 25 ++++++++++++++++++++++++- autopush/tests/test_integration.py | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/autopush/memusage.py b/autopush/memusage.py index 1c21752f..9a187ef4 100644 --- a/autopush/memusage.py +++ b/autopush/memusage.py @@ -30,6 +30,7 @@ def trap_err(func, *args, **kwargs): stderr=subprocess.STDOUT) buf.writelines([pmap, '\n\n']) trap_err(dump_rpy_heap, buf) + trap_err(get_stats_asmmemmgr, buf) return buf.getvalue() @@ -41,9 +42,31 @@ def dump_rpy_heap(stream): # pragma: nocover with tempfile.NamedTemporaryFile('wb') as fp: gc._dump_rpy_heap(fp.fileno()) - stream.write("{} size: {}\n".format(fp.name, os.stat(fp.name).st_size)) + try: + fpsize = os.stat(fp.name).st_size + except OSError: + pass + else: + stream.write("{} size: {}\n".format(fp.name, fpsize)) stat = Stat() stat.summarize(fp.name, stream=None) stat.load_typeids(zlib.decompress(gc.get_typeids_z()).split("\n")) stream.write('\n\n') stat.print_summary(stream) + + +def get_stats_asmmemmgr(stream): # pragma: nocover + """Write PyPy's get_stats_asmmemmgr to the specified stream + + (The raw memory currently used by the JIT backend) + + """ + try: + import pypyjit + except ImportError: + # not PyPy or no jit? + return + + stream.write('\n\nget_stats_asmmemmgr: ') + stream.write(repr(pypyjit.get_stats_asmmemmgr())) + stream.write('\n') diff --git a/autopush/tests/test_integration.py b/autopush/tests/test_integration.py index 7a7874c2..047aa79a 100644 --- a/autopush/tests/test_integration.py +++ b/autopush/tests/test_integration.py @@ -2125,6 +2125,7 @@ def test_memusage(self): if hasattr(sys, 'pypy_version_info'): # pragma: nocover ok_('size: ' in body) ok_('rpy_unicode' in body) + ok_('get_stats_asmmemmgr: (' in body) @inlineCallbacks