-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrit.py
executable file
·206 lines (181 loc) · 5.79 KB
/
rit.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
#! /usr/bin/python
# -*- python -*-
# -*- coding: utf-8 -*-
try:
from sqlite3 import connect as sqlite3_connect
except:
from sqlite import connect as sqlite3_connect
from dbstats import dbstats
def get_rates(db, server, client):
db.cursor.execute('''
select distinct res.rate
from latency_per_rate_avg res,
report rep,
environment e,
machine server_machine,
machine client_machine
where res.report = rep.rowid and
rep.env = e.rowid and
e.machine = server_machine.rowid and
rep.client_env = client_machine.rowid and
server_machine.nodename = "%s" and
client_machine.nodename = "%s"
order by res.rate
''' % (server, client))
results = db.cursor.fetchall()
if results:
return [r[0] for r in results]
return None
def get_kernel_releases(db, server, client):
db.cursor.execute('''
select distinct s.kernel_release
from latency_per_rate_avg res,
report rep,
environment e,
machine server_machine,
machine client_machine,
software_versions s
where res.report = rep.rowid and
rep.env = e.rowid and
e.machine = server_machine.rowid and
rep.client_env = client_machine.rowid and
e.software_versions = s.rowid and
server_machine.nodename = "%s" and
client_machine.nodename = "%s"
order by res.rate
''' % (server, client))
results = db.cursor.fetchall()
if results:
return [k[0] for k in results]
return None
def get_kernel_max_rate(db, kernel, server, client):
db.cursor.execute('''
select max(res.rate)
from latency_per_rate_avg res,
report rep,
environment e,
machine server_machine,
machine client_machine,
software_versions s
where res.report = rep.rowid and
rep.env = e.rowid and
e.machine = server_machine.rowid and
rep.client_env = client_machine.rowid and
e.software_versions = s.rowid and
server_machine.nodename = "%s" and
client_machine.nodename = "%s" and
s.kernel_release = "%s"
''' % (server, client, kernel))
result = db.cursor.fetchone()
if result:
return int(result[0])
return None
def get_latest_report_id(db):
db.cursor.execute('select max(rowid) from report')
result = db.cursor.fetchone()
if result:
return int(result[0])
return None
def get_latency_per_rate_metric(db, rate, metric, server, client):
db.cursor.execute('''
select distinct res.report,
rep.env,
e.system_tunings,
s.kernel_release,
res.value,
t.*,
client_machine.nodename
from latency_per_rate_%s res,
report rep,
environment e,
machine server_machine,
machine client_machine,
system_tunings t,
software_versions s
where res.report = rep.rowid and
rep.env = e.rowid and
e.machine = server_machine.rowid and
rep.client_env = client_machine.rowid and
e.software_versions = s.rowid and
e.system_tunings = t.rowid and
res.rate = %d and
server_machine.nodename = "%s" and
client_machine.nodename = "%s"
order by res.value
limit 10
''' % (metric, rate, server, client))
return db.cursor.fetchall()
def get_common_columns(results, columns):
common_columns = []
for column_index in range(len(columns)):
if len(list(set([result[column_index] for result in results]))) == 1:
common_columns.append(column_index)
return common_columns
def remove_common_columns(columns, common_columns):
result = []
for i in range(len(columns)):
if i not in common_columns:
result.append(columns[i])
return result
def print_rate(db, rate, server, client):
print "rate: %d" % rate
print "-" * 78
for metric in ("avg", "min", "max", "dev"):
results = get_latency_per_rate_metric(db, rate, metric, server, client)
columns = [column[0] for column in db.cursor.description]
common_columns = get_common_columns(results, columns)
print "Shared System tunings:"
for column_index in common_columns:
value = results[0][column_index]
if value:
print "%s: %s" % (columns[column_index], value)
if len(columns) == len(common_columns):
continue
columns = remove_common_columns(columns, common_columns)
for i in range(len(results)):
results[i] = remove_common_columns(results[i], common_columns)
max_mask_lens = [len(column) for column in columns]
for result in results:
mask_lens = [len(str(column)) for column in result]
for i in range(len(mask_lens)):
if mask_lens[i] > max_mask_lens[i]:
max_mask_lens[i] = mask_lens[i]
mask_lens = ["%%%ds | " % l for l in max_mask_lens]
mask = reduce(lambda a, b: a + b, mask_lens)
print mask % tuple(columns)
for result in results:
print mask % tuple([str(i) for i in result])
print
if __name__ == '__main__':
import sys
appname = sys.argv[1]
server = sys.argv[2]
client = sys.argv[3]
db = dbstats(appname)
rates = get_rates(db, server, client)
print "server: %s\n" % server
print "client: %s\n" % client
latest_report = get_latest_report_id(db)
if not latest_report:
print "No reports found!"
sys.exit(1)
print "latest report info:"
print " report id: %d" % latest_report
print " kernel: %s" % db.get_kernel_release_for_report(latest_report)
print " max rate: " + str(db.get_max_rate_for_report(latest_report)) + "\n"
kernels = get_kernel_releases(db, server, client)
if not kernels:
print "no reports found for this server & client"
sys.exit(1)
kernels.sort()
width = max([len(i) for i in kernels])
mask = "%%-%ds: %%d" % width
print "max rates per kernel release:\n"
for k in kernels:
print mask % (k, get_kernel_max_rate(db, k, server, client))
print
for rate in rates:
try:
print_rate(db, rate, server, client)
except IOError:
break