Add plot(..)

This commit is contained in:
augustin64 2024-06-12 09:45:01 +02:00
parent 2275ebcc77
commit f894161143
2 changed files with 35 additions and 66 deletions

View File

@ -164,6 +164,15 @@ graph_lower, graph_upper = get_graphing_bounds()
print("graphing between {}, {}".format(graph_lower, graph_upper)) print("graphing between {}, {}".format(graph_lower, graph_upper))
def plot(filename, g=None):
if args.no_plot:
if g is not None:
g.savefig(img_dir+filename)
else:
plt.savefig(img_dir+filename)
plt.close()
plt.show()
def custom_hist(x_axis, *values, **kwargs): def custom_hist(x_axis, *values, **kwargs):
if "title" in kwargs: if "title" in kwargs:
plt.title(kwargs["title"]) plt.title(kwargs["title"])
@ -192,11 +201,8 @@ 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: plot("specific-a{}v{}s{}.png".format(attacker, victim, slice))
plt.savefig(img_dir+"specific-a{}v{}s{}.png".format(attacker, victim, slice))
plt.close()
else:
plt.show()
def show_grid(df, col, row, shown=["clflush_miss_n", "clflush_remote_hit", "clflush_local_hit_n", "clflush_shared_hit"]): def show_grid(df, col, row, shown=["clflush_miss_n", "clflush_remote_hit", "clflush_local_hit_n", "clflush_shared_hit"]):
# Color convention here : # Color convention here :
@ -231,12 +237,10 @@ 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: plot("miss_v_hit.png")
plt.savefig(img_dir+"miss_v_hit.png")
plt.close()
else:
plt.show()
custom_hist(df["time"], df["clflush_miss_n"], df["clflush_remote_hit"], df["clflush_local_hit_n"], df["clflush_shared_hit"], title="miss v. hit")
plot("miss_vall_hits.png")
show_specific_position(0, 2, 0) show_specific_position(0, 2, 0)
@ -244,20 +248,13 @@ if not args.stats:
df_main_core_0.loc[:, ("hash",)] = df["hash"].apply(dict_to_json) df_main_core_0.loc[:, ("hash",)] = df["hash"].apply(dict_to_json)
g = show_grid(df_main_core_0, "helper_core", "hash") g = show_grid(df_main_core_0, "helper_core", "hash")
plot("helper_grid.png", g=g)
if args.no_plot:
g.savefig(img_dir+"helper_grid.png")
plt.close()
else:
plt.show()
g = show_grid(df, "main_core", "hash") g = show_grid(df, "main_core", "hash")
plot("main_grid.png", g=g)
if args.no_plot: g = show_grid(df, "main_core", "helper_core")
g.savefig(img_dir+"main_grid.png") plot("main_helper_grid.png", g=g)
plt.close()
else:
plt.show()
if not os.path.exists(args.path + ".stats.csv") or args.stats: if not os.path.exists(args.path + ".stats.csv") or args.stats:

View File

@ -100,6 +100,15 @@ def remap_core(key):
return remap return remap
def plot(filename, g=None):
if args.no_plot:
if g is not None:
g.savefig(img_dir+filename)
else:
plt.savefig(img_dir+filename)
plt.close()
plt.show()
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"))
@ -119,13 +128,7 @@ 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)
if args.no_plot: plot("medians_miss_grid.png", g=g_)
g_.savefig(img_dir+"medians0.png")
plt.close()
else:
plt.show()
# also explains remote # also explains remote
# shared needs some thinking as there is something weird happening there. # shared needs some thinking as there is something weird happening there.
@ -276,11 +279,7 @@ 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')
if args.no_plot: plot("medians_miss.png")
plt.savefig(img_dir+"medians_miss.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]))
@ -294,37 +293,19 @@ 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')
if args.no_plot: plot("medians_remote_hit.png")
plt.savefig(img_dir+"medians_remote_hit.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")
plot("medians_miss_v_localhit_core.png", g=g)
if args.no_plot:
g.savefig(img_dir+"medians_miss_v_localhit_core.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.
plot("medians_miss_v_localhit_slice.png", g=g0)
if args.no_plot:
g0.savefig(img_dir+"medians_miss_v_localhit_slice.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")
g2.map(sns.scatterplot, 'helper_core_fixed', 'clflush_remote_hit', color="r") g2.map(sns.scatterplot, 'helper_core_fixed', 'clflush_remote_hit', color="r")
@ -332,12 +313,8 @@ g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu', color="r")
#g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu2', color="g") #g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu2', color="g")
#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")
plot("medians_remote_hit_grid.png", g=g2)
if args.no_plot:
g2.savefig(img_dir+"medians_remote_hit_grid.png")
plt.close()
else:
plt.show()
if args.rslice: if args.rslice:
for core in stats["main_core_fixed"].unique(): for core in stats["main_core_fixed"].unique():
@ -352,11 +329,6 @@ if args.rslice:
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")
plot("medians_sharedhit.png", g=g3)
# more ideas needed # more ideas needed
if args.no_plot:
g3.savefig(img_dir+"medians_sharedhit.png")
plt.close()
else:
plt.show()