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
|
#!/usr/bin/python
import sys
def parse_block(lines):
r = {
'reqs': int(lines[0].split()[1]),
'freqs': {}
}
for line in lines[1:]:
if line == 'cpu0':
continue
if line == 'cpu1':
break
freq, delta = line.strip().split()
r['freqs'][int(freq)] = int(delta[1:])
return r
def parse_file(filename):
raw_blocks = open(filename, 'rU').read().split('\n\n')
blocks = []
for raw_block in raw_blocks:
if raw_block:
blocks.append(parse_block(raw_block.splitlines()))
return blocks
def format_header(block):
r = '<tr>'
r += '<th>requests</th>'
for k in sorted(block['freqs']):
r += '<th><span>%s</span></th>' % k
r += '</tr>\n'
return r
def format_block(block):
r = '<tr>'
r += '<td>%s</td>' % block['reqs']
for k in sorted(block['freqs']):
r += '<td>%s</td>' % block['freqs'][k]
r += '</tr>\n'
return r
def format_blocks(blocks):
r = '<table>\n'
r += format_header(blocks[0])
for block in blocks:
r += format_block(block)
r += '</table>\n'
return r
header = '''\
<html>
<head>
<style>
table {
padding-top: 4em;
}
th span {
font-size: smaller;
width: 1.2em;
white-space: nowrap;
color: #000;
display: block;
-moz-transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
}
</style>
</head>
<body>
'''
def main(fname):
blocks = parse_file(fname)
print header
print format_blocks(blocks)
print '</html>'
if __name__ == '__main__':
main(sys.argv[1])
|