Author: Armin Rigo <[email protected]>
Branch: sys-getsizeof
Changeset: r87176:29bf9d9c7bbf
Date: 2016-09-17 09:33 +0200
http://bitbucket.org/pypy/pypy/changeset/29bf9d9c7bbf/
Log: A branch to "implement" sys.getsizeof(), or at least give some
number.
Add rgc.getsizeof().
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -583,6 +583,12 @@
resulttype=lltype.Void)
+def getsizeof(instance):
+ """Get the size of an object as seen by the GC.
+ Only includes this object, not anything else it depends on!
+ """
+ return get_rpy_memory_usage(cast_instance_to_gcref(instance))
+
def get_rpy_memory_usage(gcref):
"NOT_RPYTHON"
# approximate implementation using CPython's type info
diff --git a/rpython/rlib/test/test_rgc.py b/rpython/rlib/test/test_rgc.py
--- a/rpython/rlib/test/test_rgc.py
+++ b/rpython/rlib/test/test_rgc.py
@@ -239,6 +239,7 @@
x1 = X()
n = rgc.get_rpy_memory_usage(rgc.cast_instance_to_gcref(x1))
assert n >= 8 and n <= 64
+ assert n == rgc.getsizeof(x1)
def test_register_custom_trace_hook():
TP = lltype.GcStruct('X')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit