analyse_medians.py : Add argparse & --no-plot

This commit is contained in:
augustin64 2024-06-07 13:54:57 +02:00
parent 4f37118136
commit 1ffa92eb04
2 changed files with 74 additions and 17 deletions

View File

@ -77,7 +77,9 @@ parser.add_argument(
) )
args = parser.parse_args() args = parser.parse_args()
print(args.path)
img_dir = os.path.dirname(args.path)+"/figs/"
os.makedirs(img_dir, exist_ok=True)
assert os.path.exists(args.path + ".slices.csv") assert os.path.exists(args.path + ".slices.csv")
assert os.path.exists(args.path + ".cores.csv") assert os.path.exists(args.path + ".cores.csv")
@ -191,7 +193,7 @@ def show_specific_position(attacker, victim, slice):
custom_hist(df_ax_vx_sx["time"], df_ax_vx_sx["clflush_miss_n"], df_ax_vx_sx["clflush_remote_hit"], title=f"A{attacker} V{victim} S{slice}") custom_hist(df_ax_vx_sx["time"], df_ax_vx_sx["clflush_miss_n"], df_ax_vx_sx["clflush_remote_hit"], title=f"A{attacker} V{victim} S{slice}")
#tikzplotlib.save("fig-hist-good-A{}V{}S{}.tex".format(attacker,victim,slice))#, axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth') #tikzplotlib.save("fig-hist-good-A{}V{}S{}.tex".format(attacker,victim,slice))#, axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth')
if args.no_plot: if args.no_plot:
plt.savefig(args.path+".specific-a{}v{}s{}.png".format(attacker, victim, slice)) plt.savefig(img_dir+"specific-a{}v{}s{}.png".format(attacker, victim, slice))
plt.close() plt.close()
else: else:
plt.show() plt.show()
@ -230,7 +232,7 @@ df.loc[:, ("hash",)] = df["hash"].apply(dict_to_json)
if not args.stats: if not args.stats:
custom_hist(df["time"], df["clflush_miss_n"], df["clflush_remote_hit"], title="miss v. hit") custom_hist(df["time"], df["clflush_miss_n"], df["clflush_remote_hit"], title="miss v. hit")
if args.no_plot: if args.no_plot:
plt.savefig(args.path+".miss_v_hit.png") plt.savefig(img_dir+"miss_v_hit.png")
plt.close() plt.close()
else: else:
plt.show() plt.show()
@ -244,7 +246,7 @@ if not args.stats:
g = show_grid(df_main_core_0, "helper_core", "hash") g = show_grid(df_main_core_0, "helper_core", "hash")
if args.no_plot: if args.no_plot:
g.savefig(args.path+".helper_grid.png") g.savefig(img_dir+"helper_grid.png")
plt.close() plt.close()
else: else:
plt.show() plt.show()
@ -252,7 +254,7 @@ if not args.stats:
g = show_grid(df, "main_core", "hash") g = show_grid(df, "main_core", "hash")
if args.no_plot: if args.no_plot:
g.savefig(args.path+".main_grid.png") g.savefig(img_dir+"main_grid.png")
plt.close() plt.close()
else: else:
plt.show() plt.show()

View File

