Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -40,10 +40,24 @@ def get_kallsyms_table(): · 39 unmodified lines | ||
| 40 | 40 | |
| 41 | 41 | def get_sym(sloc): |
| 42 | 42 | 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) | |
| 47 | 61 | |
| 48 | 62 | def print_drop_table(): |
| 49 | 63 | print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT") |