diff options
author | Neil Horman <nhorman@tuxdriver.com> | 2011-07-04 13:40:17 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-09-29 15:41:37 -0400 |
commit | 63e03724b51e7315a66a3f1fee6cb8b4a16dc8cc (patch) | |
tree | 90b387fca4acded9587473bf269f185a56c04074 /tools/perf/scripts | |
parent | 98dfd55d80eaac03740aed6c6331e34a504fdf18 (diff) |
perf script: Add drop monitor script
A while back I created the dropmonitor protocol, which allowed users to get
reports of dropped frames communicated to them via a netlink socket.
While useful, several people have now asked that I integrate the ability
to do drop monitoring with perf, so they don't have to run additional
tools.
This patch adds a drop monitor script to the perf suite, and provides
the same output that the netlink socket does.
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1309801217-22450-1-git-send-email-nhorman@tuxdriver.com
Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/scripts')
-rwxr-xr-x | tools/perf/scripts/python/bin/net_dropmonitor-record | 2 | ||||
-rwxr-xr-x | tools/perf/scripts/python/bin/net_dropmonitor-report | 4 | ||||
-rwxr-xr-x | tools/perf/scripts/python/net_dropmonitor.py | 72 |
3 files changed, 78 insertions, 0 deletions
diff --git a/tools/perf/scripts/python/bin/net_dropmonitor-record b/tools/perf/scripts/python/bin/net_dropmonitor-record new file mode 100755 index 000000000000..423fb81dadae --- /dev/null +++ b/tools/perf/scripts/python/bin/net_dropmonitor-record | |||
@@ -0,0 +1,2 @@ | |||
1 | #!/bin/bash | ||
2 | perf record -e skb:kfree_skb $@ | ||
diff --git a/tools/perf/scripts/python/bin/net_dropmonitor-report b/tools/perf/scripts/python/bin/net_dropmonitor-report new file mode 100755 index 000000000000..8d698f5a06aa --- /dev/null +++ b/tools/perf/scripts/python/bin/net_dropmonitor-report | |||
@@ -0,0 +1,4 @@ | |||
1 | #!/bin/bash | ||
2 | # description: display a table of dropped frames | ||
3 | |||
4 | perf script -s "$PERF_EXEC_PATH"/scripts/python/net_dropmonitor.py $@ | ||
diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py new file mode 100755 index 000000000000..a4ffc9500023 --- /dev/null +++ b/tools/perf/scripts/python/net_dropmonitor.py | |||
@@ -0,0 +1,72 @@ | |||
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), | ||
35 | kallsyms.append({ 'loc': loc, 'name' : name}) | ||
36 | |||
37 | print "\r" + str(j) + "/" + str(linecount) | ||
38 | kallsyms.sort() | ||
39 | return | ||
40 | |||
41 | def 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 | |||
48 | def 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 | |||
57 | def trace_begin(): | ||
58 | print "Starting trace (Ctrl-C to dump results)" | ||
59 | |||
60 | def 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 | ||
66 | def 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 | ||