Skip to content

Commit

Permalink
examples: Make some improvements for stacksnoop.py
Browse files Browse the repository at this point in the history
  • Loading branch information
xingfeng2510 authored and yonghong-song committed Apr 25, 2022
1 parent 7906cfb commit 0c2af9c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
14 changes: 3 additions & 11 deletions examples/tracing/stacksnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from __future__ import print_function
from bcc import BPF
import argparse
import ctypes as ct
import time

# arguments
Expand Down Expand Up @@ -79,13 +78,6 @@

TASK_COMM_LEN = 16 # linux/sched.h

class Data(ct.Structure):
_fields_ = [
("stack_id", ct.c_ulonglong),
("pid", ct.c_uint),
("comm", ct.c_char * TASK_COMM_LEN),
]

matched = b.num_open_kprobes()
if matched == 0:
print("Function \"%s\" not found. Exiting." % function)
Expand All @@ -102,18 +94,18 @@ class Data(ct.Structure):
print("%-18s %s" % ("TIME(s)", "FUNCTION"))

def print_event(cpu, data, size):
event = ct.cast(data, ct.POINTER(Data)).contents
event = b["events"].event(data)

ts = time.time() - start_ts

if verbose:
print("%-18.9f %-12.12s %-6d %-3d %s" %
(ts, event.comm.decode(), event.pid, cpu, function))
(ts, event.comm.decode('utf-8', 'replace'), event.pid, cpu, function))
else:
print("%-18.9f %s" % (ts, function))

for addr in stack_traces.walk(event.stack_id):
sym = b.ksym(addr, show_offset=offset)
sym = b.ksym(addr, show_offset=offset).decode('utf-8', 'replace')
print("\t%s" % sym)

print()
Expand Down
1 change: 0 additions & 1 deletion examples/tracing/vfsreadlat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from __future__ import print_function
from bcc import BPF
from ctypes import c_ushort, c_int, c_ulonglong
from time import sleep
from sys import argv

Expand Down

0 comments on commit 0c2af9c

Please sign in to comment.