Skip to content

Commit

Permalink
toplev: Some mypy improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Andi Kleen committed Nov 20, 2023
1 parent b8a7363 commit f80abc3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
28 changes: 14 additions & 14 deletions tl_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,6 @@ def force_cpu(self, known_cpus):
print("Unknown FORCECPU ",force)
return True

def force_counters(self):
cnt = self.env.forcecounters
if cnt:
cntn = int(cnt)
if self.realcpu == "adl":
self.counters = {
"cpu_core": cntn,
"cpu_atom": cntn,
"cpu": cntn } # type: None | Dict[str,int]
else:
self.counters = { "cpu": cntn }

def force_ht(self):
ht = self.env.forceht
if ht:
Expand All @@ -118,8 +106,8 @@ def __init__(self, known_cpus=(), nocheck=False, env=Env()):
self.threads = 0
forced_cpu = self.force_cpu(known_cpus)
forced_ht = self.force_ht()
cores = Counter()
sockets = Counter()
cores = Counter() # type: Counter[tuple[int,int]]
sockets = Counter() # type: Counter[int]
self.coreids = defaultdict(list)
self.cputocore = {}
self.cputothread = {}
Expand Down Expand Up @@ -244,3 +232,15 @@ def __init__(self, known_cpus=(), nocheck=False, env=Env()):
self.modelid = modelid_map[mid]
self.true_name = self.modelid.lower()
# XXX match steppings here too

def force_counters(self):
cnt = self.env.forcecounters
if cnt:
cntn = int(cnt)
if self.realcpu == "adl":
self.counters = {
"cpu_core": cntn,
"cpu_atom": cntn,
"cpu": cntn } # type: None | Dict[str,int]
else:
self.counters = { "cpu": cntn }
22 changes: 12 additions & 10 deletions toplev.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
)

eventlist_alias = {
}
} # type: Dict[str,str]

tsx_cpus = ("hsw", "hsx", "bdw", "skl", "skx", "clx", "icl", "icx",
"spr", "sprmax")
Expand All @@ -102,7 +102,7 @@

non_json_events = set(("dummy", "duration_time"))

tma_mgroups = set()
tma_mgroups = set() # type: Set[str]

# tunables (tunable with --tune)

Expand Down Expand Up @@ -1466,7 +1466,7 @@ def setup_perf(evstr, rest):
class Stat(object):
def __init__(self):
self.total = 0
self.errors = Counter()
self.errors = Counter() # type: Counter[str]

def print_not(a, count, msg, j):
print(("%s %s %s %.2f%% in %d measurements"
Expand Down Expand Up @@ -1959,6 +1959,7 @@ def execute_no_multiplex(runner_list, out, rest, summary):
print("RUN #%d of %d%s: %s" % (n + 1, num_runs,
" for %s" % runner_name(runner) if len(runner_list) > 1 else "",
" ".join([quote(o.name) for o in gg.objl])))
# becomes results for first iteration
lresults = results if n == 0 else []
res = None
events = outg + [g]
Expand Down Expand Up @@ -2173,7 +2174,7 @@ def do_execute(rlist, summary, evstr, flat_rmap, out, rest, resoff, revnum):
rev = defaultdict(list)
valstats = defaultdict(list) # type: defaultdict[str,List[ValStat]]
env = {}
account = defaultdict(Stat)
account = defaultdict(Stat) # type: defaultdict[str,Stat]
inf, prun = setup_perf(evstr, rest)
prev_interval = 0.0
interval = None
Expand Down Expand Up @@ -2363,6 +2364,7 @@ def uncore_event(event):
dup_val(cpu.sockettocpus[socket])
elif re.match(r'(S\d+-)?(D\d+-)?C\d+', title) and (smt_mode or args.no_aggr):
m = re.match(r'(?:S(\d+)-)?(?:D(\d+)-)?C(\d+)', title)
assert m is not None
if m.group(2): # XXX
warn_once("die topology not supported currently")
socket, core = int(m.group(1)), int(m.group(3))
Expand Down Expand Up @@ -2851,7 +2853,7 @@ class Summary(object):
def __init__(self):
self.res = defaultdict(list)
self.rev = defaultdict(list)
self.env = Counter()
self.env = Counter() # type: Counter[str]
self.valstats = defaultdict(list)
self.summary_perf = OrderedDict()

Expand Down Expand Up @@ -3345,7 +3347,7 @@ def filter_nodes(self):
parents += get_parents(s)

self.sibmatch = set() # type: Set[Any]
mgroups = set()
mgroups = set() # type: Set[str]

def want_node(obj, mgroups, tma_mgroups):
area = safe_ref(obj, 'area')
Expand Down Expand Up @@ -3416,10 +3418,10 @@ def collect(self):
bad_nodes = set()
bad_events = set()
unsup_nodes = set()
errata_nodes = set()
errata_warn_nodes = set()
errata_names = set()
errata_warn_names = set()
errata_nodes = set() # type: Set[Any]
errata_warn_nodes = set() # type: Set[Any]
errata_names = set() # type: Set[str]
errata_warn_names = set() # type: Set[str]
min_kernel = []
for obj in self.olist:
obj.evlevels = []
Expand Down

0 comments on commit f80abc3

Please sign in to comment.