Skip to content

Commit b970dfc

Browse files
committed
Add more stats.
1 parent 6e57707 commit b970dfc

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Include/internal/pycore_code.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,18 @@ int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNI
330330
#if SPECIALIZATION_STATS
331331

332332
typedef struct _specialization_stats {
333-
uint64_t specialization_success;
334-
uint64_t specialization_failure;
333+
uint64_t loadattr_specialization_success;
334+
uint64_t loadattr_specialization_failure;
335335
uint64_t loadattr_hit;
336336
uint64_t loadattr_deferred;
337337
uint64_t loadattr_miss;
338338
uint64_t loadattr_deopt;
339+
uint64_t loadglobal_specialization_success;
340+
uint64_t loadglobal_specialization_failure;
341+
uint64_t loadglobal_hit;
342+
uint64_t loadglobal_deferred;
343+
uint64_t loadglobal_miss;
344+
uint64_t loadglobal_deopt;
339345
} SpecializationStats;
340346

341347
extern SpecializationStats _specialization_stats;

Python/ceval.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
30333033
DISPATCH();
30343034
}
30353035
else {
3036+
STAT_INC(loadglobal_deferred);
30363037
cache->adaptive.counter--;
30373038
oparg = cache->adaptive.original_oparg;
30383039
JUMP_TO_INSTRUCTION(LOAD_GLOBAL);
@@ -3050,6 +3051,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
30503051
PyObject *res = ep->me_value;
30513052
DEOPT_IF(res == NULL, LOAD_ATTR);
30523053
record_cache_hit(cache0);
3054+
STAT_INC(loadglobal_hit);
30533055
Py_INCREF(res);
30543056
PUSH(res);
30553057
DISPATCH();
@@ -3069,6 +3071,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
30693071
PyObject *res = ep->me_value;
30703072
DEOPT_IF(res == NULL, LOAD_ATTR);
30713073
record_cache_hit(cache0);
3074+
STAT_INC(loadglobal_hit);
30723075
Py_INCREF(res);
30733076
PUSH(res);
30743077
DISPATCH();
@@ -4478,9 +4481,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
44784481

44794482
LOAD_GLOBAL_miss:
44804483
{
4484+
STAT_INC(loadglobal_miss);
44814485
_PyAdaptiveEntry *cache = &GET_CACHE()->adaptive;
44824486
record_cache_miss(cache);
44834487
if (too_many_cache_misses(cache)) {
4488+
STAT_INC(loadglobal_deopt);
44844489
next_instr[-1] = _Py_MAKECODEUNIT(LOAD_GLOBAL_ADAPTIVE, _Py_OPARG(next_instr[-1]));
44854490
cache_backoff(cache);
44864491
}

Python/specialize.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ SpecializationStats _specialization_stats = { 0 };
3939
void
4040
_Py_PrintSpecializationStats(void)
4141
{
42-
PRINT_STAT(specialization_success);
43-
PRINT_STAT(specialization_failure);
42+
PRINT_STAT(loadattr_specialization_success);
43+
PRINT_STAT(loadattr_specialization_failure);
4444
PRINT_STAT(loadattr_hit);
4545
PRINT_STAT(loadattr_deferred);
4646
PRINT_STAT(loadattr_miss);
4747
PRINT_STAT(loadattr_deopt);
48+
PRINT_STAT(loadglobal_specialization_success);
49+
PRINT_STAT(loadglobal_specialization_failure);
50+
PRINT_STAT(loadglobal_hit);
51+
PRINT_STAT(loadglobal_deferred);
52+
PRINT_STAT(loadglobal_miss);
53+
PRINT_STAT(loadglobal_deopt);
4854
}
4955

5056
#endif
@@ -359,12 +365,12 @@ _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, Sp
359365
}
360366

361367
fail:
362-
STAT_INC(specialization_failure);
368+
STAT_INC(loadattr_specialization_failure);
363369
assert(!PyErr_Occurred());
364370
cache_backoff(cache0);
365371
return 0;
366372
success:
367-
STAT_INC(specialization_success);
373+
STAT_INC(loadattr_specialization_success);
368374
assert(!PyErr_Occurred());
369375
cache0->counter = saturating_start();
370376
return 0;
@@ -427,10 +433,12 @@ _Py_Specialize_LoadGlobal(
427433
*instr = _Py_MAKECODEUNIT(LOAD_GLOBAL_BUILTIN, _Py_OPARG(*instr));
428434
goto success;
429435
fail:
436+
STAT_INC(loadglobal_specialization_failure);
430437
assert(!PyErr_Occurred());
431438
cache_backoff(cache0);
432439
return 0;
433440
success:
441+
STAT_INC(loadglobal_specialization_success);
434442
assert(!PyErr_Occurred());
435443
cache0->counter = saturating_start();
436444
return 0;

0 commit comments

Comments
 (0)