@@ -37,35 +37,44 @@ def parse_mpki_and_ipc(filename: Path):
3737
3838 return cur_ipc , cur_mpki
3939
40+
4041def plot_results (all_results , labels ):
4142 fig , (ax1 , ax2 ) = plt .subplots (2 , 1 , figsize = (12 , 10 ), sharex = True )
4243
43- for results , label in zip (all_results , labels ):
44- file_idxs = [el ["file_idx" ] for el in results ]
45- mpkis = [el ["mpki" ] for el in results ]
46- ipcs = [el ["ipc" ] for el in results ]
44+ num_labels = len (labels )
45+ file_idxs = sorted (list (set (el ["file_idx" ] for results in all_results for el in results )))
46+ bar_width = 0.8 / num_labels
4747
48- res_gmean_mpki = np .round (gmean (mpkis ), 3 )
49- res_gmean_ipc = np .round (gmean (ipcs ), 3 )
48+ for i , (results , label ) in enumerate (zip (all_results , labels )):
49+ mpki_dict = {el ["file_idx" ]: el ["mpki" ] for el in results }
50+ ipc_dict = {el ["file_idx" ]: el ["ipc" ] for el in results }
5051
51- ax1 . plot ( file_idxs , mpkis , marker = 'o' , label = f" { label } (gmean MPKI= { res_gmean_mpki } )" )
52- ax2 . plot ( file_idxs , ipcs , marker = 's' , label = f" { label } (gmean IPC= { res_gmean_ipc } )" )
52+ mpkis = [ mpki_dict . get ( idx , 0 ) for idx in file_idxs ]
53+ ipcs = [ ipc_dict . get ( idx , 0 ) for idx in file_idxs ]
5354
54- ax1 .set_ylabel ("MPKI" )
55- ax1 .legend ()
56- ax1 .grid (True )
55+ res_gmean_mpki = np .round (gmean ([v for v in mpkis if v > 0 ]), 3 )
56+ res_gmean_ipc = np .round (gmean ([v for v in ipcs if v > 0 ]), 3 )
5757
58- ax2 .set_xlabel ("File Index" )
58+ positions = np .arange (len (file_idxs )) + i * bar_width
59+
60+ ax1 .bar (positions , mpkis , bar_width , label = f"{ label } (gmean MPKI={ res_gmean_mpki } )" )
61+ ax2 .bar (positions , ipcs , bar_width , label = f"{ label } (gmean IPC={ res_gmean_ipc } )" )
62+
63+ ax1 .set_ylabel ("MPKI" )
5964 ax2 .set_ylabel ("IPC" )
65+ ax2 .set_xlabel ("File Index" )
66+ ax1 .set_title ("MPKI Comparison" )
67+ ax2 .set_title ("IPC Comparison" )
68+ ax2 .set_xticks (np .arange (len (file_idxs )) + bar_width * (num_labels - 1 ) / 2 )
69+ ax2 .set_xticklabels (file_idxs )
70+ ax1 .legend ()
6071 ax2 .legend ()
72+ ax1 .grid (True )
6173 ax2 .grid (True )
62-
63- plt .suptitle ("Branch predictor policies comparison." )
6474 plt .tight_layout ()
6575 plt .savefig ("branch_comparison.png" )
6676 plt .close ()
6777
68-
6978def run_analysis (input_dir : Path ):
7079 input_files = os .listdir (input_dir )
7180 input_files = sorted (input_files , key = extract_number )
@@ -103,7 +112,7 @@ def run_analysis(input_dir: Path):
103112 for dir_path in runs_dirs :
104113 results = run_analysis (dir_path )
105114 all_results .append (results )
106- labels .append (labels_correct [dir_path .name ])
115+ labels .append (labels_correct [dir_path .name ] if dir_path . name in labels_correct . keys () else dir_path . name )
107116
108117 plot_results (all_results , labels )
109118
0 commit comments