@@ -114,16 +114,6 @@ _PyEvalFrameClearAndPop(PyThreadState *tstate, InterpreterFrame *frame);
114
114
"cannot access free variable '%s' where it is not associated with a" \
115
115
" value in enclosing scope"
116
116
117
- /* Dynamic execution profile */
118
- #ifdef DYNAMIC_EXECUTION_PROFILE
119
- #ifdef DXPAIRS
120
- static long dxpairs [257 ][256 ];
121
- #define dxp dxpairs[256]
122
- #else
123
- static long dxp [256 ];
124
- #endif
125
- #endif
126
-
127
117
#ifndef NDEBUG
128
118
/* Ensure that tstate is valid: sanity check for PyEval_AcquireThread() and
129
119
PyEval_RestoreThread(). Detect if tstate memory was freed. It can happen
@@ -1238,10 +1228,6 @@ eval_frame_handle_pending(PyThreadState *tstate)
1238
1228
faster than the normal "switch" version, depending on the compiler and the
1239
1229
CPU architecture.
1240
1230
1241
- We disable the optimization if DYNAMIC_EXECUTION_PROFILE is defined,
1242
- because it would render the measurements invalid.
1243
-
1244
-
1245
1231
NOTE: care must be taken that the compiler doesn't try to "optimize" the
1246
1232
indirect jumps by sharing them between all opcodes. Such optimizations
1247
1233
can be disabled on gcc by using the -fno-gcse flag (or possibly
@@ -1253,23 +1239,13 @@ eval_frame_handle_pending(PyThreadState *tstate)
1253
1239
* We want to be sure that the compiler knows this before it generates
1254
1240
* the CFG.
1255
1241
*/
1256
- #ifdef LLTRACE
1257
- #define LLTRACE_INSTR () if (lltrace) { lltrace_instruction(frame, opcode, oparg); }
1258
- #else
1259
- #define LLTRACE_INSTR () ((void)0)
1260
- #endif
1261
1242
1262
1243
#ifdef WITH_DTRACE
1263
1244
#define OR_DTRACE_LINE | (PyDTrace_LINE_ENABLED() ? 255 : 0)
1264
1245
#else
1265
1246
#define OR_DTRACE_LINE
1266
1247
#endif
1267
1248
1268
- #ifdef DYNAMIC_EXECUTION_PROFILE
1269
- #undef USE_COMPUTED_GOTOS
1270
- #define USE_COMPUTED_GOTOS 0
1271
- #endif
1272
-
1273
1249
#ifdef HAVE_COMPUTED_GOTOS
1274
1250
#ifndef USE_COMPUTED_GOTOS
1275
1251
#define USE_COMPUTED_GOTOS 1
@@ -1283,7 +1259,14 @@ eval_frame_handle_pending(PyThreadState *tstate)
1283
1259
#endif
1284
1260
1285
1261
#ifdef Py_STATS
1286
- #define INSTRUCTION_START (op ) frame->f_lasti = INSTR_OFFSET(); next_instr++; OPCODE_EXE_INC(op);
1262
+ #define INSTRUCTION_START (op ) \
1263
+ do { \
1264
+ frame->f_lasti = INSTR_OFFSET(); \
1265
+ next_instr++; \
1266
+ OPCODE_EXE_INC(op); \
1267
+ _py_stats.opcode_stats[lastopcode].pair_count[op]++; \
1268
+ lastopcode = op; \
1269
+ } while (0)
1287
1270
#else
1288
1271
#define INSTRUCTION_START (op ) frame->f_lasti = INSTR_OFFSET(); next_instr++
1289
1272
#endif
@@ -1296,34 +1279,12 @@ eval_frame_handle_pending(PyThreadState *tstate)
1296
1279
#define DISPATCH_GOTO () goto dispatch_opcode
1297
1280
#endif
1298
1281
1299
- /* RECORD_DXPROFILE() records the dxprofile information, if enabled. Normally a no-op */
1300
- #ifdef DYNAMIC_EXECUTION_PROFILE
1301
- #ifdef DXPAIRS
1302
- #define RECORD_DXPROFILE () \
1303
- do { \
1304
- dxpairs[lastopcode][opcode]++; \
1305
- lastopcode = opcode; \
1306
- dxp[opcode]++; \
1307
- } while (0)
1308
- #else
1309
- #define RECORD_DXPROFILE () \
1310
- do { \
1311
- dxp[opcode]++; \
1312
- } while (0)
1313
- #endif
1282
+ /* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
1283
+ #ifdef LLTRACE
1284
+ #define PRE_DISPATCH_GOTO () if (lltrace) { lltrace_instruction(frame, opcode, oparg); }
1314
1285
#else
1315
- #define RECORD_DXPROFILE () ((void)0)
1316
- #endif
1317
-
1318
- /* PRE_DISPATCH_GOTO() does lltrace and dxprofile if either is enabled. Normally a no-op */
1319
- #ifndef LLTRACE
1320
- #ifndef DYNAMIC_EXECUTION_PROFILE
1321
1286
#define PRE_DISPATCH_GOTO () ((void)0)
1322
1287
#endif
1323
- #endif
1324
- #ifndef PRE_DISPATCH_GOTO
1325
- #define PRE_DISPATCH_GOTO () do { LLTRACE_INSTR(); RECORD_DXPROFILE(); } while (0)
1326
- #endif
1327
1288
1328
1289
#define NOTRACE_DISPATCH () \
1329
1290
{ \
@@ -1403,7 +1364,7 @@ eval_frame_handle_pending(PyThreadState *tstate)
1403
1364
1404
1365
#define PREDICT_ID (op ) PRED_##op
1405
1366
1406
- #if defined( DYNAMIC_EXECUTION_PROFILE ) || USE_COMPUTED_GOTOS
1367
+ #if USE_COMPUTED_GOTOS
1407
1368
#define PREDICT (op ) if (0) goto PREDICT_ID(op)
1408
1369
#else
1409
1370
#define PREDICT (op ) \
@@ -1653,7 +1614,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
1653
1614
#include "opcode_targets.h"
1654
1615
#endif
1655
1616
1656
- #ifdef DXPAIRS
1617
+ #ifdef Py_STATS
1657
1618
int lastopcode = 0 ;
1658
1619
#endif
1659
1620
int opcode ; /* Current opcode */
@@ -7489,16 +7450,16 @@ format_awaitable_error(PyThreadState *tstate, PyTypeObject *type, int prevprevpr
7489
7450
}
7490
7451
}
7491
7452
7492
- #ifdef DYNAMIC_EXECUTION_PROFILE
7453
+ #ifdef Py_STATS
7493
7454
7494
7455
static PyObject *
7495
- getarray (long a [256 ])
7456
+ getarray (uint64_t a [256 ])
7496
7457
{
7497
7458
int i ;
7498
7459
PyObject * l = PyList_New (256 );
7499
7460
if (l == NULL ) return NULL ;
7500
7461
for (i = 0 ; i < 256 ; i ++ ) {
7501
- PyObject * x = PyLong_FromLong (a [i ]);
7462
+ PyObject * x = PyLong_FromUnsignedLongLong (a [i ]);
7502
7463
if (x == NULL ) {
7503
7464
Py_DECREF (l );
7504
7465
return NULL ;
@@ -7513,22 +7474,18 @@ getarray(long a[256])
7513
7474
PyObject *
7514
7475
_Py_GetDXProfile (PyObject * self , PyObject * args )
7515
7476
{
7516
- #ifndef DXPAIRS
7517
- return getarray (dxp );
7518
- #else
7519
7477
int i ;
7520
7478
PyObject * l = PyList_New (257 );
7521
7479
if (l == NULL ) return NULL ;
7522
7480
for (i = 0 ; i < 257 ; i ++ ) {
7523
- PyObject * x = getarray (dxpairs [i ]);
7481
+ PyObject * x = getarray (_py_stats . opcode_stats [i ]. pair_count );
7524
7482
if (x == NULL ) {
7525
7483
Py_DECREF (l );
7526
7484
return NULL ;
7527
7485
}
7528
7486
PyList_SET_ITEM (l , i , x );
7529
7487
}
7530
7488
return l ;
7531
- #endif
7532
7489
}
7533
7490
7534
7491
#endif
0 commit comments