Skip to content

Commit 0c2af9c

Browse files
xingfeng2510yonghong-song
authored andcommitted
examples: Make some improvements for stacksnoop.py
1 parent 7906cfb commit 0c2af9c

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

examples/tracing/stacksnoop.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from __future__ import print_function
1414
from bcc import BPF
1515
import argparse
16-
import ctypes as ct
1716
import time
1817

1918
# arguments
@@ -79,13 +78,6 @@
7978

8079
TASK_COMM_LEN = 16 # linux/sched.h
8180

82-
class Data(ct.Structure):
83-
_fields_ = [
84-
("stack_id", ct.c_ulonglong),
85-
("pid", ct.c_uint),
86-
("comm", ct.c_char * TASK_COMM_LEN),
87-
]
88-
8981
matched = b.num_open_kprobes()
9082
if matched == 0:
9183
print("Function \"%s\" not found. Exiting." % function)
@@ -102,18 +94,18 @@ class Data(ct.Structure):
10294
print("%-18s %s" % ("TIME(s)", "FUNCTION"))
10395

10496
def print_event(cpu, data, size):
105-
event = ct.cast(data, ct.POINTER(Data)).contents
97+
event = b["events"].event(data)
10698

10799
ts = time.time() - start_ts
108100

109101
if verbose:
110102
print("%-18.9f %-12.12s %-6d %-3d %s" %
111-
(ts, event.comm.decode(), event.pid, cpu, function))
103+
(ts, event.comm.decode('utf-8', 'replace'), event.pid, cpu, function))
112104
else:
113105
print("%-18.9f %s" % (ts, function))
114106

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

119111
print()

examples/tracing/vfsreadlat.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from __future__ import print_function
1919
from bcc import BPF
20-
from ctypes import c_ushort, c_int, c_ulonglong
2120
from time import sleep
2221
from sys import argv
2322

0 commit comments

Comments
 (0)