MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / plot_shards_multirate

Function plot_shards_multirate

scripts/plot_appr_mrc.py:33–81  ·  view source on GitHub ↗
(out_files, plot_path)

Source from the content-addressed store, hash-verified

31 print("MRC binary finished successfully.")
32
33def plot_shards_multirate(out_files, plot_path):
34 plt.figure(figsize=(10,6))
35 for csv_file in out_files:
36 try:
37 data = pd.read_csv(csv_file, dtype={"Distance": str}, low_memory=False)
38 except Exception as e:
39 print("Error reading SHARDS CSV:", csv_file, e)
40 continue
41 # Process special rows
42 overflow_rows = data[data["Distance"] == "Overflow"]
43 overflow_freq = overflow_rows["Frequency"].sum() if not overflow_rows.empty else 0
44 cold_miss_rows = data[data["Distance"] == "ColdMiss"]
45 cold_miss_freq = cold_miss_rows["Frequency"].sum() if not cold_miss_rows.empty else 0
46 total_cold = cold_miss_freq + overflow_freq
47
48 full_data = data[~data["Distance"].isin(["Overflow", "ColdMiss"])].copy()
49 try:
50 full_data["Distance"] = pd.to_numeric(full_data["Distance"], errors="coerce")
51 except Exception as e:
52 print("Error converting Distance in", csv_file, e)
53 continue
54 full_data = full_data.dropna().sort_values(by="Distance")
55 full_data["CumulativeFrequency"] = full_data["Frequency"].cumsum()
56 total_frequency = full_data["Frequency"].sum() + total_cold
57 if total_frequency == 0:
58 print(f"Warning: No frequency data in {csv_file}.")
59 continue
60 full_data["MissRatio"] = 1 - (full_data["CumulativeFrequency"] / total_frequency)
61 # Extract rate from filename (assumed pattern: histogram_{rate}.csv)
62 rate_label = os.path.splitext(os.path.basename(csv_file))[0].split("_")[-1]
63 color = PLOT_COLORS.pop(0) if PLOT_COLORS else None
64 plt.plot(full_data["Distance"], full_data["MissRatio"],
65 marker="o", linestyle="-", markersize=2, linewidth=1, alpha=0.8,
66 label=f"Rate {rate_label}", color=color)
67 plt.title("SHARDS Miss Ratio Curve (Integrated)")
68 plt.xlabel("Cache Size")
69 plt.ylabel("Miss Ratio")
70 plt.ylim(0,1)
71 plt.grid(True, linestyle="--", alpha=0.7)
72 # Use linear scale from 0 to maximum
73 # Force x-axis to start at 0 and go to the maximum distance
74 dist_min = 0
75 dist_max = full_data["Distance"].max()
76 plt.xlim(left=dist_min, right=dist_max)
77 os.makedirs(os.path.dirname(plot_path), exist_ok=True)
78 plt.legend()
79 plt.savefig(plot_path)
80 plt.close()
81 print("Integrated SHARDS plot saved to", plot_path)
82
83def plot_mini_multirate(csv_path, plot_path):
84 try:

Callers 2

plot_shards_simpleFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected