13
13
from __future__ import print_function
14
14
from bcc import BPF
15
15
import argparse
16
- import ctypes as ct
17
16
import time
18
17
19
18
# arguments
79
78
80
79
TASK_COMM_LEN = 16 # linux/sched.h
81
80
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
-
89
81
matched = b .num_open_kprobes ()
90
82
if matched == 0 :
91
83
print ("Function \" %s\" not found. Exiting." % function )
@@ -102,18 +94,18 @@ class Data(ct.Structure):
102
94
print ("%-18s %s" % ("TIME(s)" , "FUNCTION" ))
103
95
104
96
def print_event (cpu , data , size ):
105
- event = ct . cast (data , ct . POINTER ( Data )). contents
97
+ event = b [ "events" ]. event (data )
106
98
107
99
ts = time .time () - start_ts
108
100
109
101
if verbose :
110
102
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 ))
112
104
else :
113
105
print ("%-18.9f %s" % (ts , function ))
114
106
115
107
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' )
117
109
print ("\t %s" % sym )
118
110
119
111
print ()
0 commit comments