Compare commits

...

2 Commits

Author SHA1 Message Date
1a44f86e9c Factorize code a bit 2024-06-06 17:22:27 +02:00
a334f5dcf4 Make plot more visible 2024-06-06 16:46:39 +02:00

View File

@ -21,6 +21,8 @@ import warnings
warnings.filterwarnings('ignore') 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")
sns.set_theme()
def dict_to_json(d): def dict_to_json(d):
if isinstance(d, dict): if isinstance(d, dict):
return json.dumps(d) return json.dumps(d)
@ -123,53 +125,44 @@ df["helper_socket"] = df["helper_core"].apply(remap_core("socket"))
df["helper_core_fixed"] = df["helper_core"].apply(remap_core("core")) df["helper_core_fixed"] = df["helper_core"].apply(remap_core("core"))
df["helper_ht"] = df["helper_core"].apply(remap_core("hthread")) df["helper_ht"] = df["helper_core"].apply(remap_core("hthread"))
# slice_mapping = {3: 0, 1: 1, 2: 2, 0: 3}
slice_remap = lambda h: slice_mapping["slice_group"].iloc[h] slice_remap = lambda h: slice_mapping["slice_group"].iloc[h]
df["slice_group"] = df["hash"].apply(slice_remap) df["slice_group"] = df["hash"].apply(slice_remap)
#print(df.columns) def get_graphing_bounds():
#df["Hash"] = df["Addr"].apply(lambda x: (x >> 15)&0x3) q10s = [wq.quantile(df["time"], df[col], 0.1) for col in sample_flush_columns if col in df]
q90s = [wq.quantile(df["time"], df[col], 0.9) for col in sample_flush_columns if col in df]
addresses = df["address"].unique() return int(((min(q10s) - 10) // 10) * 10), int(((max(q90s) + 19) // 10) * 10)
#print(addresses)
#print(*[bin(a) for a in addresses], sep='\n')
#print(df.head())
min_time = df["time"].min()
max_time = df["time"].max()
q10s = [wq.quantile(df["time"], df[col], 0.1) for col in sample_flush_columns if col in df]
q90s = [wq.quantile(df["time"], df[col], 0.9) for col in sample_flush_columns if col in df]
graph_upper = int(((max(q90s) + 19) // 10) * 10)
graph_lower = int(((min(q10s) - 10) // 10) * 10)
# graph_lower = (min_time // 10) * 10
# graph_upper = ((max_time + 9) // 10) * 10
graph_lower, graph_upper = get_graphing_bounds()
print("graphing between {}, {}".format(graph_lower, graph_upper)) print("graphing between {}, {}".format(graph_lower, graph_upper))
df_main_core_0 = df[df["main_core"] == 0]
#df_helper_core_0 = df[df["helper_core"] == 0]
colours = ["b", "r", "g", "y"]
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"])
del kwargs["title"] del kwargs["title"]
plt.xlim([graph_lower, graph_upper])
for (i, yi) in enumerate(values): for (i, yi) in enumerate(values):
kwargs["color"] = colours[i] color = ["b", "r", "g", "y"][i%4]
hist = sns.histplot(x=x_axis, bins=range(graph_lower, graph_upper), weights=yi, stat="count", multiple="stack", kde=False, shrink=3, **kwargs) kwargs["color"] = color
sns.histplot(
custom_hist(df["time"], df["clflush_miss_n"], df["clflush_remote_hit"], title="miss v. hit") x=x_axis,
weights=yi,
#tikzplotlib.save("fig-hist-all.tex")#, axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth') binwidth=5,
plt.show() bins=range(graph_lower, graph_upper),
element="step",
edgecolor=color,
alpha=0.2,
kde=False,
**kwargs
)
def show_specific_position(attacker, victim, slice): def show_specific_position(attacker, victim, slice):
df_ax_vx_sx = df[(df["hash"] == slice) & (df["main_core"] == attacker) & (df["helper_core"] == victim)] df_ax_vx_sx = df[(df["hash"] == slice) & (df["main_core"] == attacker) & (df["helper_core"] == victim)]
@ -178,74 +171,48 @@ def show_specific_position(attacker, victim, 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')
plt.show() plt.show()
show_specific_position(3, 2, 3) def show_grid(df, col, row, shown=["clflush_miss_n", "clflush_remote_hit", "clflush_local_hit_n", "clflush_shared_hit"]):
#show_specific_position(2, 7, 14) # Color convention here :
#show_specific_position(9, 4, 8) # Blue = miss
# Red = Remote Hit
# Green = Local Hit
# Yellow = Shared Hit
df.loc[:, (row,)] = df[row].apply(dict_to_json)
g = sns.FacetGrid(df, col=col, row=row, legend_out=True)
g.map(custom_hist, "time", *shown)
plt.show()
def export_stats_csv():
def stat(x, key):
return wq.median(x["time"], x[key])
df_grouped = df.groupby(["main_core", "helper_core", "hash"])
miss = df_grouped.apply(stat, "clflush_miss_n")
hit_remote = df_grouped.apply(stat, "clflush_remote_hit")
hit_local = df_grouped.apply(stat, "clflush_local_hit_n")
hit_shared = df_grouped.apply(stat, "clflush_shared_hit")
stats = miss.reset_index()
stats.columns = ["main_core", "helper_core", "hash", "clflush_miss_n"]
stats["clflush_remote_hit"] = hit_remote.values
stats["clflush_local_hit_n"] = hit_local.values
stats["clflush_shared_hit"] = hit_shared.values
stats.to_csv(sys.argv[1] + ".stats.csv", index=False)
# Fix np.darray is unhashable custom_hist(df["time"], df["clflush_miss_n"], df["clflush_remote_hit"], title="miss v. hit")
df_main_core_0.loc[:, ('hash',)] = df_main_core_0['hash'].apply(dict_to_json)
df.loc[:, ('hash',)] = df['hash'].apply(dict_to_json)
g = sns.FacetGrid(df_main_core_0, col="helper_core", row="hash", legend_out=True)
g2 = sns.FacetGrid(df, col="main_core", row="hash", legend_out=True)
# Color convention here :
# Blue = miss
# Red = Remote Hit
# Green = Local Hit
# Yellow = Shared Hit
g.map(custom_hist, "time", "clflush_miss_n", "clflush_remote_hit", "clflush_local_hit_n", "clflush_shared_hit")
g2.map(custom_hist, "time", "clflush_miss_n", "clflush_remote_hit", "clflush_local_hit_n", "clflush_shared_hit")
# g.map(sns.distplot, "time", hist_kws={"weights": df["clflush_hit"]}, kde=False)
#plt.show()
#plt.figure()
#df_mcf6 = df[df["main_core_fixed"] == 6]
#df_mcf6_slg7 = df_mcf6[df_mcf6["slice_group"] == 7]
#g3 = sns.FacetGrid(df_mcf6_slg7, row="helper_core_fixed", col="main_ht")
#g3.map(custom_hist, "time", "clflush_miss_n", "clflush_remote_hit", "clflush_local_hit_n", "clflush_shared_hit")
#g4 = sns.FacetGrid(df_mcf6_slg7, row="helper_core_fixed", col="helper_ht")
#g4.map(custom_hist, "time", "clflush_miss_n", "clflush_remote_hit", "clflush_local_hit_n", "clflush_shared_hit")
def stat(x, key):
return wq.median(x["time"], x[key])
miss = df.groupby(["main_core", "helper_core", "hash"]).apply(stat, "clflush_miss_n")
hit_remote = df.groupby(["main_core", "helper_core", "hash"]).apply(stat, "clflush_remote_hit")
hit_local = df.groupby(["main_core", "helper_core", "hash"]).apply(stat, "clflush_local_hit_n")
hit_shared = df.groupby(["main_core", "helper_core", "hash"]).apply(stat, "clflush_shared_hit")
stats = miss.reset_index()
stats.columns = ["main_core", "helper_core", "hash", "clflush_miss_n"]
stats["clflush_remote_hit"] = hit_remote.values
stats["clflush_local_hit_n"] = hit_local.values
stats["clflush_shared_hit"] = hit_shared.values
stats.to_csv(sys.argv[1] + ".stats.csv", index=False)
#print(stats.to_string())
plt.show()
sys.exit(0)
g = sns.FacetGrid(stats, row="Core")
g.map(sns.distplot, 'Miss', bins=range(100, 480), color="r")
g.map(sns.distplot, 'Hit', bins=range(100, 480))
plt.show() plt.show()
#stats["clflush_miss_med"] = stats[[0]].apply(lambda x: x["miss_med"]) show_specific_position(0, 2, 0)
#stats["clflush_hit_med"] = stats[[0]].apply(lambda x: x["hit_med"])
#del df[[0]]
#print(hit.to_string(), miss.to_string())
# test = pd.DataFrame({"value" : [0, 5], "weight": [5, 1]}) df_main_core_0 = df[df["main_core"] == 0]
# plt.figure() show_grid(df_main_core_0, "helper_core", "hash")
# sns.distplot(test["value"], hist_kws={"weights": test["weight"]}, kde=False) show_grid(df, "main_core", "hash")
if not os.path.exists(sys.argv[1] + ".stats.csv"):
export_stats_csv()
else:
print("Skipping .stats.csv export")