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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#=====================================================
# Copyright (C) 2011-2012 Andrea Arteaga <andyspiros@gmail.com>
#=====================================================
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import os, time
from os.path import join as pjoin, basename, exists
from xml.sax.saxutils import escape as xmlescape
from .. import benchconfig as cfg
class ReportFile:
def __init__(self, fname, title='Benchmarks report', inputfile=None):
if inputfile is None:
inputfile = pjoin(cfg.reportdir, basename(cfg.inputfile))
self.fname = fname
self.content = """
<html>
<head>
<title>""" + title + """</title>
<style type="text/css">
body {
background-color: #FFFFFF;
}
img {
height:80%;
}
pre {
background-color: #EEE;
}
h1, h2, .plot, .descr, .info {
text-align: center;
}
.inputfile {
margin-bottom: 40px;
}
.fig {
margin-bottom: 50px;
padding-top: 20px;
padding-bottom: 20px;
}
</style>
</head>
<body>
<h1>""" + title + "</h1>"
date = time.strftime('%Y-%m-%d, %I:%M %p')
self.content += '<p class="info">Generated on ' + date + '</p>'
# Information regarding the CPU
cpuinfo = file('/proc/cpuinfo', 'r').readlines()
cpu = None
corecount = 0
for l in cpuinfo:
if l.startswith('model name'):
cpu = l.split(':', 1)[1].strip()
if l.startswith('processor'):
corecount += 1
if cpu:
self.content += '<p class="info">CPU: ' + cpu + \
' (' + str(corecount) + ' cores)</p>'
# Information regarding the memory
meminfo = file('/proc/meminfo', 'r').readlines()
mem = None
for l in meminfo:
if l[:8] == 'MemTotal':
mem = l.split(':', 1)[1].strip()
if mem:
self.content += '<p class="info">Total memory: ' + mem + '</p>'
# Information regarding the caches
cachedir = '/sys/devices/system/cpu/cpu0/cache'
if exists(cachedir):
self.content += '<p class="info">Caches:<br />'
for i in os.listdir(cachedir):
cdir = pjoin(cachedir, i)
ctxt = 'L' + file(pjoin(cdir, 'level')).read().strip()
ctxt += ' ' + file(pjoin(cdir, 'type')).read().strip()
ctxt += ': ' + file(pjoin(cdir, 'size')).read().strip()[:-1]
self.content += ctxt + ' kB<br />'
self.content += '</p>'
# Input file
self.content += '<div class="inputfile">Input file: ' + \
'<a href="%s">%s</a>' % (basename(inputfile), cfg.inputfile) + \
'<pre>%s</pre></div>' % xmlescape(file(cfg.inputfile, 'r').read())
self.content += '<div class="log">Logs: <a href="log">%s</a></div>' \
% cfg.logdir
def addFig(self, title, image, descr='', alt='', width=None):
self.content += '<div class="fig">'
self.content += '<h2>' + title + '</h2>'
if descr.strip() != '':
self.content += '<p class="descr">' + descr + '</p>'
self.content += '<div class="plot">'
self.content += '<a href="' + image + '">'
self.content += '<img src="' + image + '" alt="' + alt + '"'
if width is not None:
self.content += ' style="width:' + str(width) + '; height:auto"'
self.content += ' /></a>'
self.content += '</div>'
self.content += '</div><hr />'
def close(self):
self.content += '</body></html>'
f = file(self.fname, 'w')
f.write(self.content)
f.close()
self.content = ''
|