Skip to content

Commit

Permalink
tools/profile: Add additional information to backtrace for -v option
Browse files Browse the repository at this point in the history
Add additional information and change format of backtrace
- add symbol base offset, dso name
- symbol and dso info is included if it's available in target binary
- changed format:
ADDR [SYMBOL+OFFSET] (MODULE)

before:
  # ./profile.py
      [unknown]
      _PyDict_GetItem_KnownHash
      [unknown]
      [unknown]
      [unknown]
      [unknown]
      _PyObject_MakeTpCall
      _PyObject_CallFunction_SizeT
      [unknown]
      _PyEval_EvalFrameDefault
      PyEval_EvalCode
      [unknown]
      [unknown]
      _PyRun_SimpleFileObject
      _PyRun_AnyFileObject
      Py_RunMain
      Py_BytesMain
      __libc_start_call_main
      __libc_start_main_impl
      _start
      -                python3 (384002)
          1

      [unknown]
      [unknown]
      [unknown]
      [unknown]
      [unknown]
      [unknown]
      -                gnome-shell (2302)
          1

After:
  # ./profile.py -v
      0xffffffff92d5048e apparmor_file_permission+0x4e
      0xffffffff92d5048e apparmor_file_permission+0x4e
      0xffffffff92cdee66 security_file_permission+0x36
      0xffffffff92ae0177 rw_verify_area+0x47
      0xffffffff92ae2cdb vfs_read+0x7b
      0xffffffff92ae3dd3 ksys_read+0x73
      0xffffffff92ae3e89 __x64_sys_read+0x19
      0xffffffff92606f8a x64_sys_call+0x1ada
      0xffffffff93820daf do_syscall_64+0x7f
      0xffffffff93a00130 entry_SYSCALL_64_after_hwframe+0x78
      0x00007550cbd1ba61 [unknown] [libc.so.6 (deleted)]
      0x00006481674445d8 [unknown] [sshd]
      0x000064816740be42 [unknown] [sshd]
      0x000064816740bb19 [unknown] [sshd]
      0x0000648167448feb [unknown] [sshd]
      0x00006481673dae43 [unknown] [sshd]
      0x00006481673c1641 [unknown] [sshd]
      0x00007550cbc2a1ca [unknown] [libc.so.6 (deleted)]
      -                sshd (383707)
          1

      0x0000775b473f221a [unknown] [libgobject-2.0.so.0.8000.0]
      0x0000775b473fbf14 g_value_transform+0x44 [libgobject-2.0.so.0.8000.0]
      0x0000775b46c270f4 [unknown] [libgjs.so.0.0.0]
      0x0000775b46bfe3e3 [unknown] [libgjs.so.0.0.0]
      0x0000775b43d62369 [unknown] [libmozjs-115.so.115.10.0]
      0xae0a8c7400000000 [unknown]
      0x00007ffea963ff60 [unknown]
      -                gnome-shell (2302)
          1
  • Loading branch information
ekyooo committed Sep 16, 2024
1 parent 9f3d0df commit 2f6b8d8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tools/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from __future__ import print_function
from bcc import BPF, PerfType, PerfSWConfig
from bcc.containers import filter_by_containers
from bcc.utils import printb
from sys import stderr
from time import sleep
import argparse
Expand Down Expand Up @@ -130,6 +131,8 @@ def stack_id_err(stack_id):
help="trace cgroups in this BPF map only")
parser.add_argument("--mntnsmap",
help="trace mount namespaces in this BPF map only")
parser.add_argument("-v", "--verbose", action="store_true",
help="show raw addresses")

# option logic
args = parser.parse_args()
Expand Down Expand Up @@ -393,15 +396,22 @@ def aksym(addr):
print(" [Missed Kernel Stack]")
else:
for addr in kernel_stack:
print(" %s" % aksym(addr).decode('utf-8', 'replace'))
if args.verbose:
printb(b" 0x%-16x %s" % (addr, b.ksym(addr, show_offset=True)))
else:
print(" %s" % aksym(addr).decode('utf-8', 'replace'))

if not args.kernel_stacks_only:
if need_delimiter and k.user_stack_id >= 0 and k.kernel_stack_id >= 0:
print(" --")
if stack_id_err(k.user_stack_id):
print(" [Missed User Stack]")
else:
for addr in user_stack:
print(" %s" % b.sym(addr, k.pid).decode('utf-8', 'replace'))
if args.verbose:
printb(b" 0x%016x %s" % (addr, b.sym(addr, k.pid, True, True)))
else:
print(" %s" % b.sym(addr, k.pid).decode('utf-8', 'replace'))
print(" %-16s %s (%d)" % ("-", k.name.decode('utf-8', 'replace'), k.pid))
print(" %d\n" % v.value)

Expand Down

0 comments on commit 2f6b8d8

Please sign in to comment.