1
+ #!/usr/bin/env python3
2
+ """Script to create performance comparison tables from benchmark results."""
3
+
1
4
import argparse
2
5
import os
3
6
import re
4
7
import xlsxwriter
5
8
6
9
parser = argparse .ArgumentParser ()
7
- parser .add_argument ('-i' , '--input' , help = 'Input file path (logs of perf tests, .txt)' , required = True )
8
- parser .add_argument ('-o' , '--output' , help = 'Output file path (path to .xlsx table)' , required = True )
10
+ parser .add_argument ('-i' , '--input' ,
11
+ help = 'Input file path (logs of perf tests, .txt)' ,
12
+ required = True )
13
+ parser .add_argument ('-o' , '--output' ,
14
+ help = 'Output file path (path to .xlsx table)' ,
15
+ required = True )
9
16
args = parser .parse_args ()
10
17
logs_path = os .path .abspath (args .input )
11
18
xlsx_path = os .path .abspath (args .output )
15
22
result_tables = {"pipeline" : {}, "task_run" : {}}
16
23
set_of_task_name = []
17
24
18
- logs_file = open (logs_path , "r" )
19
- logs_lines = logs_file .readlines ()
25
+ with open (logs_path , "r" , encoding = 'utf-8' ) as logs_file :
26
+ logs_lines = logs_file .readlines ()
27
+
20
28
for line in logs_lines :
21
- pattern = r'tasks[\/|\\](\w*)[\/|\\](\w*):(\w*):(-*\d*\.\d*)'
22
- result = re .findall (pattern , line )
29
+ PATTERN = r'tasks[\/|\\](\w*)[\/|\\](\w*):(\w*):(-*\d*\.\d*)'
30
+ result = re .findall (PATTERN , line )
23
31
if len (result ):
24
32
task_name = result [0 ][1 ]
25
33
perf_type = result [0 ][2 ]
30
38
result_tables [perf_type ][task_name ][ttype ] = - 1.0
31
39
32
40
for line in logs_lines :
33
- pattern = r'tasks[\/|\\](\w*)[\/|\\](\w*):(\w*):(-*\d*\.\d*)'
34
- result = re .findall (pattern , line )
41
+ PATTERN = r'tasks[\/|\\](\w*)[\/|\\](\w*):(\w*):(-*\d*\.\d*)'
42
+ result = re .findall (PATTERN , line )
35
43
if len (result ):
36
44
task_type = result [0 ][0 ]
37
45
task_name = result [0 ][1 ]
38
46
perf_type = result [0 ][2 ]
39
47
perf_time = float (result [0 ][3 ])
40
48
if perf_time < 0.1 :
41
- msg = f"Performance time = { perf_time } < 0.1 second : for { task_type } - { task_name } - { perf_type } \n "
42
- raise Exception (msg )
49
+ MSG = (f"Performance time = { perf_time } < 0.1 second : "
50
+ f"for { task_type } - { task_name } - { perf_type } \n " )
51
+ raise ValueError (MSG )
43
52
result_tables [perf_type ][task_name ][task_type ] = perf_time
44
53
45
54
46
- for table_name in result_tables :
55
+ for table_name , table_data in result_tables . items () :
47
56
workbook = xlsxwriter .Workbook (os .path .join (xlsx_path , table_name + '_perf_table.xlsx' ))
48
57
worksheet = workbook .add_worksheet ()
49
58
worksheet .set_column ('A:Z' , 23 )
50
59
right_bold_border = workbook .add_format ({'bold' : True , 'right' : 2 , 'bottom' : 2 })
51
- bottom_bold_border = workbook .add_format ({'bold' : True , 'bottom' : 2 })
52
- cpu_num = os .environ .get ("PPC_NUM_PROC" )
53
- if cpu_num is None :
54
- raise EnvironmentError ("Required environment variable 'PPC_NUM_PROC' is not set." )
55
- cpu_num = int (cpu_num )
56
- worksheet .write (0 , 0 , "cpu_num = " + str (cpu_num ), right_bold_border )
60
+ right_border = workbook .add_format ({'right' : 2 })
61
+ bottom_border = workbook .add_format ({'bottom' : 2 })
62
+ bottom_bold_border = workbook .add_format ({'bottom' : 2 , 'bold' : True })
63
+ cell_format = workbook .add_format ({'align' : 'center' , 'valign' : 'vcenter' , 'bold' : True })
64
+ cell_result_format = workbook .add_format ({'align' : 'center' , 'valign' : 'vcenter' })
57
65
58
- it = 1
59
- for type_of_task in list_of_type_of_tasks :
60
- worksheet .write (0 , it , "T_" + type_of_task + "(" + str (cpu_num ) + ")" , bottom_bold_border )
61
- it += 1
62
- worksheet .write (0 , it , "S(" + str (cpu_num ) + ")" + " = " +
63
- "T_seq(" + str (cpu_num ) + ")" + " / " +
64
- "T_" + type_of_task + "(" + str (cpu_num ) + ")" , bottom_bold_border )
65
- it += 1
66
- worksheet .write (0 , it , "Eff(" + str (cpu_num ) + ")" + " = " +
67
- "S(" + str (cpu_num ) + ")" + " / " + str (cpu_num ), right_bold_border )
68
- it += 1
66
+ IT = - 1
67
+ for name in sorted (set_of_task_name ):
68
+ IT += 1
69
+ worksheet .merge_range (IT , 0 , IT , 1 , table_name + " : " + name , cell_format )
70
+ for idx , ttype in enumerate (list_of_type_of_tasks ):
71
+ if idx < len (list_of_type_of_tasks ) - 1 :
72
+ worksheet .write (IT , 2 + idx , ttype , cell_format )
73
+ else :
74
+ worksheet .write (IT , 2 + idx , ttype , right_bold_border )
69
75
70
- it = 1
71
- for task_name in list (set (set_of_task_name )):
72
- worksheet .write (it , 0 , task_name , workbook .add_format ({'bold' : True , 'right' : 2 }))
73
- it += 1
76
+ IT = - 1
77
+ for name in sorted (set_of_task_name ):
78
+ IT += 1
74
79
75
- it_i = 1
76
- it_j = 1
77
- right_border = workbook .add_format ({'right' : 2 })
78
- for task_name in list (set (set_of_task_name )):
79
- for type_of_task in list_of_type_of_tasks :
80
- if task_name not in result_tables [table_name ].keys ():
81
- print (f"Warning! Task '{ task_name } ' is not found in results" )
82
- worksheet .write (it_j , it_i , "Error!" )
83
- it_i += 1
84
- worksheet .write (it_j , it_i , "Error!" )
85
- it_i += 1
86
- worksheet .write (it_j , it_i , "Error!" )
87
- it_i += 1
88
- continue
89
- par_time = result_tables [table_name ][task_name ][type_of_task ]
90
- seq_time = result_tables [table_name ][task_name ]["seq" ]
91
- if par_time == 0 :
92
- speed_up = - 1
80
+ IT_I = 2
81
+ IT_J = 2
82
+ seq_time = result_tables [table_name ][name ]["seq" ]
83
+ for ttype in list_of_type_of_tasks :
84
+ res_time = result_tables [table_name ][name ][ttype ]
85
+ if res_time > 0.0 :
86
+ if seq_time > 0 and ttype != "seq" :
87
+ time_str = "time = {:.6f}" .format (res_time )
88
+ SPEED_UP = seq_time / res_time
89
+ speed_up_str = "speedup = {:.2f}" .format (SPEED_UP )
90
+ cell_str = time_str + "\n " + speed_up_str
91
+ else :
92
+ cell_str = "time = {:.6f}" .format (res_time )
93
+ if ttype == "tbb" :
94
+ worksheet .write (IT , IT_I , cell_str , bottom_bold_border )
95
+ else :
96
+ worksheet .write (IT , IT_I , cell_str , cell_result_format )
93
97
else :
94
- speed_up = seq_time / par_time
95
- efficiency = speed_up / cpu_num
96
- worksheet .write (it_j , it_i , par_time )
97
- it_i += 1
98
- worksheet .write (it_j , it_i , speed_up )
99
- it_i += 1
100
- worksheet .write (it_j , it_i , efficiency , right_border )
101
- it_i += 1
102
- it_i = 1
103
- it_j += 1
104
- workbook .close ()
98
+ if ttype == "tbb" :
99
+ worksheet .write (IT , IT_I , "-" , bottom_bold_border )
100
+ else :
101
+ worksheet .write (IT , IT_I , "-" , cell_result_format )
102
+ IT_I += 1
103
+ IT_I = 2
104
+
105
+ workbook .close ()
0 commit comments