@@ -37,8 +37,9 @@ def read_data(filename):
37
37
with open (filename , "r" , encoding = "utf8" ) as fh :
38
38
re_thread = re .compile (r'^VLPROFTHREAD (\d+)$' )
39
39
re_record = re .compile (r'^VLPROFEXEC (\S+) (\d+)(.*)$' )
40
- re_payload_mtaskBegin = re .compile (r'id (\d+) predictStart (\d+) cpu (\d+)' )
41
- re_payload_mtaskEnd = re .compile (r'id (\d+) predictCost (\d+)' )
40
+ re_payload_mtaskBegin = re .compile (
41
+ r'id (\d+) predictStart (\d+) cpu (\d+) module\s*(\w+)?' )
42
+ re_payload_mtaskEnd = re .compile (r'predictCost (\d+)' )
42
43
re_payload_wait = re .compile (r'cpu (\d+)' )
43
44
44
45
re_arg1 = re .compile (r'VLPROF arg\s+(\S+)\+([0-9.]*)\s*' )
@@ -56,8 +57,8 @@ def read_data(filename):
56
57
57
58
ExecGraphStack = []
58
59
SectionStack = []
60
+ MtasksStack = []
59
61
ThreadScheduleWait = collections .defaultdict (list )
60
- mTaskThread = {}
61
62
62
63
for line in fh :
63
64
recordMatch = re_record .match (line )
@@ -74,33 +75,35 @@ def read_data(filename):
74
75
SectionStack .pop ()
75
76
Sections [thread ].append ((tick , tuple (SectionStack )))
76
77
elif kind == "MTASK_BEGIN" :
77
- mtask , predict_start , ecpu = re_payload_mtaskBegin .match (payload ).groups ()
78
+ mtask , predict_start , ecpu , module = re_payload_mtaskBegin .match (
79
+ payload ).groups ()
78
80
mtask = int (mtask )
79
81
predict_start = int (predict_start )
80
82
ecpu = int (ecpu )
81
- mTaskThread [mtask ] = thread
82
83
records = Threads [thread ]
83
- assert not records or records [- 1 ]['start' ] <= records [- 1 ]['end' ] <= tick
84
84
records .append ({
85
85
'start' : tick ,
86
86
'mtask' : mtask ,
87
87
'predict_start' : predict_start ,
88
+ 'module' : module ,
88
89
'cpu' : ecpu
89
90
})
90
- Mtasks [mtask ]['begin' ] = tick
91
- Mtasks [mtask ]['thread' ] = thread
92
- Mtasks [mtask ]['predict_start' ] = predict_start
91
+ Mtasks [(module , mtask )]['begin' ] = tick
92
+ Mtasks [(module , mtask )]['predict_start' ] = predict_start
93
+ Mtasks [(module , mtask )]['thread' ] = thread
94
+ MtasksStack .append ((module , mtask , records [- 1 ]))
93
95
elif kind == "MTASK_END" :
94
- mtask , predict_cost = re_payload_mtaskEnd .match (payload ).groups ()
96
+ predict_cost , = re_payload_mtaskEnd .match (payload ).groups ()
95
97
mtask = int (mtask )
98
+ module , mtask , record = MtasksStack .pop ()
96
99
predict_cost = int (predict_cost )
97
- begin = Mtasks [mtask ]['begin' ]
98
- record = Threads [mTaskThread [mtask ]][- 1 ]
100
+ begin = Mtasks [(module , mtask )]['begin' ]
99
101
record ['end' ] = tick
102
+ assert record and records [- 1 ]['start' ] <= records [- 1 ]['end' ] <= tick
100
103
record ['predict_cost' ] = predict_cost
101
- Mtasks [mtask ]['elapsed' ] += tick - begin
102
- Mtasks [mtask ]['predict_cost' ] = predict_cost
103
- Mtasks [mtask ]['end' ] = max (Mtasks [mtask ]['end' ], tick )
104
+ Mtasks [( module , mtask ) ]['elapsed' ] += tick - begin
105
+ Mtasks [( module , mtask ) ]['predict_cost' ] = predict_cost
106
+ Mtasks [( module , mtask ) ]['end' ] = max (Mtasks [( module , mtask ) ]['end' ], tick )
104
107
elif kind == "THREAD_SCHEDULE_WAIT_BEGIN" :
105
108
ecpu = int (re_payload_wait .match (payload ).groups ()[0 ])
106
109
ThreadScheduleWait [ecpu ].append (tick )
@@ -171,6 +174,7 @@ def report():
171
174
for records in Threads .values ():
172
175
for record in records :
173
176
cpu = record ['cpu' ]
177
+ #raise Exception(record)
174
178
elapsed = record ['end' ] - record ['start' ]
175
179
Cpus [cpu ]['mtask_time' ] += elapsed
176
180
@@ -234,8 +238,8 @@ def report_mtasks():
234
238
long_mtask = None
235
239
predict_mtask_time = 0
236
240
predict_elapsed = 0
237
- for mtaskId in Mtasks :
238
- record = Mtasks [mtaskId ]
241
+ for ( module , mtaskId ) in Mtasks :
242
+ record = Mtasks [( module , mtaskId ) ]
239
243
predict_mtask_time += record ['predict_cost' ]
240
244
total_mtask_time += record ['elapsed' ]
241
245
thread_mtask_time [record ['thread' ]] += record ['elapsed' ]
@@ -244,6 +248,7 @@ def report_mtasks():
244
248
if record ['elapsed' ] > long_mtask_time :
245
249
long_mtask_time = record ['elapsed' ]
246
250
long_mtask = mtaskId
251
+ long_mtask_module = module
247
252
Global ['predict_last_end' ] = predict_elapsed
248
253
249
254
serialTime = ElapsedTime - ExecGraphTime
@@ -272,31 +277,51 @@ def report_mtasks():
272
277
max_p2e = - 1000000
273
278
max_mtask = None
274
279
275
- for mtask in sorted (Mtasks .keys ()):
276
- if Mtasks [mtask ]['elapsed' ] > 0 :
277
- if Mtasks [mtask ]['predict_cost' ] == 0 :
278
- Mtasks [mtask ]['predict_cost' ] = 1 # don't log(0) below
279
- p2e_ratio = math .log (Mtasks [mtask ]['predict_cost' ] / Mtasks [mtask ]['elapsed' ])
280
+ for (module , mtaskId ) in sorted (Mtasks .keys ()):
281
+ mtask = Mtasks [(module , mtaskId )]
282
+ if mtask ['elapsed' ] > 0 :
283
+ if mtask ['predict_cost' ] == 0 :
284
+ mtask ['predict_cost' ] = 1 # don't log(0) below
285
+ p2e_ratio = math .log (mtask ['predict_cost' ] / mtask ['elapsed' ])
280
286
p2e_ratios .append (p2e_ratio )
281
287
282
288
if p2e_ratio > max_p2e :
283
289
max_p2e = p2e_ratio
284
- max_mtask = mtask
290
+ max_mtask = mtaskId
291
+ max_module = module
285
292
if p2e_ratio < min_p2e :
286
293
min_p2e = p2e_ratio
287
- min_mtask = mtask
294
+ min_mtask = mtaskId
295
+ min_module = module
288
296
289
297
print ("\n MTask statistics:" )
290
- print (" Longest mtask id = {}" .format (long_mtask ))
298
+ if long_mtask_module :
299
+ print (" Longest mtask id = {} from module '{}'" .format (long_mtask , long_mtask_module ))
300
+ else :
301
+ print (" Longest mtask id = {}" .format (long_mtask ))
291
302
print (" Longest mtask time = {:.2%} of time elapsed in parallelized code" .format (
292
303
long_mtask_time / ExecGraphTime ))
293
304
print (" min log(p2e) = %0.3f" % min_p2e , end = "" )
294
305
295
- print (" from mtask %d (predict %d," % (min_mtask , Mtasks [min_mtask ]['predict_cost' ]), end = "" )
296
- print (" elapsed %d)" % Mtasks [min_mtask ]['elapsed' ])
306
+ if min_module :
307
+ print (" from module '%s' mtask %d (predict %d," %
308
+ (min_module , min_mtask , Mtasks [(min_module , min_mtask )]['predict_cost' ]),
309
+ end = "" )
310
+ else :
311
+ print (" from mtask %d (predict %d," %
312
+ (min_mtask , Mtasks [(min_module , min_mtask )]['predict_cost' ]),
313
+ end = "" )
314
+ print (" elapsed %d)" % Mtasks [(min_module , min_mtask )]['elapsed' ])
297
315
print (" max log(p2e) = %0.3f" % max_p2e , end = "" )
298
- print (" from mtask %d (predict %d," % (max_mtask , Mtasks [max_mtask ]['predict_cost' ]), end = "" )
299
- print (" elapsed %d)" % Mtasks [max_mtask ]['elapsed' ])
316
+ if max_module :
317
+ print (" from module '%s' mtask %d (predict %d," %
318
+ (max_module , max_mtask , Mtasks [(max_module , max_mtask )]['predict_cost' ]),
319
+ end = "" )
320
+ else :
321
+ print (" from mtask %d (predict %d," %
322
+ (max_mtask , Mtasks [(max_module , max_mtask )]['predict_cost' ]),
323
+ end = "" )
324
+ print (" elapsed %d)" % Mtasks [(max_module , max_mtask )]['elapsed' ])
300
325
301
326
stddev = statistics .pstdev (p2e_ratios )
302
327
mean = statistics .mean (p2e_ratios )
@@ -482,17 +507,17 @@ def write_vcd(filename):
482
507
# Compute scale so predicted graph is of same width as interval
483
508
measured_scaling = (end - start ) / Global ['predict_last_end' ]
484
509
# Predict mtasks that fill the time the execution occupied
485
- for mtask in Mtasks :
486
- thread = Mtasks [mtask ]['thread' ]
487
- pred_scaled_start = start + int (Mtasks [mtask ]['predict_start' ] * measured_scaling )
510
+ for (module , mtaskId ) in Mtasks :
511
+ mtask = Mtasks [(module , mtaskId )]
512
+ thread = mtask ['thread' ]
513
+ pred_scaled_start = start + int (mtask ['predict_start' ] * measured_scaling )
488
514
pred_scaled_end = start + int (
489
- (Mtasks [mtask ]['predict_start' ] + Mtasks [mtask ]['predict_cost' ]) *
490
- measured_scaling )
515
+ (mtask ['predict_start' ] + mtask ['predict_cost' ]) * measured_scaling )
491
516
if pred_scaled_start == pred_scaled_end :
492
517
continue
493
518
494
519
mcode = getCode (32 , 'predicted' , 't%d_mtask' % thread )
495
- addValue (mcode , pred_scaled_start , mtask )
520
+ addValue (mcode , pred_scaled_start , mtaskId )
496
521
addValue (mcode , pred_scaled_end , None )
497
522
498
523
parallelism ['predicted' ][pred_scaled_start ] += 1
0 commit comments