Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e82287c
Adjust structure of optimization_stats->opcode
JeffersGlass Feb 6, 2024
7f041f0
Output data from uop chains
JeffersGlass Feb 6, 2024
0262ce8
Outputing sequences of UOps as Numbers!
JeffersGlass Feb 6, 2024
cdb7402
Output sequence chains by name
JeffersGlass Feb 6, 2024
eb1dadd
Add missing check for _Py_stats
JeffersGlass Feb 6, 2024
ba7248d
Adjust formatting on sequence output
JeffersGlass Feb 6, 2024
6c2fa8a
Add uop sequence pairs to info
JeffersGlass Feb 7, 2024
6365ba2
Fix multi-length sequence output
JeffersGlass Feb 7, 2024
27cc9fc
Output top 100 sequences of all present lengths
JeffersGlass Feb 7, 2024
45a57b7
Move initialization to check in '_stats_on'
JeffersGlass Feb 7, 2024
f7508e9
Add PYTHONSTATS_UOPDEPTH environment variable
JeffersGlass Feb 8, 2024
9feb04c
Catch up with main
JeffersGlass Feb 8, 2024
3a45127
Catch up with main again
JeffersGlass Feb 8, 2024
58c1854
Formatting cleanup
JeffersGlass Feb 8, 2024
26a1c02
Add docs, ACK
JeffersGlass Feb 8, 2024
b5ee34e
Add docs, ACK
JeffersGlass Feb 8, 2024
2af5cb1
Merge branch 'main' into uop-sequence-count
erlend-aasland Feb 8, 2024
4ee849f
Merge branch 'uop-sequence-count' of https://github.com/jeffersglass/…
JeffersGlass Feb 8, 2024
94c4f19
Address linting errors
JeffersGlass Feb 8, 2024
870a7ce
Minor formatting, table renaming in summarize_stats.py
JeffersGlass Feb 8, 2024
eab5abe
Remove my 'formatting fix' that was causing segfaults
JeffersGlass Feb 8, 2024
09a6555
Implement pair counts
JeffersGlass Feb 12, 2024
094e88f
Format python with Black
JeffersGlass Feb 12, 2024
e27d886
Rework UOP_PAIR_INC to be no-op in non-stats case
JeffersGlass Feb 12, 2024
6ee92ae
Add check for _Py_stats to avoid segfault
JeffersGlass Feb 12, 2024
ba7ba11
Undo some of Black's formatting
JeffersGlass Feb 12, 2024
3e57621
Merge branch 'main' into uop-sequence-count
JeffersGlass Feb 12, 2024
1ce35fd
Track UOp pairs instead of lengthy sequences
JeffersGlass Feb 12, 2024
cbb5f70
Swap lastuop/current uop in counts
JeffersGlass Feb 13, 2024
03db7a5
Catch up with main
JeffersGlass Feb 14, 2024
23e61d3
Adjust formatting to better match PEP 7
JeffersGlass Feb 14, 2024
9c92a0a
Revert "Catch up with main"
JeffersGlass Feb 14, 2024
d623b82
Merge branch 'main' into uop-sequence-count
JeffersGlass Feb 14, 2024
1baf905
Merge branch 'main' into uop-sequence-count
JeffersGlass Feb 15, 2024
0a14173
Address review comments
JeffersGlass Feb 15, 2024
1ce5302
Catch up with main
JeffersGlass Mar 2, 2024
516bab6
Undo spurious changes to prefixes
JeffersGlass Apr 7, 2024
7349474
Add title keyword arg to pair count tables
JeffersGlass Apr 7, 2024
7ba3c93
Catch up with main
JeffersGlass Apr 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Include/cpython/pystats.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct _gc_stats {
typedef struct _uop_stats {
uint64_t execution_count;
uint64_t miss;
uint64_t pair_count[MAX_UOP_ID + 1];
} UOpStats;

#define _Py_UOP_HIST_SIZE 32
Expand Down
8 changes: 8 additions & 0 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ extern int _PyStaticCode_Init(PyCodeObject *co);
#define GC_STAT_ADD(gen, name, n) do { if (_Py_stats) _Py_stats->gc_stats[(gen)].name += (n); } while (0)
#define OPT_STAT_INC(name) do { if (_Py_stats) _Py_stats->optimization_stats.name++; } while (0)
#define UOP_STAT_INC(opname, name) do { if (_Py_stats) { assert(opname < 512); _Py_stats->optimization_stats.opcode[opname].name++; } } while (0)
#define UOP_PAIR_INC(uopcode, lastuop) \
do { \
if (lastuop && _Py_stats) { \
_Py_stats->optimization_stats.opcode[lastuop].pair_count[uopcode]++; \
} \
lastuop = uopcode; \
} while (0)
#define OPT_UNSUPPORTED_OPCODE(opname) do { if (_Py_stats) _Py_stats->optimization_stats.unsupported_opcode[opname]++; } while (0)
#define OPT_ERROR_IN_OPCODE(opname) do { if (_Py_stats) _Py_stats->optimization_stats.error_in_opcode[opname]++; } while (0)
#define OPT_HIST(length, name) \
Expand Down Expand Up @@ -337,6 +344,7 @@ PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
#define GC_STAT_ADD(gen, name, n) ((void)0)
#define OPT_STAT_INC(name) ((void)0)
#define UOP_STAT_INC(opname, name) ((void)0)
#define UOP_PAIR_INC(uopcode, lastuop) ((void)0)
#define OPT_UNSUPPORTED_OPCODE(opname) ((void)0)
#define OPT_ERROR_IN_OPCODE(opname) ((void)0)
#define OPT_HIST(length, name) ((void)0)
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ Neil Girdhar
Matt Giuca
Andrea Giudiceandrea
Franz Glasner
Jeff Glass
Wim Glenn
Michael Goderbauer
Karan Goel
Expand Down
2 changes: 2 additions & 0 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
; // dummy statement after a label, before a declaration
uint16_t uopcode;
#ifdef Py_STATS
int lastuop = 0;
uint64_t trace_uop_execution_counter = 0;
#endif

Expand All @@ -1018,6 +1019,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
next_uop++;
OPT_STAT_INC(uops_executed);
UOP_STAT_INC(uopcode, execution_count);
UOP_PAIR_INC(uopcode, lastuop);
#ifdef Py_STATS
trace_uop_execution_counter++;
#endif
Expand Down
9 changes: 9 additions & 0 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "pycore_object.h"
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
#include "pycore_uop_metadata.h" // _PyOpcode_uop_name
#include "pycore_uop_ids.h" // MAX_UOP_ID
#include "pycore_opcode_utils.h" // RESUME_AT_FUNC_START
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
#include "pycore_runtime.h" // _Py_ID()
Expand Down Expand Up @@ -269,6 +270,14 @@ print_optimization_stats(FILE *out, OptimizationStats *stats)
}
}

