plot access patterns Args: datapath: the path to the access pattern data file n_obj_to_plot: the number of objects to plot Returns: None
(
datapath: str, n_obj_to_plot: int = 2000, figname_prefix: str = ""
)
| 85 | |
| 86 | |
| 87 | def plot_access_pattern( |
| 88 | datapath: str, n_obj_to_plot: int = 2000, figname_prefix: str = "" |
| 89 | ) -> None: |
| 90 | """plot access patterns |
| 91 | |
| 92 | Args: |
| 93 | datapath: the path to the access pattern data file |
| 94 | n_obj_to_plot: the number of objects to plot |
| 95 | |
| 96 | Returns: |
| 97 | None |
| 98 | """ |
| 99 | |
| 100 | if not figname_prefix: |
| 101 | figname_prefix = extract_dataname(datapath) |
| 102 | |
| 103 | access_time_list = _load_access_pattern_data(datapath, n_obj_to_plot) |
| 104 | |
| 105 | is_real_time = "Rtime" in datapath |
| 106 | if is_real_time: |
| 107 | if access_time_list[0][-1] < 30 * 24 * 3600: |
| 108 | xlabel = "Time (hour)" |
| 109 | time_unit = 3600 |
| 110 | else: |
| 111 | xlabel = "Time (day)" |
| 112 | time_unit = 3600 * 24 |
| 113 | figname = "{}/{}_access_rt.{}".format(FIG_DIR, figname_prefix, FIG_TYPE) |
| 114 | for idx, ts_list in enumerate(access_time_list): |
| 115 | # access_rtime_list stores N objects, each object has one access pattern list |
| 116 | plt.scatter( |
| 117 | [ts / time_unit for ts in ts_list], [idx for _ in range(len(ts_list))], s=8 |
| 118 | ) |
| 119 | |
| 120 | else: |
| 121 | assert ( |
| 122 | "Vtime" in datapath |
| 123 | ), "the input file might not be accessPattern data file" |
| 124 | xlabel = "Time (# million requests)" |
| 125 | figname = "{}/{}_access_vt.{}".format(FIG_DIR, figname_prefix, FIG_TYPE) |
| 126 | for idx, ts_list in enumerate(access_time_list): |
| 127 | # access_rtime_list stores N objects, each object has one access pattern list |
| 128 | plt.scatter( |
| 129 | [ts / 1e6 for ts in ts_list], [idx for _ in range(len(ts_list))], s=8 |
| 130 | ) |
| 131 | |
| 132 | plt.xlabel(xlabel) |
| 133 | plt.ylabel("Sampled object") # (sorted by first access time) |
| 134 | plt.savefig(figname, bbox_inches="tight") |
| 135 | plt.clf() |
| 136 | logger.info("save fig to {}".format(figname)) |
| 137 | |
| 138 | |
| 139 | if __name__ == "__main__": |
no test coverage detected