@ -9,6 +9,7 @@ import seaborn as sns
from sys import exit from sys import exit
import numpy as np import numpy as np
from scipy import optimize from scipy import optimize
import argparse
import sys import sys
import os import os
@ -18,7 +19,7 @@ warnings.filterwarnings('ignore')
print("warnings are filtered, enable them back if you are having some trouble") print("warnings are filtered, enable them back if you are having some trouble")
# TODO # TODO
# sys.argv[1] should be the root # args.path should be the root
# with root-result_lite.csv.bz2 the result # with root-result_lite.csv.bz2 the result
# and .stats.csv # and .stats.csv
# root.slices a slice mapping - done # root.slices a slice mapping - done
@ -29,11 +30,30 @@ print("warnings are filtered, enable them back if you are having some trouble")
# each row is an origin core # each row is an origin core
# each column a helper core if applicable # each column a helper core if applicable
assert os.path.exists(sys.argv[1] + ".stats.csv") parser = argparse.ArgumentParser(
assert os.path.exists(sys.argv[1] + ".slices.csv") prog=sys.argv[0],
assert os.path.exists(sys.argv[1] + ".cores.csv") )
stats = pd.read_csv(sys.argv[1] + ".stats.csv", parser.add_argument("path", help="Path to the experiment files")
parser.add_argument(
"--no-plot",
dest="no_plot",
action="store_true",
default=False,
help="No visible plot (save figures to files)"
)
args = parser.parse_args()
img_dir = os.path.dirname(args.path)+"/figs/"
os.makedirs(img_dir, exist_ok=True)
assert os.path.exists(args.path + ".stats.csv")
assert os.path.exists(args.path + ".slices.csv")
assert os.path.exists(args.path + ".cores.csv")
stats = pd.read_csv(args.path + ".stats.csv",
dtype={ dtype={
"main_core": np.int8, "main_core": np.int8,
"helper_core": np.int8, "helper_core": np.int8,
@ -53,8 +73,8 @@ stats = pd.read_csv(sys.argv[1] + ".stats.csv",
} }
) )
slice_mapping = pd.read_csv(sys.argv[1] + ".slices.csv") slice_mapping = pd.read_csv(args.path + ".slices.csv")
core_mapping = pd.read_csv(sys.argv[1] + ".cores.csv") core_mapping = pd.read_csv(args.path + ".cores.csv")
print("core mapping:\n", core_mapping.to_string()) print("core mapping:\n", core_mapping.to_string())
print("slice mapping:\n", slice_mapping.to_string()) print("slice mapping:\n", slice_mapping.to_string())
@ -72,7 +92,6 @@ def remap_core(key):
return remap return remap
stats["main_socket"] = stats["main_core"].apply(remap_core("socket")) stats["main_socket"] = stats["main_core"].apply(remap_core("socket"))
stats["main_core_fixed"] = stats["main_core"].apply(remap_core("core")) stats["main_core_fixed"] = stats["main_core"].apply(remap_core("core"))
stats["main_ht"] = stats["main_core"].apply(remap_core("hthread")) stats["main_ht"] = stats["main_core"].apply(remap_core("hthread"))
@ -92,7 +111,11 @@ print("Graphing from {} to {}".format(graph_lower_miss, graph_upper_miss))
g_ = sns.FacetGrid(stats, col="main_core_fixed", row="slice_group") g_ = sns.FacetGrid(stats, col="main_core_fixed", row="slice_group")
g_.map(sns.histplot, 'clflush_miss_n', bins=range(graph_lower_miss, graph_upper_miss), color="b", edgecolor="b", alpha=0.2) g_.map(sns.histplot, 'clflush_miss_n', bins=range(graph_lower_miss, graph_upper_miss), color="b", edgecolor="b", alpha=0.2)
plt.show() if args.no_plot:
g_.savefig(img_dir+"medians0.png")
plt.close()
else:
plt.show()
@ -245,7 +268,11 @@ figure_median_I.tight_layout()
# import tikzplotlib # import tikzplotlib
# tikzplotlib.save("fig-median-I.tex", axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth') # tikzplotlib.save("fig-median-I.tex", axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth')
plt.show() if args.no_plot:
plt.savefig(img_dir+"medians1.png")
plt.close()
else:
plt.show()
#stats["predicted_remote_hit_no_gpu"] = exclusive_hit_topology_nogpu_df(stats, *(res_no_gpu[0])) #stats["predicted_remote_hit_no_gpu"] = exclusive_hit_topology_nogpu_df(stats, *(res_no_gpu[0]))
stats["predicted_remote_hit_gpu"] = exclusive_hit_topology_gpu_df(stats, *(res_gpu[0])) stats["predicted_remote_hit_gpu"] = exclusive_hit_topology_gpu_df(stats, *(res_gpu[0]))
@ -259,19 +286,36 @@ figure_median_E_A0.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_
figure_median_E_A0.set_titles(col_template="$S$ = {col_name}") figure_median_E_A0.set_titles(col_template="$S$ = {col_name}")
# tikzplotlib.save("fig-median-E-A0.tex", axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth') # tikzplotlib.save("fig-median-E-A0.tex", axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth')
plt.show() if args.no_plot:
plt.savefig(img_dir+"medians1.png")
plt.close()
else:
plt.show()
g = sns.FacetGrid(stats, row="main_core_fixed") g = sns.FacetGrid(stats, row="main_core_fixed")
g.map(sns.scatterplot, 'slice_group', 'clflush_miss_n', color="b") g.map(sns.scatterplot, 'slice_group', 'clflush_miss_n', color="b")
g.map(sns.scatterplot, 'slice_group', 'clflush_local_hit_n', color="g") g.map(sns.scatterplot, 'slice_group', 'clflush_local_hit_n', color="g")
if args.no_plot:
g.savefig(img_dir+"medians2.png")
plt.close()
else:
plt.show()
g0 = sns.FacetGrid(stats, row="slice_group") g0 = sns.FacetGrid(stats, row="slice_group")
g0.map(sns.scatterplot, 'main_core_fixed', 'clflush_miss_n', color="b") g0.map(sns.scatterplot, 'main_core_fixed', 'clflush_miss_n', color="b")
g0.map(sns.scatterplot, 'main_core_fixed', 'clflush_local_hit_n', color="g") # this gives away the trick I think ! g0.map(sns.scatterplot, 'main_core_fixed', 'clflush_local_hit_n', color="g") # this gives away the trick I think !
# possibility of sending a general please discard this everyone around one of the ring + wait for ACK - direction depends on the core. # possibility of sending a general please discard this everyone around one of the ring + wait for ACK - direction depends on the core.
if args.no_plot:
g0.savefig(img_dir+"medians2.png")
plt.close()
else:
plt.show()
g2 = sns.FacetGrid(stats, row="main_core_fixed", col="slice_group") g2 = sns.FacetGrid(stats, row="main_core_fixed", col="slice_group")
@ -281,9 +325,20 @@ g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu', color="r")
#g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_no_gpu', color="g") #g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_no_gpu', color="g")
#g2.map(plot_func(exclusive_hit_topology_nogpu_df, *(res_no_gpu[0])), 'helper_core_fixed', color="g") #g2.map(plot_func(exclusive_hit_topology_nogpu_df, *(res_no_gpu[0])), 'helper_core_fixed', color="g")
if args.no_plot:
g2.savefig(img_dir+"medians3.png")
plt.close()
else:
plt.show()
g3 = sns.FacetGrid(stats, row="main_core_fixed", col="slice_group") g3 = sns.FacetGrid(stats, row="main_core_fixed", col="slice_group")
g3.map(sns.scatterplot, 'helper_core_fixed', 'clflush_shared_hit', color="y") g3.map(sns.scatterplot, 'helper_core_fixed', 'clflush_shared_hit', color="y")
# more ideas needed # more ideas needed
if args.no_plot:
g3.savefig(img_dir+"medians4.png")
plt.close()
else:
plt.show()
plt.show()