for (int i = 1; i <= MAX_UOP_ID; i++){
for (int j = 1; j <= MAX_UOP_ID; j++) {
if (stats->opcode[i].pair_count[j]) {
fprintf(out, "uop[%s].pair_count[%s] : %" PRIu64 "\n",
_PyOpcode_uop_name[i], _PyOpcode_uop_name[j], stats->opcode[i].pair_count[j]);
}
}
}
for (int i = 0; i < MAX_UOP_ID; i++) {
if (stats->error_in_opcode[i]) {
fprintf(
Expand Down
9 changes: 5 additions & 4 deletions Tools/scripts/summarize_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,9 +736,9 @@ def execution_count_section() -> Section:
)


def pair_count_section() -> Section:
def pair_count_section(prefix: str, title=None) -> Section:
def calc_pair_count_table(stats: Stats) -> Rows:
opcode_stats = stats.get_opcode_stats("opcode")
opcode_stats = stats.get_opcode_stats(prefix)
pair_counts = opcode_stats.get_pair_counts()
total = opcode_stats.get_total_execution_count()

Expand All @@ -760,7 +760,7 @@ def calc_pair_count_table(stats: Stats) -> Rows:

return Section(
"Pair counts",
"Pair counts for top 100 Tier 1 instructions",
f"Pair counts for top 100 {title if title else prefix} pairs",
[
Table(
("Pair", "Count:", "Self:", "Cumulative:"),
Expand Down Expand Up @@ -1232,6 +1232,7 @@ def iter_optimization_tables(base_stats: Stats, head_stats: Stats | None = None)
)
],
)
yield pair_count_section(prefix="uop", title="Non-JIT uop")
yield Section(
"Unsupported opcodes",
"",
Expand Down Expand Up @@ -1292,7 +1293,7 @@ def calc_rows(stats: Stats) -> Rows:

LAYOUT = [
execution_count_section(),
pair_count_section(),
pair_count_section("opcode"),
pre_succ_pairs_section(),
specialization_section(),
specialization_effectiveness_section(),
Expand Down