Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathreuse.py
More file actions
Latest commit
168 lines (138 loc) · 4.72 KB
/
Copy pathreuse.py
File metadata and controls
168 lines (138 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""
plot reuse time distribution
usage:
1. run traceAnalyzer: `./traceAnalyzer /path/trace trace_format --common`,
this will generate some output, including reuse distribution result, trace.reuse
2. plot reuse distribution using this script:
`python3 reuse.py trace.reuse`
"""
importos
importsys
importre
importnumpyasnp
importmatplotlib.pyplotasplt
fromtypingimportList, Dict, Tuple
importlogging
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
fromutils.trace_utilsimportextract_dataname
fromutils.plot_utilsimportFIG_DIR, FIG_TYPE
fromutils.data_utilsimportconv_to_cdf
logger=logging.getLogger("reuse")
def_load_reuse_data(datapath: str) ->Tuple[dict, dict]:
"""load reuse distribution plot data from C++ computation
Args:
datapath (str): the path of reuse data file
Returns:
Tuple[dict, dict]: reuse_rtime_count, reuse_vtime_count
"""
ifile=open(datapath)
data_line=ifile.readline()
desc_line=ifile.readline()
m=re.match(r"# reuse real time: freq \(time granularity (?P<tg>\d+)\)", desc_line)
assertmisnotNone, (
"the input file might not be reuse data file, desc line "
+desc_line
+" data "
+datapath
)
rtime_granularity=int(m.group("tg"))
log_base=1.5
reuse_rtime_count, reuse_vtime_count= {}, {}
forlineinifile:
ifline[0] =="#"and"virtual time"inline:
m=re.match(
r"# reuse virtual time: freq \(log base (?P<lb>\d+\.?\d*)\)", line
)
assertmisnotNone, (
"the input file might not be reuse data file, desc line "
+line
+" data "
+datapath
)
log_base=float(m.group("lb"))
break
eliflen(line.strip()) ==0:
continue
else:
reuse_time, count= [int(i) foriinline.split(":")]
ifreuse_time<-1:
print("find negative reuse time "+line)
reuse_rtime_count[reuse_time*rtime_granularity] =count
forlineinifile:
iflen(line.strip()) ==0:
continue
else:
reuse_time, count= [int(i) foriinline.split(":")]
ifreuse_time<-1:
print("find negative reuse time "+line)
reuse_vtime_count[log_base**reuse_time] =count
ifile.close()
returnreuse_rtime_count, reuse_vtime_count
defplot_reuse(datapath: str, figname_prefix: str="") ->None:
"""
plot reuse time distribution
Args:
datapath (str): the path of reuse data file
figname_prefix (str, optional): the prefix of figname. Defaults to "".
Returns:
None: None
"""
iflen(figname_prefix) ==0:
figname_prefix=extract_dataname(datapath)
reuse_rtime_count, reuse_vtime_count=_load_reuse_data(datapath)
x, y=conv_to_cdf(None, data_dict=reuse_rtime_count)
ifx[0] <0:
x=x[1:]
y= [y[i] -y[0] foriinrange(1, len(y))]
plt.plot([i/3600foriinx], y)
plt.grid(linestyle="--")
plt.ylim(0, 1)
plt.xlabel("Time (Hour)")
plt.ylabel("Fraction of requests (CDF)")
plt.savefig(
"{}/{}_reuse_rt.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.xscale("log")
plt.xticks(
np.array([60, 300, 3600, 86400, 86400*2, 86400*4]) /3600,
["1 min", "5 min", "1 hour", "1 day", "", "4 day"],
rotation=28,
)
plt.savefig(
"{}/{}_reuse_rt_log.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.clf()
x, y=conv_to_cdf(None, data_dict=reuse_vtime_count)
ifx[0] <0:
x=x[1:]
y= [y[i] -y[0] foriinrange(1, len(y))]
plt.plot([iforiinx], y)
plt.grid(linestyle="--")
plt.xlabel("Virtual time (# requests)")
plt.ylabel("Fraction of requests (CDF)")
plt.savefig(
"{}/{}_reuse_vt.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.xscale("log")
plt.savefig(
"{}/{}_reuse_vt_log.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.clf()
logger.info(
"reuse time plot saved to {}/{}_reuse_rt.{} and {}/{}_reuse_vt.{}".format(
FIG_DIR, figname_prefix, FIG_TYPE, FIG_DIR, figname_prefix, FIG_TYPE
)
)
if__name__=="__main__":
importargparse
ap=argparse.ArgumentParser()
ap.add_argument("datapath", type=str, help="data path")
ap.add_argument(
"--figname-prefix", type=str, default="", help="the prefix of figname"
)
p=ap.parse_args()
plot_reuse(p.datapath, p.figname_prefix)