-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_failurerate.py
More file actions
executable file
·178 lines (162 loc) · 5.64 KB
/
calc_failurerate.py
File metadata and controls
executable file
·178 lines (162 loc) · 5.64 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
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python
import random
import math
from optparse import OptionParser
# import matplotlib.pyplot as plt
import numpy as np
X_MAX = 7200000
def parseLogfile(testname, clusterlog,failurelog, conf):
out = open(testname+"_machine.csv", "w")
outputline=""
#read cluster log
result={}
clog = open(clusterlog, "r")
for line in clog:
line = line.strip('\n')
line = line.strip('\r')
if len(line)==0:
continue
parts = line.split(";")
cid = parts[0]
zid = parts[1]
pids = parts[2].split(",")
s_pid = int(pids[0])
e_pid = int(pids[1])
pid_count = e_pid - s_pid + 1
for i in range(pid_count):
pid = str(s_pid+i)
result[pid]={}
result[pid]["LMZ"]=zid
result[pid]["cid"]=cid
result[pid]["time"]=[]
result[pid]["status"]=[]
clog.close()
#find max sim time
config = open(conf, "r")
sim_time = 0
for line in config:
line = line.strip('\n')
line = line.strip('\r')
if len(line)==0:
continue
parts = line.split("=")
if(parts[0]=="SIM_TIME_IN_DAYS"):
sim_time = int(parts[1]) * 24 * 60 * 60
if(parts[0]=="NUM_PART"):
partitions = int(parts[1])
if(parts[0]=="NUM_CLUSTER"):
clusters = int(parts[1])
config.close()
numofpartitions = partitions * clusters
#parse failure log
flog = open(failurelog, "r")
for line in flog:
line = line.strip('\n')
line = line.strip('\r')
if len(line)==0:
continue
parts = line.split(";")
ftime = int(float(parts[0]))
flagType = parts[1]
ftype = parts[2]
if ftype == "MT":
zid = parts[4]
if(flagType=="FS"):
for pid in result.keys():
if(result[pid]["LMZ"]==zid):
result[pid]["time"].append(ftime)
result[pid]["status"].append(0)
if(flagType=="FE"):
for pid in result.keys():
if(result[pid]["LMZ"]==zid):
result[pid]["time"].append(ftime)
result[pid]["status"].append(1)
elif ftype == "MNF":
targetType = parts[3]
if targetType == "Cluster":
cid = parts[4]
if(flagType=="FS"):
for pid in result.keys():
if(result[pid]["cid"]==cid):
result[pid]["time"].append(ftime)
result[pid]["status"].append(0)
if(flagType=="FE"):
for pid in result.keys():
if(result[pid]["cid"]==cid):
result[pid]["time"].append(ftime)
result[pid]["status"].append(1)
elif targetType == "Partition":
thispid = parts[4]
if(flagType=="FS"):
for pid in result.keys():
if(pid==thispid):
result[pid]["time"].append(ftime)
result[pid]["status"].append(0)
if(flagType=="FE"):
for pid in result.keys():
if(pid==thispid):
result[pid]["time"].append(ftime)
result[pid]["status"].append(1)
flog.close()
#calcuate down partitions
down=[]
for i in range(sim_time+1):
count = 0
for pid in result.keys():
counter = 0
if(counter<len(result[pid]["time"]) and i==result[pid]["time"][counter]):
status = result[pid]["status"][counter]
counter += 1
else:
if(counter>0):
status = result[pid]["status"][counter-1]
else:
status = 1
if(status==0):
count += 1
down.append(count)
print float(sum(down))/len(down)
# #calcuate down partitions
# time=[]
# down=[]
# for i in range(sim_time+1):
# time.append(i)
# count = 0
# for pid in result.keys():
# if(result[pid]["status"]==0):
# count += 1
# down.append(count)
# #calculate average down partitions
# avg_down = float(sum(down))/len(down)
# outputline += "avg_down=%f" % avg_down
out.write(outputline)
out.close()
if __name__ == "__main__":
p = OptionParser()
p.add_option("-t", "--testname", dest = "testname", type = "string",
help = "name of test")
p.add_option("-l", "--clusterlog", dest = "clusterlog", type = "string",
help = "path of cluster log file")
p.add_option("-f", "--failurelog", dest = "failurelog", type = "string",
help = "path of failure log file")
p.add_option("-c", "--config", dest = "config", type = "string",
help = "name of config log files")
(opts, args) = p.parse_args()
if not opts.testname:
print "please specify test name (-t)"
p.print_help()
exit()
if not opts.clusterlog:
print "please specify path of cluster log file (-cl)"
p.print_help()
exit()
if not opts.failurelog:
print "please specify path of failure log file (-f)"
p.print_help()
exit()
if not opts.config:
print "please specify config file (-c)"
p.print_help()
exit()
parseLogfile(opts.testname, opts.clusterlog, opts.failurelog, opts.config)
exit()