-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_workloadc.py.bck
231 lines (193 loc) · 7.81 KB
/
plot_workloadc.py.bck
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import re
import matplotlib.pyplot as pyplot
import numpy as np
import argparse
from operator import add
from operator import sub
def make_patch_spines_invisible(ax):
ax.set_frame_on(True)
ax.patch.set_visible(False)
#for sp in ax.spines.itervalues():
# sp.set_visible(False)
for k in ax.spines.keys():
ax.spines[k].set_visible(False)
parser = argparse.ArgumentParser()
parser.add_argument("-caseresult_dir", "--caseresult_dir", help="Result Dir")
parser.add_argument("-cases", "--cases", help="Cases")
parser.add_argument("-loc", "--loc", help="loc")
parser.add_argument("-title", "--title", help="title")
parser.add_argument("-plot_dir", "--plot_dir", help="plot directory")
args = parser.parse_args()
workloadc_throughputs = []
number_bytes_written_master = []
number_bytes_written_slave1 = []
number_of_compaction = []
number_of_storeFiles = []
number_bytes_read_master=[]
number_bytes_read_slave1=[]
number_bytes_read=[]
workloadc_start_timestamp=[]
workloadc_end_timestamp = []
cases = args.cases.split(':')
#for case in cases:
#with open('caseresult/case' + case + '/case' + case+'.log', 'r') as file:
#m = re.findall("\+ echo (\d+)", file.read())
#workloadc_start_timestamp.append(int(m[8]))
#workloadc_start_timestamp.append(int(m[0]))
#workloadc_start_timestamp.append(int(m[int(args.loc)]))
#workloadc_end_timestamp.append(int(m[9]))
#workloadc_end_timestamp.append(int(m[1]))
#workloadc_end_timestamp.append(int(m[int(args.loc)+1]))
# collecting the load throughputs
for case in cases:
with open(args.caseresult_dir + '/case' + case + '/workloadc_1.dat', 'r') as file:
for line in file:
words = line.split()
if len(words) == 3:
if words[0] == '[OVERALL],' and words[1] == 'Throughput(ops/sec),':
workloadc_throughputs.append(float(words[2]))
# collecting metrics
def metricstats(file_name, master, metric):
metric_val_list=[]
metric_end_val_list=[]
metric_start_val_list=[]
casecount=-1
for case in cases:
if master:
filename = args.caseresult_dir + '/case'+ case + '/master/' + file_name
else:
filename = args.caseresult_dir + '/case' + case + '/slave1/' + file_name
casecount=casecount+1
with open(filename, 'r') as file:
found = False
f = file.read()
count = 0
#stamp = workloadc_end_timestamp[casecount]
while not found and count < 1000:
#regex = "("+str(stamp)+".*)"
matches = re.findall(regex, f)
print(matches)
for match in matches:
tokens = match.split()
metric_val=0
for token in tokens:
words=token.strip(',').split('=')
if re.match(metric, words[0]):
metric_val = metric_val + int(words[1])
found = True
if found:
metric_end_val_list.append(metric_val)
break
stamp = stamp-1
count=count+1
found = False
count = 0
stamp = workloadc_start_timestamp[casecount]
while not found and count < 1000:
regex = "("+str(stamp)+".*)"
matches = re.findall(regex, f)
print(matches)
for match in matches:
tokens = match.split()
metric_val=0
for token in tokens:
words=token.strip(',').split('=')
if re.match(metric, words[0]):
metric_val = metric_val + int(words[1])
found = True
if found:
metric_start_val_list.append(metric_val)
break
stamp = stamp+1
count=count+1
metric_val_list = list(map(sub, metric_end_val_list, metric_start_val_list))
return(metric_val_list)
def compactionstats(file_name, master, metric):
metric_val_list=[]
casecount=-1
for case in cases:
if master:
filename = args.caseresult_dir + '/case'+ case + '/master/' + file_name
else:
filename = args.caseresult_dir + '/case' + case + '/slave1/' + file_name
casecount=casecount+1
with open(filename, 'r') as file:
found = False
count=0
end_stamp = workloadc_end_timestamp[casecount]
start_stamp = workloadc_start_timestamp[casecount]
for line in file:
words=line.split()
stamplen = len(str(end_stamp))
running_stamp = words[0][0:stamplen]
if end_stamp > int(running_stamp) and start_stamp < int(running_stamp):
for word in words:
kv = word.strip(',').split('=')
p = re.compile('namespace_default_table_usertable_region_\w*_metric_numFilesCompactedCount')
if p.match(kv[0]):
count = count + int(kv[1])
metric_val_list.append(count)
return(metric_val_list)
number_bytes_written_master = metricstats( 'datanode-metrics.out', True, 'bytes_written')
number_bytes_written_slave1 = metricstats( 'datanode-metrics.out', False, 'bytes_written')
number_bytes_written = list(map(add, number_bytes_written_master, number_bytes_written_slave1))
number_bytes_read_master = metricstats('datanode-metrics.out', True, 'bytes_read')
number_bytes_read_slave1 = metricstats('datanode-metrics.out', False, 'bytes_read')
number_bytes_read = list(map(add, number_bytes_read_master, number_bytes_read_slave1))
number_storeFiles_master = metricstats('all.metrics', True, 'storeFileCount')
number_storeFiles_slave1 = metricstats('all.metrics', False, 'storeFileCount')
number_storeFiles = list(map(add, number_storeFiles_master, number_storeFiles_slave1))
# collecting the compaction counts
master_number_compaction= compactionstats('all.metrics', True, 'namespace_default_table_usertable_region_\w*_metric_numFilesCompactedCount')
slave_number_compaction= compactionstats('all.metrics', False, 'namespace_default_table_usertable_region_\w*_metric_numberFilesCompactedCount')
number_of_compaction = list(map(add, master_number_compaction, slave_number_compaction))
print(*workloadc_throughputs, sep=',', end='\n')
print(*number_bytes_written, sep=',', end='\n')
#print(*master_number_compaction, sep=',', end='\n')
print(*number_of_compaction, sep=',', end='\n')
print(*number_storeFiles, sep=',', end='\n')
print(*number_bytes_read, sep=',', end='\n')
fig, ax1 = pyplot.subplots()
fig.subplots_adjust(right=0.75)
p1, = ax1.plot([1,2,3], workloadc_throughputs, color='r', marker='o', label="workloadc throughput", linewidth=1.5)
ax2 = ax1.twinx()
p2, = ax2.plot([1,2,3], number_bytes_written, color='b', marker='o', label="byte written", linewidth=1.5)
ax3 = ax1.twinx()
p3, = ax3.plot([1,2,3], number_of_compaction, color='g', marker='o', label="number of compaction", linewidth=1.5)
#ax4 = ax1.twinx()
#p4, = ax4.plot([1,2,3], number_storeFiles, color='k', marker='o', label="change in number of storeFiles")
ax5 = ax1.twinx()
p5, = ax5.plot([1,2,3], number_bytes_read, color='c', marker='o', label="byte read", linewidth=1.5)
ax3.spines["right"].set_position(("axes", 1.1))
#ax4.spines["right"].set_position(("axes", 1.2))
ax5.spines["right"].set_position(("axes", 1.3))
make_patch_spines_invisible(ax3)
#make_patch_spines_invisible(ax4)
make_patch_spines_invisible(ax5)
ax3.spines["right"].set_visible(True)
#ax4.spines["right"].set_visible(True)
ax5.spines["right"].set_visible(True)
ax1.yaxis.label.set_color(p1.get_color())
ax2.yaxis.label.set_color(p2.get_color())
ax3.yaxis.label.set_color(p3.get_color())
#ax4.yaxis.label.set_color(p4.get_color())
ax5.yaxis.label.set_color(p5.get_color())
ax1.set_ylabel('Throughput')
ax2.set_ylabel('byte written')
ax3.set_ylabel('number of compaction')
#ax4.set_ylabel('change in number of storeFiles')
ax5.set_ylabel('byte read')
pyplot.xticks([1,2,3],['Default', 'Major Off', 'Major and Minor Off'], rotation=30)
tkw = dict(size=10, width=1.5)
ax1.tick_params(axis='y', colors=p1.get_color(), **tkw)
ax2.tick_params(axis='y', colors=p2.get_color(), **tkw)
ax3.tick_params(axis='y', colors=p3.get_color(), **tkw)
#ax4.tick_params(axis='y', colors=p4.get_color(), **tkw)
ax5.tick_params(axis='y', colors=p5.get_color(), **tkw)
ax1.tick_params(axis='x', **tkw)
#lines = [p1, p2, p3, p4, p5]
lines = [p1, p2, p3, p5]
ax1.legend(lines, [l.get_label() for l in lines])
pyplot.title(args.title)
pyplot.savefig(args.plot_dir + 'workloadc_' + args.cases, bbox_inches='tight', pad_inches=0.2)
#pyplot.show()