From 6645fb5cde1ddef22307372b713d801713244476 Mon Sep 17 00:00:00 2001 From: AlonMenczer Date: Fri, 29 Nov 2024 11:47:06 +0200 Subject: [PATCH 1/4] gh-127389 - fix 'Uops Executed' display in summarize_stats.py --- Tools/scripts/summarize_stats.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py index 5793e5c649d6b3..9ad52bfbf6ac56 100644 --- a/Tools/scripts/summarize_stats.py +++ b/Tools/scripts/summarize_stats.py @@ -45,6 +45,7 @@ TOTAL = "specialization.hit", "specialization.miss", "execution_count" +UOPS_EXECUTED_LABEL = "Uops executed" def pretty(name: str) -> str: @@ -313,7 +314,7 @@ def kind_to_text(kind: int, opcode: str): def is_specializable(self, opcode: str) -> bool: return "specializable" in self._get_stats_for_opcode(opcode) - def get_specialized_total_counts(self) -> tuple[int, int, int]: + def get_specialized_total_counts(self) -> tuple[int, int, int, int]: basic = 0 specialized_hits = 0 specialized_misses = 0 @@ -442,7 +443,7 @@ def get_gc_stats(self) -> list[dict[str, int]]: gc_stats[gen_n][name] = value return gc_stats - def get_optimization_stats(self) -> dict[str, tuple[int, int | None]]: + def get_optimization_stats(self) -> dict[Doc, tuple[int, int | None]]: if "Optimization attempts" not in self._data: return {} @@ -483,7 +484,7 @@ def get_optimization_stats(self) -> dict[str, tuple[int, int | None]]: ): (trace_too_long, attempts), Doc( "Trace too short", - "A potential trace is abandoced because it it too short.", + "A potential trace is abandoned because it it too short.", ): (trace_too_short, attempts), Doc( "Inner loop found", "A trace is truncated because it has an inner loop" @@ -507,7 +508,7 @@ def get_optimization_stats(self) -> dict[str, tuple[int, int | None]]: None, ), Doc( - "Uops executed", + UOPS_EXECUTED_LABEL, "The total number of uops (micro-operations) that were executed", ): ( uops, @@ -515,7 +516,7 @@ def get_optimization_stats(self) -> dict[str, tuple[int, int | None]]: ), } - def get_optimizer_stats(self) -> dict[str, tuple[int, int | None]]: + def get_optimizer_stats(self) -> dict[Doc, tuple[int, int | None]]: attempts = self._data["Optimization optimizer attempts"] successes = self._data["Optimization optimizer successes"] no_memory = self._data["Optimization optimizer failure no memory"] @@ -1140,14 +1141,13 @@ def calc_gc_stats(stats: Stats) -> Rows: def optimization_section() -> Section: def calc_optimization_table(stats: Stats) -> Rows: optimization_stats = stats.get_optimization_stats() - return [ ( - label, + doc, Count(value), - Ratio(value, den, percentage=label != "Uops executed"), + Ratio(value, den, percentage=doc.text != UOPS_EXECUTED_LABEL), ) - for label, (value, den) in optimization_stats.items() + for doc, (value, den) in optimization_stats.items() ] def calc_optimizer_table(stats: Stats) -> Rows: @@ -1264,7 +1264,7 @@ def iter_optimization_tables(base_stats: Stats, head_stats: Stats | None = None) def rare_event_section() -> Section: - def calc_rare_event_table(stats: Stats) -> Table: + def calc_rare_event_table(stats: Stats) -> Rows: DOCS = { "set class": "Setting an object's class, `obj.__class__ = ...`", "set bases": "Setting the bases of a class, `cls.__bases__ = ...`", @@ -1395,7 +1395,7 @@ def to_markdown(x): print("Stats gathered on:", date.today(), file=out) -def output_stats(inputs: list[Path], json_output=str | None): +def output_stats(inputs: list[Path], json_output: str | None): match len(inputs): case 1: data = load_raw_data(Path(inputs[0])) From c336e189b6beee610ec8dff564b2d0219f08a92c Mon Sep 17 00:00:00 2001 From: AlonMenczer Date: Sat, 30 Nov 2024 14:28:54 +0200 Subject: [PATCH 2/4] revert typo fix --- Tools/scripts/summarize_stats.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py index 9ad52bfbf6ac56..2ba08f4d168545 100644 --- a/Tools/scripts/summarize_stats.py +++ b/Tools/scripts/summarize_stats.py @@ -4,27 +4,28 @@ from __future__ import annotations -# NOTE: Bytecode introspection modules (opcode, dis, etc.) should only -# be imported when loading a single dataset. When comparing datasets, it -# could get it wrong, leading to subtle errors. - import argparse import collections -from collections.abc import KeysView -from dataclasses import dataclass -from datetime import date import enum import functools import itertools import json -from operator import itemgetter import os -from pathlib import Path import re import sys import textwrap +from collections.abc import KeysView +from dataclasses import dataclass +from datetime import date +from operator import itemgetter +from pathlib import Path from typing import Any, Callable, TextIO, TypeAlias +# NOTE: Bytecode introspection modules (opcode, dis, etc.) should only +# be imported when loading a single dataset. When comparing datasets, it +# could get it wrong, leading to subtle errors. + + RawData: TypeAlias = dict[str, Any] Rows: TypeAlias = list[tuple] @@ -484,7 +485,7 @@ def get_optimization_stats(self) -> dict[Doc, tuple[int, int | None]]: ): (trace_too_long, attempts), Doc( "Trace too short", - "A potential trace is abandoned because it it too short.", + "A potential trace is abandoced because it it too short.", ): (trace_too_short, attempts), Doc( "Inner loop found", "A trace is truncated because it has an inner loop" From 21b8c83393ca1a7d2a3ba15b546ca7f626692609 Mon Sep 17 00:00:00 2001 From: AlonMenczer Date: Sat, 30 Nov 2024 16:16:14 +0200 Subject: [PATCH 3/4] Revert import formatting --- Tools/scripts/summarize_stats.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py index 2ba08f4d168545..f8c3b9f548f7ab 100644 --- a/Tools/scripts/summarize_stats.py +++ b/Tools/scripts/summarize_stats.py @@ -4,28 +4,27 @@ from __future__ import annotations +# NOTE: Bytecode introspection modules (opcode, dis, etc.) should only +# be imported when loading a single dataset. When comparing datasets, it +# could get it wrong, leading to subtle errors. + import argparse import collections +from collections.abc import KeysView +from dataclasses import dataclass +from datetime import date import enum import functools import itertools import json +from operator import itemgetter import os +from pathlib import Path import re import sys import textwrap -from collections.abc import KeysView -from dataclasses import dataclass -from datetime import date -from operator import itemgetter -from pathlib import Path from typing import Any, Callable, TextIO, TypeAlias -# NOTE: Bytecode introspection modules (opcode, dis, etc.) should only -# be imported when loading a single dataset. When comparing datasets, it -# could get it wrong, leading to subtle errors. - - RawData: TypeAlias = dict[str, Any] Rows: TypeAlias = list[tuple] From de807d2504667bbff703f6d72f9e26fe984e6700 Mon Sep 17 00:00:00 2001 From: AlonMenczer Date: Sat, 30 Nov 2024 17:05:10 +0200 Subject: [PATCH 4/4] Revert unrelated type hint fixes --- Tools/scripts/summarize_stats.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Tools/scripts/summarize_stats.py b/Tools/scripts/summarize_stats.py index f8c3b9f548f7ab..501c848182518f 100644 --- a/Tools/scripts/summarize_stats.py +++ b/Tools/scripts/summarize_stats.py @@ -314,7 +314,7 @@ def kind_to_text(kind: int, opcode: str): def is_specializable(self, opcode: str) -> bool: return "specializable" in self._get_stats_for_opcode(opcode) - def get_specialized_total_counts(self) -> tuple[int, int, int, int]: + def get_specialized_total_counts(self) -> tuple[int, int, int]: basic = 0 specialized_hits = 0 specialized_misses = 0 @@ -516,7 +516,7 @@ def get_optimization_stats(self) -> dict[Doc, tuple[int, int | None]]: ), } - def get_optimizer_stats(self) -> dict[Doc, tuple[int, int | None]]: + def get_optimizer_stats(self) -> dict[str, tuple[int, int | None]]: attempts = self._data["Optimization optimizer attempts"] successes = self._data["Optimization optimizer successes"] no_memory = self._data["Optimization optimizer failure no memory"] @@ -1141,6 +1141,7 @@ def calc_gc_stats(stats: Stats) -> Rows: def optimization_section() -> Section: def calc_optimization_table(stats: Stats) -> Rows: optimization_stats = stats.get_optimization_stats() + return [ ( doc, @@ -1264,7 +1265,7 @@ def iter_optimization_tables(base_stats: Stats, head_stats: Stats | None = None) def rare_event_section() -> Section: - def calc_rare_event_table(stats: Stats) -> Rows: + def calc_rare_event_table(stats: Stats) -> Table: DOCS = { "set class": "Setting an object's class, `obj.__class__ = ...`", "set bases": "Setting the bases of a class, `cls.__bases__ = ...`", @@ -1395,7 +1396,7 @@ def to_markdown(x): print("Stats gathered on:", date.today(), file=out) -def output_stats(inputs: list[Path], json_output: str | None): +def output_stats(inputs: list[Path], json_output=str | None): match len(inputs): case 1: data = load_raw_data(Path(inputs[0]))