Skip to content

Commit 013061c

Browse files
committed
utilities: New helper ovs-parse-backtrace.
The new ovs-parse-backtrace utility makes the output of ovs-appctl backtrace more human readable by removing duplicate traces and converting addresses to function names. Signed-off-by: Ethan Jackson <ethan@nicira.com>
1 parent 3d7cab5 commit 013061c

9 files changed

Lines changed: 149 additions & 0 deletions

debian/openvswitch-common.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
usr/bin/ovs-appctl
22
usr/bin/ovs-benchmark
33
usr/bin/ovs-ofctl
4+
usr/bin/ovs-parse-backtrace
45
usr/bin/ovs-parse-leaks
56
usr/bin/ovs-pki
67
usr/bin/ovsdb-client

debian/openvswitch-common.manpages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ _debian/utilities/ovs-benchmark.1
55
_debian/utilities/ovs-ofctl.8
66
_debian/utilities/ovs-pki.8
77
utilities/bugtool/ovs-bugtool.8
8+
utilities/ovs-parse-backtrace.8
89
utilities/ovs-parse-leaks.8

rhel/openvswitch-fedora.spec.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ systemctl start openvswitch.service
170170
%doc /usr/share/man/man8/ovs-brcompatd.8.gz
171171
%doc /usr/share/man/man8/ovs-dpctl.8.gz
172172
%doc /usr/share/man/man8/ovs-ofctl.8.gz
173+
%doc /usr/share/man/man8/ovs-parse-backtrace.8.gz
173174
%doc /usr/share/man/man8/ovs-parse-leaks.8.gz
174175
%doc /usr/share/man/man8/ovs-vsctl.8.gz
175176
%doc /usr/share/man/man8/ovs-vswitchd.8.gz
@@ -179,6 +180,7 @@ systemctl start openvswitch.service
179180
/usr/share/openvswitch/scripts/ovs-ctl
180181
%exclude /etc/openvswitch
181182
%exclude /usr/bin/ovs-benchmark
183+
%exclude /usr/bin/ovs-parse-backtrace
182184
%exclude /usr/bin/ovs-parse-leaks
183185
%exclude /usr/bin/ovs-pcap
184186
%exclude /usr/bin/ovs-tcpundump

rhel/openvswitch.spec.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ exit 0
115115
/usr/bin/ovs-benchmark
116116
/usr/bin/ovs-dpctl
117117
/usr/bin/ovs-ofctl
118+
/usr/bin/ovs-parse-backtrace
118119
/usr/bin/ovs-parse-leaks
119120
/usr/bin/ovs-pcap
120121
/usr/bin/ovs-pki
@@ -140,6 +141,7 @@ exit 0
140141
/usr/share/man/man8/ovs-ctl.8.gz
141142
/usr/share/man/man8/ovs-dpctl.8.gz
142143
/usr/share/man/man8/ovs-ofctl.8.gz
144+
/usr/share/man/man8/ovs-parse-backtrace.8.gz
143145
/usr/share/man/man8/ovs-parse-leaks.8.gz
144146
/usr/share/man/man8/ovs-pki.8.gz
145147
/usr/share/man/man8/ovs-vlan-test.8.gz

utilities/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
/ovs-lib
1919
/ovs-ofctl
2020
/ovs-ofctl.8
21+
/ovs-parse-backtrace
2122
/ovs-parse-leaks
2223
/ovs-pcap
2324
/ovs-pcap.1

utilities/automake.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ bin_SCRIPTS += utilities/ovs-pki utilities/ovs-parse-leaks
88
if HAVE_PYTHON
99
bin_SCRIPTS += \
1010
utilities/ovs-l3ping \
11+
utilities/ovs-parse-backtrace \
1112
utilities/ovs-pcap \
1213
utilities/ovs-tcpundump \
1314
utilities/ovs-test \
@@ -24,6 +25,7 @@ EXTRA_DIST += \
2425
utilities/ovs-ctl.in \
2526
utilities/ovs-l3ping.in \
2627
utilities/ovs-lib.in \
28+
utilities/ovs-parse-backtrace.in \
2729
utilities/ovs-parse-leaks.in \
2830
utilities/ovs-pcap.in \
2931
utilities/ovs-pki.in \
@@ -39,6 +41,7 @@ MAN_ROOTS += \
3941
utilities/ovs-dpctl.8.in \
4042
utilities/ovs-l3ping.8.in \
4143
utilities/ovs-ofctl.8.in \
44+
utilities/ovs-parse-backtrace.8 \
4245
utilities/ovs-parse-leaks.8 \
4346
utilities/ovs-pcap.1.in \
4447
utilities/ovs-pki.8.in \
@@ -59,6 +62,7 @@ DISTCLEANFILES += \
5962
utilities/ovs-l3ping.8 \
6063
utilities/ovs-lib \
6164
utilities/ovs-ofctl.8 \
65+
utilities/ovs-parse-backtrace \
6266
utilities/ovs-parse-leaks \
6367
utilities/ovs-pcap \
6468
utilities/ovs-pcap.1 \
@@ -80,6 +84,7 @@ man_MANS += \
8084
utilities/ovs-dpctl.8 \
8185
utilities/ovs-l3ping.8 \
8286
utilities/ovs-ofctl.8 \
87+
utilities/ovs-parse-backtrace.8 \
8388
utilities/ovs-parse-leaks.8 \
8489
utilities/ovs-pcap.1 \
8590
utilities/ovs-pki.8 \

