-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZpoolData.py
224 lines (201 loc) · 7.8 KB
/
ZpoolData.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
'''
Created on Apr 12, 2017
@author: dquigley
'''
import os
from ToolData import ToolData
from __builtin__ import True
from PerfUtil import PerfUtil
class ZpoolRecord(object):
def __init__(self):
self.name = ""
self.capacityAlloc = 0
self.capacityFree = 0
self.operationsRead = 0
self.operationsWrite = 0
self.bandwidthRead = 0
self.bandwidthWrite = 0
self.totalwaitRead = 0
self.totalwaitWrite = 0
self.diskwaitRead = 0
self.diskwaitWrite = 0
self.syncqwaitRead = 0
self.syncqwaitWrite = 0
self.asyncqwaitRead = 0
self.asyncqwaitWrite = 0
self.scrubwait = 0
@classmethod
def recordFromArgs(cls, args):
record = cls()
if len(args) == 16:
record.name = args[0]
record.capacityAlloc = int(args[1])
record.capacityFree = int(args[2])
record.operationsRead = int(args[3])
record.operationsWrite = int(args[4])
record.bandwidthRead = int(args[5])
record.bandwidthWrite = int(args[6])
record.totalwaitRead = int(args[7])
record.totalwaitWrite = int(args[8])
record.diskwaitRead = int(args[9])
record.diskwaitWrite = int(args[10])
record.syncqwaitRead = int(args[11])
record.syncqwaitWrite = int(args[12])
record.asyncqwaitRead = int(args[13])
record.asyncqwaitWrite = int(args[14])
record.scrubwait = int(args[15])
return record
class ZpoolIOStat(object):
def __init__(self):
self.pool = None
self.children = []
pass
@classmethod
def statsFromLines(cls, lines):
stats = cls()
stats.pool = ZpoolRecord.recordFromArgs(lines[0].split())
if len(lines) > 1:
for line in lines[1:]:
stats.children.append(ZpoolRecord.recordFromArgs(line.split()))
return stats
class ZpoolIOSummary(object):
def __init__(self):
self.finalized = False
self.name = ""
self.count = 0
self.capacityAlloc = 0
self.capacityFree = 0
self.operationsRead = 0
self.operationsWrite = 0
self.bandwidthRead = 0
self.bandwidthWrite = 0
self.totalwaitRead = 0
self.totalwaitWrite = 0
self.diskwaitRead = 0
self.diskwaitWrite = 0
self.syncqwaitRead = 0
self.syncqwaitWrite = 0
self.asyncqwaitRead = 0
self.asyncqwaitWrite = 0
self.scrubwait = 0
def addRecord(self, record):
self.count = self.count+1
self.capacityAlloc += record.capacityAlloc
self.capacityFree += record.capacityFree
self.operationsRead += record.operationsRead
self.operationsWrite += record.operationsWrite
self.bandwidthRead += record.bandwidthRead
self.bandwidthWrite += record.bandwidthWrite
self.totalwaitRead += record.totalwaitRead
self.totalwaitWrite += record.totalwaitWrite
self.diskwaitRead += record.diskwaitRead
self.diskwaitWrite += record.diskwaitWrite
self.syncqwaitRead += record.syncqwaitRead
self.syncqwaitWrite += record.syncqwaitWrite
self.asyncqwaitRead += record.asyncqwaitRead
self.asyncqwaitWrite += record.asyncqwaitWrite
self.scrubwait += record.scrubwait
def returnFinalized(self):
from copy import deepcopy
final = deepcopy(self)
final.finalize()
return final
def finalize(self):
self.capacityAlloc /= self.count
self.capacityFree /= self.count
self.operationsRead /= self.count
self.operationsWrite /= self.count
self.bandwidthRead /= self.count
self.bandwidthWrite /= self.count
self.totalwaitRead /= self.count
self.totalwaitWrite /= self.count
self.diskwaitRead /= self.count
self.diskwaitWrite /= self.count
self.syncqwaitRead /= self.count
self.syncqwaitWrite /= self.count
self.asyncqwaitRead /= self.count
self.asyncqwaitWrite /= self.count
self.scrubwait /= self.count
self.finalized = True
def compare(self, other):
score = 0
score += PerfUtil.compare(self.capacityAlloc, other.capacityAlloc)
score += PerfUtil.compare(self.capacityFree, other.capacityFree)
score += PerfUtil.compare(self.operationsRead, other.operationsRead)
score += PerfUtil.compare(self.operationsWrite, other.operationsWrite)
score += PerfUtil.compare(self.bandwidthRead, other.bandwidthRead)
score += PerfUtil.compare(self.bandwidthWrite, other.bandwidthWrite)
score += PerfUtil.compare(self.totalwaitRead, other.totalwaitRead)
score += PerfUtil.compare(self.totalwaitWrite, other.totalwaitWrite)
score += PerfUtil.compare(self.diskwaitRead, other.diskwaitRead)
score += PerfUtil.compare(self.diskwaitWrite, other.diskwaitWrite)
score += PerfUtil.compare(self.syncqwaitRead, other.syncqwaitRead)
score += PerfUtil.compare(self.syncqwaitWrite, other.syncqwaitWrite)
score += PerfUtil.compare(self.asyncqwaitRead, other.asyncqwaitRead)
score += PerfUtil.compare(self.asyncqwaitWrite, other.asyncqwaitWrite)
score += PerfUtil.compare(self.scrubwait, other.scrubwait)
return PerfUtil.normalize(score)
class ZpoolDataSummary(object):
def __init__(self, data = None):
self.pool = ZpoolIOSummary()
self.children = []
if data is not None:
for child in data.stats[0].children:
newChild = ZpoolIOSummary()
newChild.name = child.name
self.children.append(newChild)
self.summarizeData(data)
def summarizeData(self, data):
for row in data.stats:
self.pool.addRecord(row.pool)
for i in range(len(row.children)):
self.children[i].addRecord(row.children[i])
self.pool.finalize()
for child in self.children:
child.finalize()
def compare(self, other):
"""
TODO: This should be modified to check if self and other have been finalized
and if not have them return finalized copies with return finalized also for
now assume both runs have the same number of children
"""
score = 0
score += self.pool.compare(other.pool)
for i in range(len(self.children)):
score+= self.children[i].compare(other.children[i])
return PerfUtil.normalize(score)
class ZpoolData(ToolData):
'''
classdocs
'''
def __init__(self, filename=None):
ToolData.__init__(self, "zpool.iostat")
self.stats = []
if filename:
self.parseResults(filename)
else:
self.filename = ""
pass
def parseResults(self, resultFile):
"""
TODO: This function is the way it is because we don't collect the
zpool.iostat data with -H. Convert to use -H in the future
since we don't need it to be human readable
"""
self.filename = os.path.abspath(resultFile)
f = open(self.filename)
save = False
lines = []
for line in f:
if line[0] == '-' and save is False:
save = True
elif line[0] == '-' and save is True:
save = False
self.stats.append(ZpoolIOStat.statsFromLines(lines))
lines = []
elif save:
lines.append(line)
f.close()
pass
def summarize(self):
return ZpoolDataSummary(self)