Skip to content

Commit

Permalink
trace.py: add option to show multiline backtrace
Browse files Browse the repository at this point in the history
The format of backtrace output from trace.py is not very
human friendly so this patch adds new option - '-l', '--multiline'.

New output:

0xffff8000021e5040 >/tests/tst-tcp  1         0.174132344 tcp_state            tp=0xffffa00001dcd800, CLOSED -> CLOSED
  tcpcb::set_state(int)
  tcp_attach
  tcp_usr_attach
  socreate
  socreate(int, int, int)
  sys_socket
  linux_socket
  socket
  0x1000000e83b1
  0x200000700f1b
  0x1000000e859f

0xffff8000021e5040 >/tests/tst-tcp  1         0.174145515 tcp_state            tp=0xffffa00001dcd800, CLOSED -> LISTEN
  tcpcb::set_state(int)
  tcp_usr_listen
  sys_listen
  listen
  0x1000000e842c

vs the regular one:

0xffff8000021e5040 >/tests/tst-tcp  1         0.174132344 tcp_state            tp=0xffffa00001dcd800, CLOSED -> CLOSED   [tcpcb::set_state(int), tcp_attac h, tcp_usr_attach, socreate, socreate(int, int, int), sys_socket, linux_socket, socket, 0x1000000e83b1, 0x200000700f1b, 0x1000000e859f]
0xffff8000021e5040 >/tests/tst-tcp  1         0.174145515 tcp_state            tp=0xffffa00001dcd800, CLOSED -> LISTEN   [tcpcb::set_state(int), tcp_usr_l isten, sys_listen, listen, 0x1000000e842c]

Signed-off-by: Waldemar Kozaczuk <[email protected]>
  • Loading branch information
wkozaczuk committed Jul 30, 2022
1 parent 46b79c2 commit 1970fd6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scripts/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ def make_symbolic(addr):

def dump_trace(out_func):
indents = defaultdict(int)
bt_formatter = BacktraceFormatter(symbol_resolver, symbol_formatter)
bt_formatter = BacktraceFormatter(symbol_resolver, symbol_formatter, True)

def lookup_tp(name):
return gdb.lookup_global_symbol(name).value().dereference()
Expand Down
12 changes: 8 additions & 4 deletions scripts/osv/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,29 @@ def format_time(time):
return "%12.9f" % nanos_to_seconds(time)

class BacktraceFormatter:
def __init__(self, resolver, formatter):
def __init__(self, resolver, formatter, multiline):
self.resolver = resolver
self.formatter = formatter
self.multiline = multiline

def __call__(self, backtrace):
if not backtrace:
return ''

frames = list(debug.resolve_all(self.resolver, (x - 1 for x in backtrace if x)))

while frames[0].name and frames[0].name.startswith("tracepoint"):
while frames[0].name and (frames[0].name.startswith("tracepoint") or frames[0].filename.endswith("trace.hh")):
frames.pop(0)

return ' [' + ', '.join(map(self.formatter, frames)) + ']'
if self.multiline:
return '\n ' + '\n '.join(map(self.formatter, frames)) + '\n'
else:
return ' [' + ', '.join(map(self.formatter, frames)) + ']'

def simple_symbol_formatter(src_addr):
return '0x%x' % src_addr.addr

default_backtrace_formatter = BacktraceFormatter(debug.DummyResolver(), simple_symbol_formatter)
default_backtrace_formatter = BacktraceFormatter(debug.DummyResolver(), simple_symbol_formatter, False)

class TimeRange(object):
"""
Expand Down
3 changes: 2 additions & 1 deletion scripts/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_backtrace_formatter(args):
if not args.backtrace:
return lambda backtrace: ''

return trace.BacktraceFormatter(symbol_resolver(args), src_addr_formatter(args))
return trace.BacktraceFormatter(symbol_resolver(args), src_addr_formatter(args), True if args.multiline else False)

def list_trace(args):
def data_formatter(sample):
Expand Down Expand Up @@ -667,6 +667,7 @@ def add_trace_listing_options(parser):
add_symbol_resolution_options(parser)
parser.add_argument("-b", "--backtrace", action="store_true", help="show backtrace")
parser.add_argument("--no-header", action="store_true", help="do not show the header")
parser.add_argument("-l", "--multiline", action="store_true", help="show backtrace in multiple lines")

def convert_dump(args):
if os.path.isfile(args.dumpfile):
Expand Down

0 comments on commit 1970fd6

Please sign in to comment.