Skip to content

Commit

Permalink
Revert "toplev: Use isdecimal"
Browse files Browse the repository at this point in the history
This reverts commit 2d2fcf5.

Breaks python2
  • Loading branch information
Andi Kleen committed Nov 12, 2024
1 parent 998aef2 commit 5227d83
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions toplev.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ def initialize_event(name, i, e):
if e.counter.startswith("Fixed"):
ectx.limited_counters[i] = int(e.counter.split()[2]) + FIXED_BASE
ectx.fixed_events.add(i)
elif e.counter.isdecimal() and int(e.counter) >= 32:
elif is_number(e.counter) and int(e.counter) >= 32:
ectx.limited_counters[i] = int(e.counter) - 32 + FIXED_BASE
ectx.fixed_events.add(i)
else:
Expand Down Expand Up @@ -1609,6 +1609,9 @@ def is_event(l, n):
# use static string to make regexpr caching work
return re.match(valid_events.string, l[n], re.I)

def is_number(n):
return re.match(r'\d+$', n) is not None

def set_interval(env, d, interval):
env['interval-ns'] = d * 1e9
env['interval-ms'] = d * 1e3
Expand Down Expand Up @@ -1751,7 +1754,7 @@ def print_keys(runner, res, rev, valstats, out, interval, env, mode, runner_list
nothing = set() # type: Set[str]
allowed_threads = runner.cpu_list
def filtered(j):
return j != "" and j.isdecimal() and int(j) not in allowed_threads
return j != "" and is_number(j) and int(j) not in allowed_threads
core_node = lambda obj: safe_ref(obj, 'domain') in runner.ectx.core_domains
thread_node = lambda obj: not (core_node(obj) or package_node(obj))

Expand Down Expand Up @@ -1902,7 +1905,7 @@ def filtered(j):
for j in keys:
if j == "":
continue
if j.isdecimal():
if is_number(j):
if filtered(j):
continue
p_id = cpu.cputosocket[int(j)]
Expand Down Expand Up @@ -1994,7 +1997,7 @@ def print_summary(summary, out, runner_list, full_system):
l.append("0") # XXX
if r is None:
continue
if title.isdecimal():
if is_number(title):
cpunum = int(title)
if (r[2].startswith("uncore") or r[2].startswith("power")) and (
cpunum != cpu.sockettocpus[cpu.cputosocket[cpunum]][0]):
Expand Down Expand Up @@ -2242,7 +2245,7 @@ def check_event(rlist, event, off, title, prev_interval, l, revnum, linenum, las
print("event wrong pmu", event, title, r.pmu)
return None, FINE, event
# cannot check because it's an event that needs to be expanded first
if not event.startswith("cpu") and title.isdecimal() and int(title) not in r.cpu_list:
if not event.startswith("cpu") and is_number(title) and int(title) not in r.cpu_list:
return r, FINE, event
if revnum is None:
revnum = r.sched.evnum
Expand Down Expand Up @@ -2495,7 +2498,7 @@ def ignored_cpu(num):
[k in runner.cpu_list for k in cpu.coreids[cpu.cputocore[num]]]))

def add(t):
if runner.cpu_list and t.isdecimal() and ignored_cpu(int(t)):
if runner.cpu_list and is_number(t) and ignored_cpu(int(t)):
return

if skip:
Expand All @@ -2522,7 +2525,7 @@ def uncore_event(event):

# power/uncore events are only output once for every socket
if ((uncore_event(event) or uncore_event(origevent)) and
title.isdecimal() and
is_number(title) and
(not ((args.core or args.cpu) and not args.single_thread))):
cpunum = int(title)
socket = cpu.cputosocket[cpunum]
Expand All @@ -2537,7 +2540,7 @@ def uncore_event(event):
# duration time is only output once, except with --cpu/-C (???)
# except perf 6.2+ outputs it with -A on all cpus, but not counting except the first
elif ((event.startswith("duration_time") or origevent.startswith("duration_time"))
and title.isdecimal() and not args.cpu and not args.core):
and is_number(title) and not args.cpu and not args.core):
dup_val(runner.cpu_list)
else:
add(title)
Expand Down

0 comments on commit 5227d83

Please sign in to comment.