Skip to content

Commit a4460f2

Browse files
authoredMay 18, 2022
Split refcount stats into 'interpreter' and 'non-interpreter' (GH-92919)
1 parent 3fa0237 commit a4460f2

File tree

6 files changed

+24
-0
lines changed

6 files changed

+24
-0
lines changed
 

‎Include/pystats.h

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ typedef struct _call_stats {
3636
typedef struct _object_stats {
3737
uint64_t increfs;
3838
uint64_t decrefs;
39+
uint64_t interpreter_increfs;
40+
uint64_t interpreter_decrefs;
3941
uint64_t allocations;
4042
uint64_t allocations512;
4143
uint64_t allocations4k;
@@ -60,10 +62,18 @@ PyAPI_DATA(PyStats) _py_stats;
6062

6163
extern void _Py_PrintSpecializationStats(int to_file);
6264

65+
#ifdef _PY_INTERPRETER
66+
67+
#define _Py_INCREF_STAT_INC() _py_stats.object_stats.interpreter_increfs++
68+
#define _Py_DECREF_STAT_INC() _py_stats.object_stats.interpreter_decrefs++
69+
70+
#else
6371

6472
#define _Py_INCREF_STAT_INC() _py_stats.object_stats.increfs++
6573
#define _Py_DECREF_STAT_INC() _py_stats.object_stats.decrefs++
6674

75+
#endif
76+
6777
#else
6878

6979
#define _Py_INCREF_STAT_INC() ((void)0)

‎Objects/genobject.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* Generator object implementation */
22

3+
#define _PY_INTERPRETER
4+
35
#include "Python.h"
46
#include "pycore_call.h" // _PyObject_CallNoArgs()
57
#include "pycore_ceval.h" // _PyEval_EvalFrame()

‎Python/ceval.c

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
XXX document it!
66
*/
77

8+
#define _PY_INTERPRETER
9+
810
#include "Python.h"
911
#include "pycore_abstract.h" // _PyIndex_Check()
1012
#include "pycore_call.h" // _PyObject_FastCallDictTstate()

‎Python/frame.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
#define _PY_INTERPRETER
3+
24
#include "Python.h"
35
#include "frameobject.h"
46
#include "pycore_code.h" // stats

‎Python/specialize.c

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ print_object_stats(FILE *out, ObjectStats *stats)
191191
fprintf(out, "Object allocations over 4 kbytes: %" PRIu64 "\n", stats->allocations_big);
192192
fprintf(out, "Object frees: %" PRIu64 "\n", stats->frees);
193193
fprintf(out, "Object new values: %" PRIu64 "\n", stats->new_values);
194+
fprintf(out, "Object interpreter increfs: %" PRIu64 "\n", stats->interpreter_increfs);
195+
fprintf(out, "Object interpreter decrefs: %" PRIu64 "\n", stats->interpreter_decrefs);
194196
fprintf(out, "Object increfs: %" PRIu64 "\n", stats->increfs);
195197
fprintf(out, "Object decrefs: %" PRIu64 "\n", stats->decrefs);
196198
fprintf(out, "Object materialize dict (on request): %" PRIu64 "\n", stats->dict_materialized_on_request);

‎Tools/scripts/summarize_stats.py

+6
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,19 @@ def emit_object_stats(stats):
272272
with Section("Object stats", summary="allocations, frees and dict materializatons"):
273273
total_materializations = stats.get("Object new values")
274274
total_allocations = stats.get("Object allocations")
275+
total_increfs = stats.get("Object interpreter increfs") + stats.get("Object increfs")
276+
total_decrefs = stats.get("Object interpreter decrefs") + stats.get("Object decrefs")
275277
rows = []
276278
for key, value in stats.items():
277279
if key.startswith("Object"):
278280
if "materialize" in key:
279281
ratio = f"{100*value/total_materializations:0.1f}%"
280282
elif "allocations" in key:
281283
ratio = f"{100*value/total_allocations:0.1f}%"
284+
elif "increfs" in key:
285+
ratio = f"{100*value/total_increfs:0.1f}%"
286+
elif "decrefs" in key:
287+
ratio = f"{100*value/total_decrefs:0.1f}%"
282288
else:
283289
ratio = ""
284290
label = key[6:].strip()

0 commit comments

Comments
 (0)