Linux Audio

Check our new training course

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