On 10.05.15 02:25, Ian Cordasco wrote:
Can you share how you gathered them so someone could run them on a
64-bit build?

This is quick and dirty patch. It generates 8 GB log file!

patch --merge -p1 <PyObject_INIT_stat.diff
make -s -j2
./python -Wd -m test.regrtest -w -uall 2>PyObject_INIT.log
python3 PyObject_INIT_stat.py <PyObject_INIT.log >PyObject_INIT.stat

Perhaps compiling with COUNT_ALLOCS will produce similar statistic for types (but without statistics for sizes) and should be much faster.
diff -r f7cc54086cd2 Include/objimpl.h
--- a/Include/objimpl.h	Sat May 09 11:37:23 2015 -0700
+++ b/Include/objimpl.h	Sat May 09 22:05:04 2015 +0300
@@ -137,9 +137,9 @@ PyAPI_FUNC(PyVarObject *) _PyObject_NewV
 /* Macros trading binary compatibility for speed. See also pymem.h.
    Note that these macros expect non-NULL object pointers.*/
 #define PyObject_INIT(op, typeobj) \
-    ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) )
+    ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), fprintf(stderr, "PyObject_INIT %.200s\n", Py_TYPE(op)->tp_name), (op) )
 #define PyObject_INIT_VAR(op, typeobj, size) \
-    ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
+    ( Py_SIZE(op) = (size), Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), fprintf(stderr, "PyObject_INIT_VAR %.200s %zd\n", Py_TYPE(op)->tp_name, Py_SIZE(op)), (op) )
 
 #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
 
import sys, collections

stat1 = collections.Counter()
stat2 = collections.defaultdict(collections.Counter)
for line in sys.stdin:
    if not line.startswith('PyObject_INIT'):
        continue
    try:
        s, t, *r = line.split()
        stat1[t] += 1
        if s == 'PyObject_INIT_VAR':
            stat2[t][int(r[0])] += 1
    except Exception as e:
        print('*** ERROR: %r %r' % (line, e), file=sys.stderr)

total = sum(stat1.values())
acc = 0
print('%-30s %10s %7s %7s' % ('type', 'count', '%', 'acc.%'))
print()
for t, c in stat1.most_common(30):
    acc += c
    print('%-30s %10d %6.2f%% %6.2f%%' % (t, c, 100 * c / total, 100 * acc / total))

for t in sorted(stat2, key=stat1.__getitem__, reverse=True)[:20]:
    c = stat1[t]
    print()
    print('%-30s %10d %6.2f%%' % (t, c, 100 * c / total))
    acc = 0
    for s, c2 in sorted(stat2[t].items()):
        acc += c2
        print('%30d %10d %6.2f%% %6.2f%%' % (s, c2, 100 * c2 / c, 100 * acc / c))
    c2 = c - sum(stat2[t].values())
    if c2:
        print('%30s %10d %6.2f%% %6.2f%%' % ('-', c2, 100 * c2 / c, 100))
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to