forked from openvswitch/ovs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
9 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
/ovs-lib | ||
/ovs-ofctl | ||
/ovs-ofctl.8 | ||
/ovs-parse-backtrace | ||
/ovs-parse-leaks | ||
/ovs-pcap | ||
/ovs-pcap.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.TH ovs\-parse\-backtrace 8 "October 2012" "Open vSwitch" "Open vSwitch Manual" | ||
. | ||
.SH NAME | ||
ovs\-parse\-backtrace \- parses ovs-appctl backtrace output | ||
. | ||
.SH SYNOPSIS | ||
\fBovs\-appctl backtrace\fR | \fBovs\-parse\-backtrace\fR [\fIbinary\fR] | ||
.P | ||
\fBovs\-parse\-backtrace\fR [\fIbinary\fR] < \fIbacktrace\fR | ||
. | ||
.SH DESCRIPTION | ||
In some configurations, many Open vSwitch daemons can produce a series of | ||
backtraces using the \fBovs\-appctl backtrace\fR command. Users can analyze | ||
these backtraces to figure out what the given Open vSwitch daemon may be | ||
spending most of its time doing. \fBovs\-parse\-backtrace\fR makes this output | ||
easier to interpret. | ||
.PP | ||
The \fBovs\-appctl backtrace\fR output must be supplied on standard input. The | ||
binary that produced the output should be supplied as the sole non-option | ||
argument. For best results, the binary should have debug symbols. | ||
. | ||
.SH OPTIONS | ||
.TP | ||
\fB\-\-help\fR | ||
Prints a usage message and exits. | ||
.P | ||
\fB\-\-version\fR | ||
Prints the version and exits. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#! @PYTHON@ | ||
# | ||
# Copyright (c) 2012 Nicira, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import optparse | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
|
||
addr2line_cache = {} # None if addr2line is missing or broken. | ||
|
||
|
||
def addr2line(binary, addr): | ||
global addr2line_cache | ||
|
||
if addr2line_cache is None: | ||
return "" | ||
|
||
if addr in addr2line_cache: | ||
return addr2line_cache[addr] | ||
|
||
cmd = ["addr2line", "-f", "-s", "-e", binary, addr] | ||
try: | ||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE) | ||
lines = proc.stdout.readlines() | ||
failed = proc.returncode | ||
except OSError: | ||
failed = True | ||
|
||
if failed: | ||
addr2line_cache = None | ||
return "" | ||
|
||
lines = [l.strip() for l in lines] | ||
return " ".join(lines) | ||
|
||
|
||
def main(): | ||
parser = optparse.OptionParser(version='@VERSION@', | ||
usage="usage: %prog [binary]", | ||
description="""\ | ||
Parses the output of ovs-appctl backtrace producing a more human readable | ||
result. Expected usage is for ovs-appctl backtrace to be piped in.""") | ||
options, args = parser.parse_args() | ||
|
||
if len(args) > 1: | ||
parser.print_help() | ||
sys.exit(1) | ||
|
||
if len(args) == 1: | ||
binary = args[0] | ||
else: | ||
binary = "@sbindir@/ovs-vswitchd" | ||
debug = "/usr/lib/debug%s.debug" % binary | ||
if os.path.exists(debug): | ||
binary = debug | ||
|
||
print "Binary: %s\n" % binary | ||
|
||
stdin = sys.stdin.read() | ||
trace_list = stdin.strip().split("\n\n") | ||
|
||
try: | ||
#Remove the first line from each trace. | ||
trace_list = [trace[(trace.index("\n") + 1):] for trace in trace_list] | ||
except ValueError: | ||
sys.stdout.write(stdin) | ||
sys.exit(1) | ||
|
||
trace_map = {} | ||
for trace in trace_list: | ||
trace_map[trace] = trace_map.get(trace, 0) + 1 | ||
|
||
sorted_traces = sorted(trace_map.items(), key=(lambda x: x[1]), | ||
reverse=True) | ||
for trace, count in sorted_traces: | ||
lines = trace.splitlines() | ||
longest = max(len(l) for l in lines) | ||
|
||
print "Backtrace Count: %d" % count | ||
for line in lines: | ||
match = re.search(r'\[(0x.*)]', line) | ||
if match: | ||
print "%s %s" % (line.ljust(longest), | ||
addr2line(binary, match.group(1))) | ||
else: | ||
print line | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters