@@ -17,11 +17,17 @@ def __init__(self, args, gt, callbacks):
17
17
self .gpu_transition = {}
18
18
self .gpu_frame = {'catch' : [0 , 0 ], 'task' : None }
19
19
self .prepares = {}
20
+ self .pid_names = {}
21
+ self .tid_map = {}
20
22
for callback in self .callbacks .callbacks :
21
23
if 'ContextSwitch' in dir (callback ):
22
24
self .cs = callback .ContextSwitch (callback , args .input + '.ftrace' )
23
25
callback ("metadata_add" , {'domain' : 'GPU' , 'str' : '__process__' , 'pid' : - 1 , 'tid' : - 1 , 'data' : 'GPU Engines' , 'time' : 0 , 'delta' : - 2 })
24
26
27
+ def add_tid_name (self , tid , name ):
28
+ if tid in self .tid_map :
29
+ self .pid_names [self .tid_map [tid ]] = name
30
+
25
31
def handle_record (self , time , cmd , args ):
26
32
if cmd == 'off' :
27
33
if not self .cs or not self .callbacks .check_time_in_limits (time ):
@@ -33,13 +39,16 @@ def handle_record(self, time, cmd, args):
33
39
prev_tid = '0'
34
40
if next_prio == '0' and next_name == 'kernel_task' :
35
41
next_tid = '0'
36
-
42
+ prev_tid = int (prev_tid , 16 )
43
+ next_tid = int (next_tid , 16 )
37
44
self .cs .write (
38
45
time = time , cpu = int (cpu , 16 ),
39
- prev_tid = int ( prev_tid , 16 ), prev_state = 'S' , next_tid = int ( next_tid , 16 ) ,
46
+ prev_tid = prev_tid , prev_state = 'S' , next_tid = next_tid ,
40
47
prev_prio = int (prev_prio , 16 ), next_prio = int (next_prio , 16 ),
41
48
prev_name = prev_name .replace (' ' , '_' ), next_name = next_name .replace (' ' , '_' )
42
49
)
50
+ self .add_tid_name (prev_tid , prev_name )
51
+ self .add_tid_name (next_tid , next_name )
43
52
elif cmd .startswith ('dtHook' ):
44
53
if not self .ignore_gpu :
45
54
pid , tid = args [0 :2 ]
@@ -52,8 +61,10 @@ def handle_record(self, time, cmd, args):
52
61
else :
53
62
print "unsupported cmd:" , cmd , args
54
63
55
- def handle_stack (self , time , pid , tid , stack ):
64
+ def handle_stack (self , kind , time , pid , tid , stack ):
56
65
pid = int (pid , 16 )
66
+ tid = int (tid , 16 )
67
+ self .tid_map [tid ] = pid
57
68
if not self .callbacks .check_time_in_limits (time ) or not self .callbacks .check_pid_allowed (pid ):
58
69
return
59
70
parsed = []
@@ -63,9 +74,10 @@ def handle_stack(self, time, pid, tid, stack):
63
74
parsed .append ({'ptr' : hash (name ), 'module' : module , 'str' : name })
64
75
else :
65
76
parsed .append ({'ptr' : int (frame , 16 ), 'module' : '' , 'str' : '' })
66
- self .callbacks .handle_stack (pid , int ( tid , 16 ), time , parsed )
77
+ self .callbacks .handle_stack (pid , tid , time , parsed , kind )
67
78
68
79
def task (self , time , pid , tid , starts , domain , name , args ):
80
+ self .tid_map [tid ] = pid
69
81
if name in ['IGAccelGLContext::BlitFramebuffer' , 'CGLFlushDrawable' ]:
70
82
self .gpu_frame ['catch' ][0 if starts else 1 ] = time
71
83
if name == 'CGLFlushDrawable' :
@@ -184,8 +196,10 @@ def gpu_call(self, time, cmd, pid, tid, args):
184
196
pass
185
197
elif 'WriteStamp' == cmd :
186
198
pass
199
+ elif 'DidFlip' == cmd :
200
+ pass
187
201
else :
188
- print cmd
202
+ print "Unhandled gpu_call:" , cmd
189
203
190
204
def on_gpu_frame (self , time , pid , tid ):
191
205
self .callbacks .on_event ("marker" , {'pid' : pid , 'tid' : tid , 'domain' : 'gits' , 'time' : time , 'str' : "GPU Frame" , 'type' : 5 , 'data' : 'task' })
@@ -195,6 +209,9 @@ def finalize(self):
195
209
for callback in self .callbacks .callbacks :
196
210
thread_name = name .replace ('\\ "' , '' ).replace ('"' , '' )
197
211
callback ("metadata_add" , {'domain' : 'IntelSEAPI' , 'str' : '__thread__' , 'pid' : pid , 'tid' : tid , 'data' : '%s (%d)' % (thread_name , tid )})
212
+ for pid , name in self .pid_names .iteritems ():
213
+ self .callbacks .set_process_name (pid , name )
214
+ self .callbacks .set_process_name (- pid , 'Sampling: ' + name )
198
215
199
216
200
217
def transform_dtrace (args ):
@@ -212,6 +229,8 @@ def transform_dtrace(args):
212
229
reading_stack = None
213
230
stack = []
214
231
for line in file :
232
+ count += 1
233
+ ends_with_vt = (11 == ord (line [- 1 ])) if len (line ) else False
215
234
line = line .strip ()
216
235
if not line :
217
236
if reading_stack :
@@ -220,16 +239,19 @@ def transform_dtrace(args):
220
239
stack = []
221
240
continue
222
241
if reading_stack :
223
- stack .append (line )
242
+ if ends_with_vt : # Vertical Tab signifies too long stack frame description
243
+ line += '...'
244
+ end_of_line = file .readline () # it is also treated as line end by codecs.open
245
+ line += end_of_line .strip ()
246
+ stack .append (line .replace ('\t ' , ' ' ))
224
247
continue
225
248
parts = line .split ('\t ' )
226
- if parts [1 ] == 'stack' :
227
- reading_stack = [int (parts [0 ], 16 ), parts [2 ], parts [3 ].rstrip (':' )]
249
+ if parts [1 ] in [ 'ustack' , 'kstack' , 'jstack' ] :
250
+ reading_stack = [parts [ 1 ], int (parts [0 ], 16 ), parts [2 ], parts [3 ].rstrip (':' )]
228
251
continue
229
252
dtrace .handle_record (int (parts [0 ], 16 ), parts [1 ], parts [2 :])
230
253
if not count % 1000 :
231
254
progress .tick (file .tell ())
232
- count += 1
233
255
dtrace .finalize ()
234
256
return callbacks .get_result ()
235
257
0 commit comments