-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats2csv.py
executable file
·57 lines (48 loc) · 1.3 KB
/
stats2csv.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
#!/usr/bin/env python
import csv
import os
import sys
import cPickle as pickle
def main():
names, stats = load_stats_files()
get_cols = [ 'get %s' % n for n in names ]
put_cols = [ 'put %s' % n for n in names ]
cols = get_cols + put_cols
writer = csv.DictWriter(open('stats.csv', 'w'), cols)
writer.writerows(rows(names, stats))
def load_stats_files():
names = []
stats = []
fnames = sys.argv[1:]
for fn in fnames:
stats.append(pickle.load(open(fn, 'r')))
names.append(fn)
return names, stats
def rows(names, stats):
r = 0
while True:
row = {}
for ix, s in enumerate(stats):
get_col = 'get %s' % names[ix]
put_col = 'put %s' % names[ix]
try:
row[get_col] = s['get'][r]
except IndexError:
row[get_col] = None
try:
row[put_col] = s['put'][r]
except IndexError:
row[put_col] = None
any = False
for k, v in row.items():
if v is not None:
any = True
break
if not any:
raise StopIteration
yield row
if r % 100 == 0:
print r,
r = r + 1
if __name__ == '__main__':
main()