-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathait-db-add-latrate
executable file
·52 lines (40 loc) · 1.28 KB
/
ait-db-add-latrate
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
#! /usr/bin/python
# -*- python -*-
# -*- coding: utf-8 -*-
from dbstats import dbstats
class latencies_per_rate_report:
def __init__(self, filename):
self.rates = {}
self._load_latencies_report(filename)
def _load_latencies_report(self, filename):
try:
f = file(filename)
except:
return
for line in f.readlines():
fields = line.strip().split(',')
rate = int(fields[0])
self.rates[rate] = tuple([float(i) for i in fields[1:]])
f.close()
if __name__ == '__main__':
import sys, os
appname = sys.argv[1]
client_machine = sys.argv[2]
server_machine = sys.argv[3]
report = sys.argv[4]
db = dbstats(appname)
if not db.setreport(report, client_machine, server_machine):
print "report %s already in database" % report
sys.exit(1)
print "Adding report %s to the database" % db.report
r = latencies_per_rate_report(report)
metrics = [ "min", "max", "avg" ]
for metric in range(len(metrics)):
metric_rates = {}
for rate in r.rates.keys():
metric_rates[rate] = r.rates[rate][metric]
db.insert_latency_per_rate(metrics[metric], metric_rates)
if os.access("/proc/lock_stat", os.F_OK) and \
os.access("lock_stat/last", os.F_OK):
os.rename("lock_stat/last", "lock_stat/%d.txt" % db.report)
os.rename(report, "reports/%s/%d" % (appname, db.report))