import repository from arizona
[raven.git] / tools / phonehome / reportrecur.py
1 import os, sys, time
2 import report
3
4 glo_hosts = {}
5
6 def sort_nodes():
7    global glo_hosts
8
9    glo_hosts = {}
10
11    host_colnum = report.list_find(report.glo_colnames, "hostname")
12    if host_colnum < 0:
13        print "unknown colname: hostname"
14        return
15
16    # generate a dictionary based on hostname
17    
18    for result in report.glo_good_results:
19        host = result[host_colnum]
20
21        host_stats = glo_hosts.get(host, None)
22        if not host_stats:
23           host_stats = []
24           glo_hosts[host] =  host_stats
25
26        host_stats.append(result)
27
28    report.glo_compare_colnum = report.list_find(report.glo_colnames, "tinstall")
29    if report.glo_compare_colnum < 0:
30        print "unknown colname: tinstall"
31        return
32
33    for hostname in glo_hosts.keys():
34        host_stats = glo_hosts[hostname]
35        host_stats.sort(report.result_compare)
36
37 def write_graph(host_stats, colindex):
38    global glo_colnames
39
40    try:
41        f = open("/tmp/history.dat", "w")
42    except:
43        print "failed to write histogram data file"
44        return
45
46    for results in host_stats:
47        timestamp = results[4]
48
49        if (results[colindex]>=0):
50           ltime = time.localtime(float(timestamp))
51           timefmt = str(ltime[0]) + "/" + str(ltime[1]) + "/" + str(ltime[2]) + \
52                         "_" + str(ltime[3]) + ":" + str(ltime[4])
53
54           f.write(str(timefmt) + " " + str(results[colindex]) + "\n")
55
56    f.close()
57
58 def report_graph(host_stats, colname, colindex, title, pngname):
59    write_graph(host_stats, colindex)
60
61    f = open("/tmp/history.gnuplot", "w")
62    f.write('set output "' + pngname + '"\n')
63    f.write('set term png\n')
64    f.write('set ylabel "' + colname + ' (seconds)"\n')
65    f.write('set xlabel "date"\n')
66    f.write('set xdata time\n')
67    f.write('set timefmt "%Y/%m/%d_%H:%M"\n')
68    f.write('plot "/tmp/history.dat" using 1:2 with linespoints\n')
69    f.close()
70
71    os.system("gnuplot < /tmp/history.gnuplot")
72
73    print '<h2>' + title + '</h2>'
74    print '<br><img src="' + os.path.basename(pngname) + '"><br>'
75
76 def report_node(hostname):
77    host_stats = glo_hosts[hostname]
78
79    print "<h2>" + str(hostname)+ "</h2>"
80
81    columns = ["hostname", "status", "ctime_tinstall", "tbenchelap"]
82
83    print "<table>"
84
85    # a header row, to name our columns
86    print "<tr>",
87    for colname in columns:
88        print "<td>" + colname + "</td>",
89    print "</tr>"
90
91    for result in host_stats:
92        report.print_results(result[4], result, columns)
93
94    print "</table>"
95
96    colname = "tbenchelap"
97    colnum = report.list_find(report.glo_colnames, colname)
98    if colnum < 0:
99       print "unknown colname: hostname"
100       return
101
102    pngname = "/repository/phonehome/" + glo_name + "_" + glo_slicename + "_" + hostname + "_recur" + ".png"
103
104    report_graph(host_stats, colname, colnum, "benchmark run time", pngname)
105
106 def report_nodes():
107    for hostname in glo_hosts.keys():
108       report_node(hostname)
109
110 def main():
111    global glo_name
112    global glo_slicename
113
114    name = "smbphonehome_tar"
115    slicename = "arizona_stork_install"
116    timestamp = None
117
118    if len(sys.argv)>1:
119        slicename = sys.argv[1]
120
121    if len(sys.argv)>2:
122        name = sys.argv[2]
123
124    # some of the names are a  little misleading, so fix them up
125    if name == "smbphonehome_tar":
126        title = "install"
127    elif name == "cpubench":
128        title = "sieve"
129    else:
130        title = name
131
132    glo_name = name
133    glo_slicename = slicename
134
135    print "<h1>" + str(title) + " recur report for " + slicename + "</h1>"
136
137    report.read(name, slicename)
138
139    sort_nodes()
140
141    report_nodes()
142
143 if __name__ == "__main__":
144    main()