History

perf: net_dropmonitor: Use bisection in symbol lookup

Ben Hutchings committed 13 years ago

Commit 0ce58ba1 parent 326017c1 file · +18 −4Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/net_dropmonitor.py+18−4
@@ -40,10 +40,24 @@ def get_kallsyms_table(): · 39 unmodified lines
4040
4141 def get_sym(sloc):
4242 loc = int(sloc)
43− for symloc, name in kallsyms[::-1]:
44− if loc >= symloc:
45− return (name, loc - symloc)
46− return (None, 0)
43+
44+ # Invariant: kallsyms[i][0] <= loc for all 0 <= i <= start
45+ # kallsyms[i][0] > loc for all end <= i < len(kallsyms)
46+ start, end = -1, len(kallsyms)
47+ while end != start + 1:
48+ pivot = (start + end) // 2
49+ if loc < kallsyms[pivot][0]:
50+ end = pivot
51+ else:
52+ start = pivot
53+
54+ # Now (start == -1 or kallsyms[start][0] <= loc)
55+ # and (start == len(kallsyms) - 1 or loc < kallsyms[start + 1][0])
56+ if start >= 0:
57+ symloc, name = kallsyms[start]
58+ return (name, loc - symloc)
59+ else:
60+ return (None, 0)
4761
4862 def print_drop_table():
4963 print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")