1 # Monitor the system for dropped packets and proudce a report of drop locations and counts
2 # SPDX-License-Identifier: GPL-2.0
4 from __future__
import print_function
9 sys
.path
.append(os
.environ
['PERF_EXEC_PATH'] + \
10 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
12 from perf_trace_context
import *
19 def get_kallsyms_table():
23 f
= open("/proc/kallsyms", "r")
28 loc
= int(line
.split()[0], 16)
29 name
= line
.split()[2]
30 kallsyms
.append((loc
, name
))
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]:
46 # Now (start == -1 or kallsyms[start][0] <= loc)
47 # and (start == len(kallsyms) - 1 or loc < kallsyms[start + 1][0])
49 symloc
, name
= kallsyms
[start
]
50 return (name
, loc
- symloc
)
54 def print_drop_table():
55 print("%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT"))
56 for i
in drop_log
.keys():
57 (sym
, off
) = get_sym(i
)
60 print("%25s %25s %25s" % (sym
, off
, drop_log
[i
]))
64 print("Starting trace (Ctrl-C to dump results)")
67 print("Gathering kallsyms data")
71 # called from perf, when it finds a correspoinding event
72 def skb__kfree_skb(name
, context
, cpu
, sec
, nsec
, pid
, comm
, callchain
,
73 skbaddr
, location
, protocol
):
74 slocation
= str(location
)
76 drop_log
[slocation
] = drop_log
[slocation
] + 1
78 drop_log
[slocation
] = 1