summaryrefslogtreecommitdiff
path: root/tools/parsebench.py
blob: fdaed56638fa523c77a95eebfa785e1691ee9f56 (plain)
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
#!/usr/bin/env python

# Copyright (c) 2015-2016, NORDUnet A/S.
# See LICENSE for licensing information.

import argparse
import sys
import ast
import itertools

def parse_one_line(line):
    row = line.rstrip().split(":")
    assert row[0].startswith("bench-")
    iteration = int(row[0][6:])
    stage = row[2].strip()
    data = ast.literal_eval(row[3].strip())
    return (iteration, stage, data)

def main():
    parser = argparse.ArgumentParser(description="")
    parser.add_argument('inputfile', help="Input file", nargs='*')
    args = parser.parse_args()
    print "<!DOCTYPE html>"
    print "<html>"
    print "<head>"
    print "</head>"
    print "<body>"
    for filename in args.inputfile:
        parse_one_file(filename)
    print "</body>"
    print "</html>"

scale = 0.25

def parse_one_file(filename):
    lines = [parse_one_line(line) for line in open(filename)]
    iterations = itertools.groupby(lines, lambda x: x[0])
    print "<h1>%s</h1>" % (filename,)
    print "<div>"
    firsttime = True

    stageorderdict = {}
    stageorder = []
    stages = {}
    itemorder = {}

    for (i, iteration) in iterations:
        for (_, stage, data) in iteration:
            if stage not in stages:
                stageorderdict[stage] = len(stageorderdict)
                stageorder.append(stage)
                stages[stage] = {}
                itemorder[stage] = []
            for (item, useconds) in data:
                if item not in stages[stage]:
                    itemorder[stage].append(item)
                    stages[stage][item] = len(stages[stage])

    iterations = itertools.groupby(lines, lambda x: x[0])
    for (i, iteration) in iterations:
        print >>sys.stderr,  (i, iteration)
        sys.stdout.write("<div style='margin-bottom: 1em;'>")
        for (_, stage, data) in iteration:
            data = list(data)
            for (itemn, (item, useconds)) in enumerate(data):
                seconds = useconds / 1000000
                shades = stages[stage]
                step = 50 / (len(shades) - 1)
                shade = shades[item]
                stagen = stageorderdict[stage]
                print "<div class='element' style='display: inline-block; margin: 0; width: %dpx; padding: 0; background-color: hsl(%d, 90%%, %d%%);' title='%s:%s %d'>" % (int(seconds*scale), stagen * 90, shade * step + 40, stage, item, seconds)
                print "&nbsp;"
                sys.stdout.write("</div>")
        sys.stdout.write("</div>")
    print "</div>"
    print "<div style='height: 30px;'>"
    print "</div>"
    print "<div>"

    for stage in stageorder:
        print "<div><span>%s</span>" % (stage,)
        shades = stages[stage]
        for item in itemorder[stage]:
            shade = shades[item]
            step = 50 / (len(shades) - 1)

            stagen = stageorderdict[stage]
            print "<span style='background-color: hsl(%d, 90%%, %d%%);'>%s</span>" % (stagen * 90, shade * step + 40, item)
        print "</div>"
    print "</div>"

main()