Loading...
1# Monitor the system for dropped packets and proudce a report of drop locations and counts
2# SPDX-License-Identifier: GPL-2.0
3
4from __future__ import print_function
5
6import os
7import sys
8
9sys.path.append(os.environ['PERF_EXEC_PATH'] + \
10 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
11
12from perf_trace_context import *
13from Core import *
14from Util import *
15
16drop_log = {}
17kallsyms = []
18
19def get_kallsyms_table():
20 global kallsyms
21
22 try:
23 f = open("/proc/kallsyms", "r")
24 except:
25 return
26
27 for line in f:
28 loc = int(line.split()[0], 16)
29 name = line.split()[2]
30 kallsyms.append((loc, name))
31 kallsyms.sort()
32
33def get_sym(sloc):
34 loc = int(sloc)
35
36 # Invariant: kallsyms[i][0] <= loc for all 0 <= i <= start
37 # kallsyms[i][0] > loc for all end <= i < len(kallsyms)
38 start, end = -1, len(kallsyms)
39 while end != start + 1:
40 pivot = (start + end) // 2
41 if loc < kallsyms[pivot][0]:
42 end = pivot
43 else:
44 start = pivot
45
46 # Now (start == -1 or kallsyms[start][0] <= loc)
47 # and (start == len(kallsyms) - 1 or loc < kallsyms[start + 1][0])
48 if start >= 0:
49 symloc, name = kallsyms[start]
50 return (name, loc - symloc)
51 else:
52 return (None, 0)
53
54def print_drop_table():
55 print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT"))
56 for i in drop_log.keys():
57 (sym, off) = get_sym(i)
58 if sym == None:
59 sym = i
60 print("%25s %25s %25s" % (sym, off, drop_log[i]))
61
62
63def trace_begin():
64 print("Starting trace (Ctrl-C to dump results)")
65
66def trace_end():
67 print("Gathering kallsyms data")
68 get_kallsyms_table()
69 print_drop_table()
70
71# called from perf, when it finds a correspoinding event
72def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, callchain,
73 skbaddr, location, protocol):
74 slocation = str(location)
75 try:
76 drop_log[slocation] = drop_log[slocation] + 1
77 except:
78 drop_log[slocation] = 1
1# Monitor the system for dropped packets and proudce a report of drop locations and counts
2
3import os
4import sys
5
6sys.path.append(os.environ['PERF_EXEC_PATH'] + \
7 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
8
9from perf_trace_context import *
10from Core import *
11from Util import *
12
13drop_log = {}
14kallsyms = []
15
16def get_kallsyms_table():
17 global kallsyms
18
19 try:
20 f = open("/proc/kallsyms", "r")
21 except:
22 return
23
24 for line in f:
25 loc = int(line.split()[0], 16)
26 name = line.split()[2]
27 kallsyms.append((loc, name))
28 kallsyms.sort()
29
30def get_sym(sloc):
31 loc = int(sloc)
32
33 # Invariant: kallsyms[i][0] <= loc for all 0 <= i <= start
34 # kallsyms[i][0] > loc for all end <= i < len(kallsyms)
35 start, end = -1, len(kallsyms)
36 while end != start + 1:
37 pivot = (start + end) // 2
38 if loc < kallsyms[pivot][0]:
39 end = pivot
40 else:
41 start = pivot
42
43 # Now (start == -1 or kallsyms[start][0] <= loc)
44 # and (start == len(kallsyms) - 1 or loc < kallsyms[start + 1][0])
45 if start >= 0:
46 symloc, name = kallsyms[start]
47 return (name, loc - symloc)
48 else:
49 return (None, 0)
50
51def print_drop_table():
52 print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT")
53 for i in drop_log.keys():
54 (sym, off) = get_sym(i)
55 if sym == None:
56 sym = i
57 print "%25s %25s %25s" % (sym, off, drop_log[i])
58
59
60def trace_begin():
61 print "Starting trace (Ctrl-C to dump results)"
62
63def trace_end():
64 print "Gathering kallsyms data"
65 get_kallsyms_table()
66 print_drop_table()
67
68# called from perf, when it finds a correspoinding event
69def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, callchain,
70 skbaddr, location, protocol):
71 slocation = str(location)
72 try:
73 drop_log[slocation] = drop_log[slocation] + 1
74 except:
75 drop_log[slocation] = 1