[pypy-svn] r58680 - in pypy/dist/pypy/translator/tool: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Mon Oct 6 18:37:19 CEST 2008
Author: cfbolz
Date: Mon Oct 6 18:37:18 2008
New Revision: 58680
Modified:
pypy/dist/pypy/translator/tool/staticsizereport.py
pypy/dist/pypy/translator/tool/test/test_staticsizereport.py
Log:
fix some corner cases
Modified: pypy/dist/pypy/translator/tool/staticsizereport.py
==============================================================================
--- pypy/dist/pypy/translator/tool/staticsizereport.py (original)
+++ pypy/dist/pypy/translator/tool/staticsizereport.py Mon Oct 6 18:37:18 2008
@@ -12,23 +12,31 @@
if arrayfld:
length = len(getattr(ptr, arrayfld))
else:
- length = len(ptr)
- return convert_offset_to_int(llmemory.sizeof(TYPE, length))
- return convert_offset_to_int(llmemory.sizeof(TYPE))
+ try:
+ length = len(ptr)
+ except TypeError:
+ print "couldn't find size of", ptr
+ return 0
+ else:
+ length = None
+ return convert_offset_to_int(llmemory.sizeof(TYPE, length))
-def group_static_size_by_lltype(database):
+def by_lltype(obj):
+ return typeOf(obj)
+
+def group_static_size(database, grouper=by_lltype):
totalsize = {}
numobjects = {}
for node in database.globalcontainers():
obj = node.obj
- group = typeOf(obj)
+ group = grouper(obj)
totalsize[group] = totalsize.get(group, 0) + guess_size(obj)
numobjects[group] = numobjects.get(group, 0) + 1
return totalsize, numobjects
-def print_static_size_by_lltype(database):
- totalsize, numobjects = group_static_size_by_lltype(database)
+def print_static_size(database, grouper=by_lltype):
+ totalsize, numobjects = group_static_size(database, grouper)
l = [(size, key) for key, size in totalsize.iteritems()]
l.sort()
l.reverse()
Modified: pypy/dist/pypy/translator/tool/test/test_staticsizereport.py
==============================================================================
--- pypy/dist/pypy/translator/tool/test/test_staticsizereport.py (original)
+++ pypy/dist/pypy/translator/tool/test/test_staticsizereport.py Mon Oct 6 18:37:18 2008
@@ -1,5 +1,5 @@
from pypy.translator.c.test.test_typed import CompilationTestCase
-from pypy.translator.tool.staticsizereport import group_static_size_by_lltype
+from pypy.translator.tool.staticsizereport import group_static_size
class TestStaticSizeReport(CompilationTestCase):
def test_simple(self):
@@ -16,7 +16,7 @@
return a.key
return a.next.key
func = self.getcompiled(f, [int])
- size, num = group_static_size_by_lltype(self.builder.db)
+ size, num = group_static_size(self.builder.db)
for key, value in num.iteritems():
if "staticsizereport.A" in str(key) and "vtable" not in str(key):
assert value == 101
More information about the Pypy-commit
mailing list