mirror of
https://github.com/python/cpython
synced 2024-09-05 00:05:39 +00:00
bpo-44890: collect specialization stats if Py_DEBUG (GH-27731)
This commit is contained in:
parent
a530a9538f
commit
8ac0886091
|
@ -301,13 +301,16 @@ int _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *nam
|
||||||
int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
|
int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
|
||||||
int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr);
|
int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr);
|
||||||
|
|
||||||
#define SPECIALIZATION_STATS 0
|
#define PRINT_SPECIALIZATION_STATS 0
|
||||||
#define SPECIALIZATION_STATS_DETAILED 0
|
#define PRINT_SPECIALIZATION_STATS_DETAILED 0
|
||||||
#define SPECIALIZATION_STATS_TO_FILE 0
|
#define PRINT_SPECIALIZATION_STATS_TO_FILE 0
|
||||||
|
|
||||||
|
#define COLLECT_SPECIALIZATION_STATS (Py_DEBUG || PRINT_SPECIALIZATION_STATS)
|
||||||
|
#define COLLECT_SPECIALIZATION_STATS_DETAILED (Py_DEBUG || PRINT_SPECIALIZATION_STATS_DETAILED)
|
||||||
|
|
||||||
#define SPECIALIZATION_FAILURE_KINDS 20
|
#define SPECIALIZATION_FAILURE_KINDS 20
|
||||||
|
|
||||||
#if SPECIALIZATION_STATS
|
#if COLLECT_SPECIALIZATION_STATS
|
||||||
|
|
||||||
typedef struct _stats {
|
typedef struct _stats {
|
||||||
uint64_t specialization_success;
|
uint64_t specialization_success;
|
||||||
|
@ -317,7 +320,7 @@ typedef struct _stats {
|
||||||
uint64_t miss;
|
uint64_t miss;
|
||||||
uint64_t deopt;
|
uint64_t deopt;
|
||||||
uint64_t unquickened;
|
uint64_t unquickened;
|
||||||
#if SPECIALIZATION_STATS_DETAILED
|
#if COLLECT_SPECIALIZATION_STATS_DETAILED
|
||||||
uint64_t specialization_failure_kinds[SPECIALIZATION_FAILURE_KINDS];
|
uint64_t specialization_failure_kinds[SPECIALIZATION_FAILURE_KINDS];
|
||||||
#endif
|
#endif
|
||||||
} SpecializationStats;
|
} SpecializationStats;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Specialization stats are always collected in debug builds.
|
|
@ -85,7 +85,7 @@ static PyObject *
|
||||||
_opcode_get_specialization_stats_impl(PyObject *module)
|
_opcode_get_specialization_stats_impl(PyObject *module)
|
||||||
/*[clinic end generated code: output=fcbc32fdfbec5c17 input=e1f60db68d8ce5f6]*/
|
/*[clinic end generated code: output=fcbc32fdfbec5c17 input=e1f60db68d8ce5f6]*/
|
||||||
{
|
{
|
||||||
#if SPECIALIZATION_STATS
|
#if COLLECT_SPECIALIZATION_STATS
|
||||||
return _Py_GetSpecializationStats();
|
return _Py_GetSpecializationStats();
|
||||||
#else
|
#else
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
|
|
|
@ -341,7 +341,7 @@ PyEval_InitThreads(void)
|
||||||
void
|
void
|
||||||
_PyEval_Fini(void)
|
_PyEval_Fini(void)
|
||||||
{
|
{
|
||||||
#if SPECIALIZATION_STATS
|
#if PRINT_SPECIALIZATION_STATS
|
||||||
_Py_PrintSpecializationStats();
|
_Py_PrintSpecializationStats();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Py_ssize_t _Py_QuickenedCount = 0;
|
Py_ssize_t _Py_QuickenedCount = 0;
|
||||||
#if SPECIALIZATION_STATS
|
#if COLLECT_SPECIALIZATION_STATS
|
||||||
SpecializationStats _specialization_stats[256] = { 0 };
|
SpecializationStats _specialization_stats[256] = { 0 };
|
||||||
|
|
||||||
#define ADD_STAT_TO_DICT(res, field) \
|
#define ADD_STAT_TO_DICT(res, field) \
|
||||||
|
@ -69,7 +69,7 @@ stats_to_dict(SpecializationStats *stats)
|
||||||
ADD_STAT_TO_DICT(res, miss);
|
ADD_STAT_TO_DICT(res, miss);
|
||||||
ADD_STAT_TO_DICT(res, deopt);
|
ADD_STAT_TO_DICT(res, deopt);
|
||||||
ADD_STAT_TO_DICT(res, unquickened);
|
ADD_STAT_TO_DICT(res, unquickened);
|
||||||
#if SPECIALIZATION_STATS_DETAILED
|
#if COLLECT_SPECIALIZATION_STATS_DETAILED
|
||||||
PyObject *failure_kinds = PyTuple_New(SPECIALIZATION_FAILURE_KINDS);
|
PyObject *failure_kinds = PyTuple_New(SPECIALIZATION_FAILURE_KINDS);
|
||||||
if (failure_kinds == NULL) {
|
if (failure_kinds == NULL) {
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
|
@ -111,7 +111,7 @@ add_stat_dict(
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPECIALIZATION_STATS
|
#if COLLECT_SPECIALIZATION_STATS
|
||||||
PyObject*
|
PyObject*
|
||||||
_Py_GetSpecializationStats(void) {
|
_Py_GetSpecializationStats(void) {
|
||||||
PyObject *stats = PyDict_New();
|
PyObject *stats = PyDict_New();
|
||||||
|
@ -144,7 +144,7 @@ print_stats(FILE *out, SpecializationStats *stats, const char *name)
|
||||||
PRINT_STAT(name, miss);
|
PRINT_STAT(name, miss);
|
||||||
PRINT_STAT(name, deopt);
|
PRINT_STAT(name, deopt);
|
||||||
PRINT_STAT(name, unquickened);
|
PRINT_STAT(name, unquickened);
|
||||||
#if SPECIALIZATION_STATS_DETAILED
|
#if PRINT_SPECIALIZATION_STATS_DETAILED
|
||||||
for (int i = 0; i < SPECIALIZATION_FAILURE_KINDS; i++) {
|
for (int i = 0; i < SPECIALIZATION_FAILURE_KINDS; i++) {
|
||||||
fprintf(out, " %s.specialization_failure_kinds[%d] : %" PRIu64 "\n",
|
fprintf(out, " %s.specialization_failure_kinds[%d] : %" PRIu64 "\n",
|
||||||
name, i, stats->specialization_failure_kinds[i]);
|
name, i, stats->specialization_failure_kinds[i]);
|
||||||
|
@ -157,7 +157,7 @@ void
|
||||||
_Py_PrintSpecializationStats(void)
|
_Py_PrintSpecializationStats(void)
|
||||||
{
|
{
|
||||||
FILE *out = stderr;
|
FILE *out = stderr;
|
||||||
#if SPECIALIZATION_STATS_TO_FILE
|
#if PRINT_SPECIALIZATION_STATS_TO_FILE
|
||||||
/* Write to a file instead of stderr. */
|
/* Write to a file instead of stderr. */
|
||||||
# ifdef MS_WINDOWS
|
# ifdef MS_WINDOWS
|
||||||
const char *dirname = "c:\\temp\\py_stats\\";
|
const char *dirname = "c:\\temp\\py_stats\\";
|
||||||
|
@ -182,7 +182,7 @@ _Py_PrintSpecializationStats(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPECIALIZATION_STATS_DETAILED
|
#if COLLECT_SPECIALIZATION_STATS_DETAILED
|
||||||
|
|
||||||
#define SPECIALIZATION_FAIL(opcode, kind) _specialization_stats[opcode].specialization_failure_kinds[kind]++
|
#define SPECIALIZATION_FAIL(opcode, kind) _specialization_stats[opcode].specialization_failure_kinds[kind]++
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue