-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analyzer.py
153 lines (128 loc) · 4.72 KB
/
Analyzer.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
'''
Created on Apr 13, 2017
@author: dquigley
'''
import jsonpickle
from os import listdir
from os.path import isfile, join, abspath, basename
from FioData import FioData
from DstatData import DstatData
from ZpoolData import ZpoolData
from PerfUtil import PerfUtil
class TestConfigSummary():
def __init__(self, testConfig = None):
if testConfig is None:
self.testScript = ""
self.sync = ""
self.iosize = ""
self.threads = ""
self.toolSummaries = {}
else:
self.loadFromTestConfig(testConfig)
def loadFromTestConfig(self, testConfig):
self.testScript = testConfig.testScript
self.sync = testConfig.sync
self.iosize = testConfig.iosize
self.threads = testConfig.threads
self.toolSummaries = {}
toolSummary = {}
for key, value in testConfig.toolData.items():
toolSummary[key] = value.summarize()
self.toolSummaries = toolSummary
def compare(self, other):
"""
TODO: This assumes that all configs have the same tools
that were summarizes or at least that every key present
in self.toolSummaries is also in other.toolSummaries
"""
score = 0
for key in self.toolSummaries.keys():
score += self.toolSummaries[key].compare(other.toolSummaries[key])
return PerfUtil.normalize(score)
class TestConfig(object):
def __init__(self):
self.testScript = ""
self.sync = ""
self.iosize = ""
self.threads = ""
self.toolData = {}
def summarize(self):
summary = TestConfigSummary(self)
return summary
class Analyzer(object):
'''
classdocs
'''
def __init__(self, dirname=None):
self.testRuns = {}
if dirname:
self.loadResults(dirname)
else:
self.dirname = ""
pass
def findTestRun(self, scriptName, sync, iosize, threads):
if scriptName not in self.testRuns.keys():
return None
for config in self.testRuns[scriptName]:
if config.sync == sync and config.iosize == iosize and config.threads == threads:
return config
return None
def loadToolData(self, fileName, toolName):
'''This is a klugy hack just for now.'''
if toolName == "fio":
return FioData(fileName)
elif toolName == "dstat":
return DstatData(fileName)
elif toolName == "zpool.iostat":
return ZpoolData(fileName)
return None
def loadResults(self, dirname):
self.dirname = abspath(dirname)
self.files = []
for f in listdir(self.dirname):
if isfile(join(self.dirname, f)):
self.files.append(join(self.dirname, f))
for f in self.files:
filename = basename(f)
tokens = filename.split('-')
if len(tokens) < 5:
continue
scriptName = tokens[0]
toolName = tokens[1]
syncType = tokens[2]
iosize = tokens[3].split('.')[0]
extension = ""
threadTokens = tokens[4].split('.')
threads = threadTokens[0]
if len(threadTokens) is 3:
extension = threadTokens[2]
#Check to see if we have an easy out by not having the right file
if toolName == "dstat" and extension != "csv":
continue
if toolName == "fio" and extension != "json":
continue
testRun = self.findTestRun(scriptName, syncType, iosize, threads)
if testRun:
testRun.toolData[toolName] = self.loadToolData(f, toolName)
else:
newRun = TestConfig()
newRun.testScript = scriptName
newRun.sync = syncType
newRun.iosize = iosize
newRun.threads = threads
newRun.toolData[toolName] = self.loadToolData(f, toolName)
if scriptName not in self.testRuns.keys():
self.testRuns[scriptName] = []
self.testRuns[scriptName].append(newRun)
pass
def writeAnalysis(self, filename):
output = {}
for key, value in self.testRuns.items():
configs = []
output[key] = configs
for config in value:
configs.append(config.summarize())
with open(filename, 'w') as f:
data = jsonpickle.encode(output)
f.write(data)
pass