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
|
#!/usr/bin/env python
# Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
# This file is part of GlusterFS.
# GlusterFS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3 of the License,
# or (at your option) any later version.
# GlusterFS is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
import numpy as np
import matplotlib.pyplot as plt
import re
import sys
from optparse import OptionParser
# Global dict-of-dict holding the latency data
# latency[xlator-name][op-name]
latencies = {}
counts = {}
totals = {}
def collect_data (f):
"""Collect latency data from the file object f and store it in
the global variable @latencies"""
# example dump file line:
# fuse.latency.TRUNCATE=3147.000,4
for line in f:
m = re.search ("(\w+)\.\w+.(\w+)=(\w+\.\w+),(\w+),(\w+.\w+)", line)
if m and float(m.group(3)) != 0:
xlator = m.group(1)
op = m.group(2)
time = m.group(3)
count = m.group(4)
total = m.group(5)
if not xlator in latencies.keys():
latencies[xlator] = dict()
if not xlator in counts.keys():
counts[xlator] = dict()
if not xlator in totals.keys():
totals[xlator] = dict()
latencies[xlator][op] = time
counts[xlator][op] = count
totals[xlator][op] = total
def calc_latency_heights (xlator_order):
heights = map (lambda x: [], xlator_order)
N = len (xlator_order)
for i in range (N):
xl = xlator_order[i]
k = latencies[xl].keys()
k.sort()
if i == len (xlator_order) - 1:
# bottom-most xlator
heights[i] = [float (latencies[xl][key]) for key in k]
else:
next_xl = xlator_order[i+1]
this_xl_time = [latencies[xl][key] for key in k]
next_xl_time = [latencies[next_xl][key] for key in k]
heights[i] = map (lambda x, y: float (x) - float (y),
this_xl_time, next_xl_time)
return heights
# have sufficient number of colors
colors = ["violet", "blue", "green", "yellow", "orange", "red"]
def latency_profile (title, xlator_order):
heights = calc_latency_heights (xlator_order)
N = len (latencies[xlator_order[0]].keys())
Nxl = len (xlator_order)
ind = np.arange (N)
width = 0.35
pieces = map (lambda x: [], xlator_order)
bottoms = map (lambda x: [], xlator_order)
bottoms[Nxl-1] = map (lambda x: 0, latencies[xlator_order[0]].keys())
for i in range (Nxl-1):
xl = xlator_order[i+1]
k = latencies[xl].keys()
k.sort()
bottoms[i] = [float(latencies[xl][key]) for key in k]
for i in range(Nxl):
pieces[i] = plt.bar (ind, heights[i], width, color=colors[i],
bottom=bottoms[i])
plt.ylabel ("Average Latency (microseconds)")
plt.title ("Latency Profile for '%s'" % title)
k = latencies[xlator_order[0]].keys()
k.sort ()
plt.xticks (ind+width/2., k)
m = round (max(map (float, latencies[xlator_order[0]].values())), -2)
plt.yticks (np.arange(0, m + m*0.1, m/10))
plt.legend (map (lambda p: p[0], pieces), xlator_order)
plt.show ()
def fop_distribution (title, xlator_order):
plt.ylabel ("Percentage of calls")
plt.title ("FOP distribution for '%s'" % title)
k = counts[xlator_order[0]].keys()
k.sort ()
N = len (latencies[xlator_order[0]].keys())
ind = np.arange(N)
width = 0.35
total = 0
top_xl = xlator_order[0]
for op in k:
total += int(counts[top_xl][op])
heights = []
for op in k:
heights.append (float(counts[top_xl][op])/total * 100)
bars = plt.bar (ind, heights, width, color="red")
for bar in bars:
height = bar.get_height()
plt.text (bar.get_x()+bar.get_width()/2., 1.05*height,
"%d%%" % int(height))
plt.xticks(ind+width/2., k)
plt.yticks(np.arange (0, 110, 10))
plt.show()
def calc_workload_heights (xlator_order, scaling):
workload_heights = map (lambda x: [], xlator_order)
top_xl = xlator_order[0]
N = len (xlator_order)
for i in range (N):
xl = xlator_order[i]
k = totals[xl].keys()
k.sort()
if i == len (xlator_order) - 1:
# bottom-most xlator
workload_heights[i] = [float (totals[xl][key]) / float(totals[top_xl][key]) * scaling[k.index(key)] for key in k]
else:
next_xl = xlator_order[i+1]
this_xl_time = [float(totals[xl][key]) / float(totals[top_xl][key]) * scaling[k.index(key)] for key in k]
next_xl_time = [float(totals[next_xl][key]) / float(totals[top_xl][key]) * scaling[k.index(key)] for key in k]
workload_heights[i] = map (lambda x, y: (float (x) - float (y)),
this_xl_time, next_xl_time)
return workload_heights
def workload_profile(title, xlator_order):
plt.ylabel ("Percentage of Total Time")
plt.title ("Workload Profile for '%s'" % title)
k = totals[xlator_order[0]].keys()
k.sort ()
N = len(totals[xlator_order[0]].keys())
Nxl = len(xlator_order)
ind = np.arange(N)
width = 0.35
total = 0
top_xl = xlator_order[0]
for op in k:
total += float(totals[top_xl][op])
p_heights = []
for op in k:
p_heights.append (float(totals[top_xl][op])/total * 100)
heights = calc_workload_heights (xlator_order, p_heights)
pieces = map (lambda x: [], xlator_order)
bottoms = map (lambda x: [], xlator_order)
bottoms[Nxl-1] = map (lambda x: 0, totals[xlator_order[0]].keys())
for i in range (Nxl-1):
xl = xlator_order[i+1]
k = totals[xl].keys()
k.sort()
bottoms[i] = [float(totals[xl][key]) / float(totals[top_xl][key]) * p_heights[k.index(key)] for key in k]
for i in range(Nxl):
pieces[i] = plt.bar (ind, heights[i], width, color=colors[i],
bottom=bottoms[i])
for key in k:
bar = pieces[Nxl-1][k.index(key)]
plt.text (bar.get_x() + bar.get_width()/2., 1.05*p_heights[k.index(key)],
"%d%%" % int(p_heights[k.index(key)]))
plt.xticks(ind+width/2., k)
plt.yticks(np.arange (0, 110, 10))
plt.legend (map (lambda p: p[0], pieces), xlator_order)
plt.show()
def main ():
parser = OptionParser(usage="usage: %prog [-l | -d | -w] -x <xlator order> <state dump file>")
parser.add_option("-l", "--latency", dest="latency", action="store_true",
help="Produce latency profile")
parser.add_option("-d", "--distribution", dest="distribution", action="store_true",
help="Produce distribution of FOPs")
parser.add_option("-w", "--workload", dest="workload", action="store_true",
help="Produce workload profile")
parser.add_option("-t", "--title", dest="title", help="Set the title of the graph")
parser.add_option("-x", "--xlator-order", dest="xlator_order", help="Specify the order of xlators")
(options, args) = parser.parse_args()
if len(args) != 1:
parser.error("Incorrect number of arguments")
if (options.xlator_order):
xlator_order = options.xlator_order.split()
else:
print "xlator order must be specified"
sys.exit(1)
collect_data(file (args[0], 'r'))
if (options.latency):
latency_profile (options.title, xlator_order)
if (options.distribution):
fop_distribution(options.title, xlator_order)
if (options.workload):
workload_profile(options.title, xlator_order)
main ()
|