utilities/ovs-parse-backtrace.8

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.TH ovs\-parse\-backtrace 8 "October 2012" "Open vSwitch" "Open vSwitch Manual"
2+
.
3+
.SH NAME
4+
ovs\-parse\-backtrace \- parses ovs-appctl backtrace output
5+
.
6+
.SH SYNOPSIS
7+
\fBovs\-appctl backtrace\fR | \fBovs\-parse\-backtrace\fR [\fIbinary\fR]
8+
.P
9+
\fBovs\-parse\-backtrace\fR [\fIbinary\fR] < \fIbacktrace\fR
10+
.
11+
.SH DESCRIPTION
12+
In some configurations, many Open vSwitch daemons can produce a series of
13+
backtraces using the \fBovs\-appctl backtrace\fR command. Users can analyze
14+
these backtraces to figure out what the given Open vSwitch daemon may be
15+
spending most of its time doing. \fBovs\-parse\-backtrace\fR makes this output
16+
easier to interpret.
17+
.PP
18+
The \fBovs\-appctl backtrace\fR output must be supplied on standard input. The
19+
binary that produced the output should be supplied as the sole non-option
20+
argument. For best results, the binary should have debug symbols.
21+
.
22+
.SH OPTIONS
23+
.TP
24+
\fB\-\-help\fR
25+
Prints a usage message and exits.
26+
.P
27+
\fB\-\-version\fR
28+
Prints the version and exits.

utilities/ovs-parse-backtrace.in

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#! @PYTHON@
2+
#
3+
# Copyright (c) 2012 Nicira, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at:
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import optparse
18+
import os
19+
import re
20+
import subprocess
21+
import sys
22+
23+
24+
addr2line_cache = {} # None if addr2line is missing or broken.
25+
26+
27+
def addr2line(binary, addr):
28+
global addr2line_cache
29+
30+
if addr2line_cache is None:
31+
return ""
32+
33+
if addr in addr2line_cache:
34+
return addr2line_cache[addr]
35+
36+
cmd = ["addr2line", "-f", "-s", "-e", binary, addr]
37+
try:
38+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
39+
stderr=subprocess.PIPE)
40+
lines = proc.stdout.readlines()
41+
failed = proc.returncode
42+
except OSError:
43+
failed = True
44+
45+
if failed:
46+
addr2line_cache = None
47+
return ""
48+
49+
lines = [l.strip() for l in lines]
50+
return " ".join(lines)
51+
52+
53+
def main():
54+
parser = optparse.OptionParser(version='@VERSION@',
55+
usage="usage: %prog [binary]",
56+
description="""\
57+
Parses the output of ovs-appctl backtrace producing a more human readable
58+
result. Expected usage is for ovs-appctl backtrace to be piped in.""")
59+
options, args = parser.parse_args()
60+
61+
if len(args) > 1:
62+
parser.print_help()
63+
sys.exit(1)
64+
65+
if len(args) == 1:
66+
binary = args[0]
67+
else:
68+
binary = "@sbindir@/ovs-vswitchd"
69+
debug = "/usr/lib/debug%s.debug" % binary
70+
if os.path.exists(debug):
71+
binary = debug
72+
73+
print "Binary: %s\n" % binary
74+
75+
stdin = sys.stdin.read()
76+
trace_list = stdin.strip().split("\n\n")
77+
78+
try:
79+
#Remove the first line from each trace.
80+
trace_list = [trace[(trace.index("\n") + 1):] for trace in trace_list]
81+
except ValueError:
82+
sys.stdout.write(stdin)
83+
sys.exit(1)
84+
85+
trace_map = {}
86+
for trace in trace_list:
87+
trace_map[trace] = trace_map.get(trace, 0) + 1
88+
89+
sorted_traces = sorted(trace_map.items(), key=(lambda x: x[1]),
90+
reverse=True)
91+
for trace, count in sorted_traces:
92+
lines = trace.splitlines()
93+
longest = max(len(l) for l in lines)
94+
95+
print "Backtrace Count: %d" % count
96+
for line in lines:
97+
match = re.search(r'\[(0x.*)]', line)
98+
if match:
99+
print "%s %s" % (line.ljust(longest),
100+
addr2line(binary, match.group(1)))
101+
else:
102+
print line
103+
print
104+
105+
106+
if __name__ == "__main__":
107+
main()

xenserver/openvswitch-xen.spec.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ exit 0
428428
/usr/bin/ovs-appctl
429429
/usr/bin/ovs-dpctl
430430
/usr/bin/ovs-ofctl
431+
/usr/bin/ovs-parse-backtrace
431432
/usr/bin/ovs-parse-leaks
432433
/usr/bin/ovs-pcap
433434
/usr/bin/ovs-tcpundump
@@ -444,6 +445,7 @@ exit 0
444445
/usr/share/man/man8/ovs-ctl.8.gz
445446
/usr/share/man/man8/ovs-dpctl.8.gz
446447
/usr/share/man/man8/ovs-ofctl.8.gz
448+
/usr/share/man/man8/ovs-parse-backtrace.8.gz
447449
/usr/share/man/man8/ovs-parse-leaks.8.gz
448450
/usr/share/man/man1/ovs-pcap.1.gz
449451
/usr/share/man/man1/ovs-tcpundump.1.gz

0 commit comments

Comments
 (0)