-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmlparser.py
322 lines (304 loc) · 11.6 KB
/
xmlparser.py
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# sphinx_gallery_thumbnail_number = 3
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook
import numpy as np
import os
import copy
import sqlite3
import datetime
import json
import pandas as pd
import xml.etree.ElementTree as ET
from os import listdir
from os.path import isfile, join
MAINDIR='NANO_PERF'
GOODJOBDIR='LOCAL'
#ALLDIRS = ['CEPH', 'CEPHCLIENT', 'HADOOP', 'HADOOP1', 'HADOOP2', 'LOCAL', 'REDIRFNAL', 'REDIRCaltech', 'CERN', 'REDIRCACHE', 'REDIRCACHE1', 'CACHEDIRECT', 'CACHEDIRECT1', 'CACHECERN', 'CACHECERN1', 'CACHECERN2', 'CACHECERN3', 'NDN', 'NDN1']
ALLDIRS = ['LOCAL', 'NDNVIP-80', 'NDN', 'NDN1', 'CACHECERN1', 'CACHECERN2', 'CACHECERN3']
#ALLDIRS = ['smartiops', 'samsung-ssd-850', 'hp-ssd-ex920-512gb', 'LOCAL', 'CACHECERN']
PERFKEYS= ['AvgEventTime', 'EventSetup Get', 'EventSetup Lock', 'EventThroughput', 'MaxEventTime', 'MinEventTime', 'NumberOfStreams', 'NumberOfThreads', 'TotalInitCPU', 'TotalInitTime', 'TotalJobCPU', 'TotalJobTime', 'TotalLoopCPU', 'TotalLoopTime']
TIMINGKEYS=[]
def scandir(DIRNAME):
path = '%s/%s/' % (MAINDIR, DIRNAME)
try:
onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
except OSError:
# Means dir does not exist yet
return {}, {}, {}
out = {}
out.setdefault('Total-Time', [])
outjobs = {}
outperf = {}
uniq = []
for filename in onlyfiles:
fileids = filename.split('-')
totalMsecs = 0
outjobs.setdefault(str(fileids[1]), {})
outjobs[str(fileids[1])]['exitcode'] = fileids[2]
outperf.setdefault(str(fileids[1]), {})
outperf[str(fileids[1])]['exitcode'] = fileids[2]
e = ET.parse("%s/%s" % (path, filename))
out.setdefault('exitcodes', [])
out['exitcodes'].append(fileids[2])
for elt in e.iter():
if 'Name' in elt.keys() and elt.get('Name').startswith('Timing'):
out.setdefault(elt.get('Name'), [])
out[elt.get('Name')].append(float(elt.get('Value')))
outjobs[str(fileids[1])][elt.get('Name')] = float(elt.get('Value'))
if 'Name' in elt.keys() and elt.get('Name') in PERFKEYS:
outperf[str(fileids[1])][elt.get('Name')] = float(elt.get('Value'))
return out, outjobs, outperf
# Python program to get average of a list
def average(lst):
try:
return sum(lst) / len(lst)
except ZeroDivisionError:
return 0
def minimum(lst):
try:
return min(lst)
except ValueError:
return 0
def maximum(lst):
try:
return max(lst)
except ValueError:
return 0
def sumall(lst):
return sum(lst)
def printsummary(keylist, indict, goodjobs):
for key in keylist:
linec = "JOBID;"
line1 = ""
i = 0
for DIR in ALLDIRS:
linec +="ExitCode;%s;" % key
if i == 0:
line1 +="%s; ;" % DIR
i+=1
else:
line1 +="%s; ;" % DIR
print line1
print linec
for jobid in range(1,401):
lineout = ""
if jobid not in goodjobs:
continue
lineout += "%s;" % jobid
for DIR in ALLDIRS:
if str(jobid) not in indict[DIR].keys():
lineout += "1000;"
else:
lineout += '%s;' % indict[DIR][str(jobid)]['exitcode']
if str(jobid) not in indict[DIR].keys():
lineout += "0;"
elif key not in indict[DIR][str(jobid)].keys():
lineout += "0;"
else:
lineout += "%s;" % indict[DIR][str(jobid)][key]
print lineout
def getSummaryPerf(keylist, indict, goodjobs):
linec = ""
for key in keylist:
linec += "%s;" % key
#for key in keylist:
# linec += "%s;" % key
print 'Type;%s;count' % linec
for DIR in ALLDIRS:
sums = {'success': {}, 'failures': {}}
for jobid in range(1,401):
if str(jobid) in indict[DIR].keys():
for key in keylist:
if int(indict[DIR][str(jobid)]['exitcode']) == 0:
sums['success'].setdefault(key, [])
sums['success'][key].append(indict[DIR][str(jobid)][key])
else:
if key in indict[DIR][str(jobid)].keys():
sums['failures'].setdefault(key, [])
sums['failures'][key].append(indict[DIR][str(jobid)][key])
else:
sums['failures'].setdefault(key, [])
sums['failures'][key].append(0)
nline = "%s;" % DIR
bigcount = {'success': 0, 'failures': 0}
#for subkey in ['success', 'failures']:
for subkey in ['failures']:
for key in keylist:
if key in sums[subkey].keys():
tmpcount = len(sums[subkey][key])
bigcount[subkey] = tmpcount if tmpcount > bigcount[subkey] else bigcount[subkey]
nline += "%s;" % float(float(sum(sums[subkey][key]))/float(len(sums[subkey][key])))
else:
bigcount[subkey] = 0
nline += "0;"
print "%s;%s" % (nline, bigcount[subkey])
def getSummaryPerf1(keylist, indict, goodjobs):
linec = ""
for key in keylist:
linec += "%s;" % key
#for key in keylist:
# linec += "%s;" % key
print 'Type;%s;count' % linec
for DIR in ALLDIRS:
sums = {'success': {}, 'failures': {}}
for jobid in range(0,401):
exitcode = 1000
if len(indict[DIR]['exitcodes']) > jobid:
exitcode = int(indict[DIR]['exitcodes'][jobid])
for key in keylist:
val = 0
if key in indict[DIR].keys():
if len(indict[DIR][key]) > jobid:
val = indict[DIR][key][jobid]
if exitcode == 0:
if key in indict[DIR].keys():
sums['success'].setdefault(key, [])
sums['success'][key].append(val)
else:
sums['success'].setdefault(key, [])
sums['success'][key].append(0)
else:
if key in indict[DIR].keys():
sums['failures'].setdefault(key, [])
sums['failures'][key].append(val)
else:
sums['failures'].setdefault(key, [])
sums['failures'][key].append(0)
nline = "%s;" % DIR
bigcount = {'success': 0, 'failures': 0}
#for subkey in ['success', 'failures']:
for subkey in ['failures']:
for key in keylist:
if key in sums[subkey].keys():
tmpcount = len(sums[subkey][key])
bigcount[subkey] = tmpcount if tmpcount > bigcount[subkey] else bigcount[subkey]
nline += "%s;" % float(float(sum(sums[subkey][key]))/float(len(sums[subkey][key])))
else:
bigcount[subkey] = 0
nline += "0;"
print "%s;%s" % (nline, bigcount[subkey])
def Average(lst):
return sum(lst) / len(lst)
def getAVGs(keylist, indict, goodjobs, onlyFailures=False):
OUTs = {}
for key in keylist:
OUTs.setdefault(key, {})
for jobid in range(1,401):
if jobid not in goodjobs:
continue
for DIR in ALLDIRS:
exitCode = 1000
try:
exitCode = int(indict[DIR][str(jobid)]['exitcode'])
except KeyError:
exitCode = 1000
if onlyFailures:
if exitCode == 0:
continue
OUTs[key].setdefault(DIR, [])
if str(jobid) not in indict[DIR].keys():
OUTs[key][DIR].append(0)
elif key not in indict[DIR][str(jobid)].keys():
OUTs[key][DIR].append(0)
else:
OUTs[key][DIR].append(float(indict[DIR][str(jobid)][key]))
for key in keylist:
linec = ""
line1 = ""
i = 0
for DIR in ALLDIRS:
if i == 0:
linec +=";%s;" % key
line1 +=";%s;" % DIR
i+=1
else:
linec +="%s;" % key
line1 +="%s;" % DIR
print line1
print linec
for typen in ['avg', 'min', 'max', 'sum']:
lineout = "%s;" % typen
for DIR in ALLDIRS:
if DIR not in OUTs[key].keys():
lineout += "0;"
continue
elif typen == 'avg':
lineout += "%s;" % Average(OUTs[key][DIR])
elif typen == 'min':
lineout += "%s;" % min(OUTs[key][DIR])
elif typen == 'max':
lineout += "%s;" % max(OUTs[key][DIR])
elif typen == 'sum':
lineout += "%s;" % sum(OUTs[key][DIR])
print lineout
if __name__ == '__main__':
retcont = {}
retjobs = {}
retperf = {}
goodjobs = []
goodfilter = []
for DIR in [GOODJOBDIR]:
path = '%s/%s/' % (MAINDIR, DIR)
try:
onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
except OSError:
break
for fname in onlyfiles:
fileids = fname.split('-')
goodjobs.append(int(fileids[1]))
goodfilter = copy.deepcopy(goodjobs)
for DIR in ALLDIRS:
path = '%s/%s/' % (MAINDIR, DIR)
for idg in goodjobs:
fname = join(path, 'jobrep-%s-0' % idg)
if not isfile(fname):
try:
goodfilter.remove(idg)
except ValueError:
print 'Already removed'
print DIR, fname
print 'overallgood jobs %s %s' % (goodjobs, len(goodjobs))
print 'goodfilter jobs %s %s ' % (goodfilter, len(goodfilter))
for DIR in ALLDIRS:
retcont[DIR], retjobs[DIR], retperf[DIR] = scandir(DIR)
timingkeys = []
for DIR in ALLDIRS:
for key, _vals in retcont[DIR].items():
if key.endswith('totalMsecs'):
if key not in timingkeys:
timingkeys.append(key)
#getgraph(timingkeys, retjobs)
#timingkeys += PERFKEYS
#printsummary(timingkeys, retjobs, goodjobs)
#print '-'*100
#printsummary(PERFKEYS, retperf, goodjobs)
# -----------------------------------------------------------
OUTExit = {}
for jobid in range(1,401):
if jobid not in goodjobs:
continue
for DIR in ALLDIRS:
OUTExit.setdefault(DIR, {})
exitCode = 1000
try:
exitCode = int(retperf[DIR][str(jobid)]['exitcode'])
except KeyError:
exitCode = 1000
OUTExit[DIR].setdefault(exitCode, 0)
OUTExit[DIR][exitCode] += 1
for key, val in OUTExit.items():
print key, val
print '-'*100
getAVGs(PERFKEYS, retperf, goodjobs)
print '-'*100
print 'Only Failures'
getAVGs(PERFKEYS, retperf, goodjobs, True)
print '-'*100
getAVGs(PERFKEYS, retperf, goodfilter)
print '-'*100
getAVGs(timingkeys, retjobs, goodfilter)
#getSummaryPerf(PERFKEYS, retperf, goodjobs)
#getSummaryPerf1(timingkeys, retcont, goodjobs)