Neil Horman | 63e0372 | 2011-07-04 13:40:17 -0400 | [diff] [blame] | 1 | # Monitor the system for dropped packets and proudce a report of drop locations and counts |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | |
| 6 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ |
| 7 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') |
| 8 | |
| 9 | from perf_trace_context import * |
| 10 | from Core import * |
| 11 | from Util import * |
| 12 | |
| 13 | drop_log = {} |
| 14 | kallsyms = [] |
| 15 | |
| 16 | def get_kallsyms_table(): |
| 17 | global kallsyms |
| 18 | try: |
| 19 | f = open("/proc/kallsyms", "r") |
| 20 | linecount = 0 |
| 21 | for line in f: |
| 22 | linecount = linecount+1 |
| 23 | f.seek(0) |
| 24 | except: |
| 25 | return |
| 26 | |
| 27 | |
| 28 | j = 0 |
| 29 | for line in f: |
| 30 | loc = int(line.split()[0], 16) |
| 31 | name = line.split()[2] |
| 32 | j = j +1 |
| 33 | if ((j % 100) == 0): |
| 34 | print "\r" + str(j) + "/" + str(linecount), |
Ben Hutchings | 326017c | 2013-05-20 14:45:34 +0000 | [diff] [blame] | 35 | kallsyms.append((loc, name)) |
Neil Horman | 63e0372 | 2011-07-04 13:40:17 -0400 | [diff] [blame] | 36 | |
| 37 | print "\r" + str(j) + "/" + str(linecount) |
| 38 | kallsyms.sort() |
| 39 | return |
| 40 | |
| 41 | def get_sym(sloc): |
| 42 | loc = int(sloc) |
Ben Hutchings | 0ce58ba | 2013-05-20 14:45:42 +0000 | [diff] [blame^] | 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) |
Neil Horman | 63e0372 | 2011-07-04 13:40:17 -0400 | [diff] [blame] | 61 | |
| 62 | def print_drop_table(): |
| 63 | print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT") |
| 64 | for i in drop_log.keys(): |
| 65 | (sym, off) = get_sym(i) |
| 66 | if sym == None: |
| 67 | sym = i |
| 68 | print "%25s %25s %25s" % (sym, off, drop_log[i]) |
| 69 | |
| 70 | |
| 71 | def trace_begin(): |
| 72 | print "Starting trace (Ctrl-C to dump results)" |
| 73 | |
| 74 | def trace_end(): |
| 75 | print "Gathering kallsyms data" |
| 76 | get_kallsyms_table() |
| 77 | print_drop_table() |
| 78 | |
| 79 | # called from perf, when it finds a correspoinding event |
| 80 | def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, |
Ben Hutchings | 140c3c6 | 2013-05-20 14:44:43 +0000 | [diff] [blame] | 81 | skbaddr, location, protocol): |
Neil Horman | 63e0372 | 2011-07-04 13:40:17 -0400 | [diff] [blame] | 82 | slocation = str(location) |
| 83 | try: |
| 84 | drop_log[slocation] = drop_log[slocation] + 1 |
| 85 | except: |
| 86 | drop_log[slocation] = 1 |