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 pathreq_rate.py
More file actions
Latest commit
158 lines (131 loc) · 4.28 KB
/
Copy pathreq_rate.py
File metadata and controls
158 lines (131 loc) · 4.28 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
""" plot request rate
usage:
1. run traceAnalyzer: `./traceAnalyzer /path/trace trace_format --common`,
this will generate some output, including request rate result, trace.reqRate
2. plot request rate using this script:
`python3 req_rate.py trace.reqRate_w300`
"""
importos, sys
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, get_colors, get_linestyles
logger=logging.getLogger("req_rate")
def_load_req_rate_data(
datapath: str,
) ->Tuple[List[float], List[float], List[float], List[float], int]:
"""load request rate plot data from C++ computation
Args:
datapath: path to the reqRate data file
Return:
req_rate_list: list of request rate
"""
ifile=open(datapath)
data_line=ifile.readline()
line=ifile.readline()
assert (
"# req rate - time window"inline
), "the input file might not be reqRate data file"
time_window=int(line.split()[6].strip("()s "))
req_rate_list= [float(i) foriinifile.readline().split(",")[:-1]]
assert"byte rate"inifile.readline()
byte_rate_list= [float(i) foriinifile.readline().split(",")[:-1]]
assert"obj rate"inifile.readline()
obj_rate_list= [float(i) foriinifile.readline().split(",")[:-1]]
assert"first seen obj (cold miss) rate"inifile.readline()
new_obj_rate_list= [float(i) foriinifile.readline().split(",")[:-1]]
ifile.close()
assertlen(req_rate_list) ==len(byte_rate_list)
assertlen(req_rate_list) ==len(obj_rate_list) ==len(new_obj_rate_list)
returnreq_rate_list, byte_rate_list, obj_rate_list, new_obj_rate_list, time_window
defplot_req_rate(datapath: str, figname_prefix: str=""):
COLOR=get_colors(2)
iflen(figname_prefix) ==0:
figname_prefix=extract_dataname(datapath)
(
req_rate_list,
byte_rate_list,
obj_rate_list,
new_obj_rate_list,
time_window,
) =_load_req_rate_data(datapath)
plt.plot(
[i*time_window/3600foriinrange(len(req_rate_list))],
[r/1000forrinreq_rate_list],
label="request",
color=COLOR[0],
linewidth=1,
)
plt.xlabel("Time (Hour)")
plt.ylabel("Request rate (KQPS)")
plt.grid(linestyle="--")
plt.savefig(
"{}/{}_reqRate.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.clf()
logger.info(
"request rate saved as {}/{}_reqRate.{}".format(
FIG_DIR, figname_prefix, FIG_TYPE
)
)
plt.plot(
[i*time_window/3600foriinrange(len(byte_rate_list))],
[n_byte/1024/1024forn_byteinbyte_rate_list],
label="byte",
color=COLOR[0],
linewidth=1,
)
plt.xlabel("Time (Hour)")
plt.ylabel("Request rate (Mbps)")
plt.grid(linestyle="--")
plt.savefig(
"{}/{}_byteRate.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.clf()
logger.info(
"byte request rate saved as {}/{}_byteRate.{}".format(
FIG_DIR, figname_prefix, FIG_TYPE
)
)
plt.plot(
[i*time_window/3600foriinrange(len(obj_rate_list))],
obj_rate_list,
label="object",
color=COLOR[0],
linestyle="-",
linewidth=1,
)
plt.plot(
[i*time_window/3600foriinrange(len(new_obj_rate_list))],
new_obj_rate_list,
label="new object",
color=COLOR[1],
linestyle="--",
linewidth=1,
)
plt.xlabel("Time (Hour)")
plt.ylabel("Object rate (QPS)")
plt.grid(linestyle="--")
plt.legend()
plt.savefig(
"{}/{}_objRate.{}".format(FIG_DIR, figname_prefix, FIG_TYPE),
bbox_inches="tight",
)
plt.clf()
logger.info(
"object request rate saved as {}/{}_objRate.{}".format(
FIG_DIR, figname_prefix, FIG_TYPE
)
)
if__name__=="__main__":
importargparse
ap=argparse.ArgumentParser()
ap.add_argument("datapath", type=str, help="data path")
p=ap.parse_args()
plot_req_rate(p.datapath)