]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Split refcount stats into 'interpreter' and 'non-interpreter' (GH-92919)
authorMark Shannon <mark@hotpy.org>
Wed, 18 May 2022 13:38:43 +0000 (14:38 +0100)
committerGitHub <noreply@github.com>
Wed, 18 May 2022 13:38:43 +0000 (14:38 +0100)
Include/pystats.h
Objects/genobject.c
Python/ceval.c
Python/frame.c
Python/specialize.c
Tools/scripts/summarize_stats.py

index bc05dd864c63a749af26c0be9bfb0e7eb917cec9..4375614b05e48393f5d1509f23daa3dc1d90e0ff 100644 (file)
@@ -36,6 +36,8 @@ typedef struct _call_stats {
 typedef struct _object_stats {
     uint64_t increfs;
     uint64_t decrefs;
+    uint64_t interpreter_increfs;
+    uint64_t interpreter_decrefs;
     uint64_t allocations;
     uint64_t allocations512;
     uint64_t allocations4k;
@@ -60,10 +62,18 @@ PyAPI_DATA(PyStats) _py_stats;
 
 extern void _Py_PrintSpecializationStats(int to_file);
 
+#ifdef _PY_INTERPRETER
+
+#define _Py_INCREF_STAT_INC() _py_stats.object_stats.interpreter_increfs++
+#define _Py_DECREF_STAT_INC()  _py_stats.object_stats.interpreter_decrefs++
+
+#else
 
 #define _Py_INCREF_STAT_INC() _py_stats.object_stats.increfs++
 #define _Py_DECREF_STAT_INC()  _py_stats.object_stats.decrefs++
 
+#endif
+
 #else
 
 #define _Py_INCREF_STAT_INC() ((void)0)
index b9a0c30c411a00b937700c2bdd1eb5fdbfba1422..a88522abf414c6e2ff2428e2544314b6b711cc6e 100644 (file)
@@ -1,5 +1,7 @@
 /* Generator object implementation */
 
+#define _PY_INTERPRETER
+
 #include "Python.h"
 #include "pycore_call.h"          // _PyObject_CallNoArgs()
 #include "pycore_ceval.h"         // _PyEval_EvalFrame()
index c81d0efff9b9b35ba7aa22346acd557ee2921e59..e4c47498c0cba42f4b17069744e0dcc3503f88c2 100644 (file)
@@ -5,6 +5,8 @@
    XXX document it!
    */
 
+#define _PY_INTERPRETER
+
 #include "Python.h"
 #include "pycore_abstract.h"      // _PyIndex_Check()
 #include "pycore_call.h"          // _PyObject_FastCallDictTstate()
index c2da123a2bbc159bacc806db3dc876d82daea808..3573f54ad63e9ba155d283c10744725a005dee4c 100644 (file)
@@ -1,4 +1,6 @@
 
+#define _PY_INTERPRETER
+
 #include "Python.h"
 #include "frameobject.h"
 #include "pycore_code.h"           // stats
index 6a91389f85610610e1146711bdf7aceed6d47a26..5469285e16c4d0b0dbb1dba564c93ff97b085f34 100644 (file)
@@ -191,6 +191,8 @@ print_object_stats(FILE *out, ObjectStats *stats)
     fprintf(out, "Object allocations over 4 kbytes: %" PRIu64 "\n", stats->allocations_big);
     fprintf(out, "Object frees: %" PRIu64 "\n", stats->frees);
     fprintf(out, "Object new values: %" PRIu64 "\n", stats->new_values);
+    fprintf(out, "Object interpreter increfs: %" PRIu64 "\n", stats->interpreter_increfs);
+    fprintf(out, "Object interpreter decrefs: %" PRIu64 "\n", stats->interpreter_decrefs);
     fprintf(out, "Object increfs: %" PRIu64 "\n", stats->increfs);
     fprintf(out, "Object decrefs: %" PRIu64 "\n", stats->decrefs);
     fprintf(out, "Object materialize dict (on request): %" PRIu64 "\n", stats->dict_materialized_on_request);
index f66fc7b684594f5e4727ebd017748e46d6a4c27c..3d7479f261b4afd86ce3b7876d9f53dc8c26fd10 100644 (file)
@@ -272,6 +272,8 @@ def emit_object_stats(stats):
     with Section("Object stats", summary="allocations, frees and dict materializatons"):
         total_materializations = stats.get("Object new values")
         total_allocations = stats.get("Object allocations")
+        total_increfs = stats.get("Object interpreter increfs") + stats.get("Object increfs")
+        total_decrefs = stats.get("Object interpreter decrefs") + stats.get("Object decrefs")
         rows = []
         for key, value in stats.items():
             if key.startswith("Object"):
@@ -279,6 +281,10 @@ def emit_object_stats(stats):
                     ratio = f"{100*value/total_materializations:0.1f}%"
                 elif "allocations" in key:
                     ratio = f"{100*value/total_allocations:0.1f}%"
+                elif "increfs"     in key:
+                    ratio = f"{100*value/total_increfs:0.1f}%"
+                elif "decrefs"     in key:
+                    ratio = f"{100*value/total_decrefs:0.1f}%"
                 else:
                     ratio = ""
                 label = key[6:].strip()