@@ -37,35 +37,44 @@ def parse_mpki_and_ipc(filename: Path):
37
37
38
38
return cur_ipc , cur_mpki
39
39
40
+
40
41
def plot_results (all_results , labels ):
41
42
fig , (ax1 , ax2 ) = plt .subplots (2 , 1 , figsize = (12 , 10 ), sharex = True )
42
43
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
47
47
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 }
50
51
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 ]
53
54
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 )
57
57
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" )
59
64
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 ()
60
71
ax2 .legend ()
72
+ ax1 .grid (True )
61
73
ax2 .grid (True )
62
-
63
- plt .suptitle ("Branch predictor policies comparison." )
64
74
plt .tight_layout ()
65
75
plt .savefig ("branch_comparison.png" )
66
76
plt .close ()
67
77
68
-
69
78
def run_analysis (input_dir : Path ):
70
79
input_files = os .listdir (input_dir )
71
80
input_files = sorted (input_files , key = extract_number )
@@ -103,7 +112,7 @@ def run_analysis(input_dir: Path):
103
112
for dir_path in runs_dirs :
104
113
results = run_analysis (dir_path )
105
114
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 )
107
116
108
117
plot_results (all_results , labels )
109
118
0 commit comments