#===================================================== # Copyright (C) 2011-2012 Andrea Arteaga #===================================================== # # 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 = """ """ + title + """

""" + title + "

" date = time.strftime('%Y-%m-%d, %I:%M %p') self.content += '

Generated on ' + date + '

' # 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 += '

CPU: ' + cpu + \ ' (' + str(corecount) + ' cores)

' # 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 += '

Total memory: ' + mem + '

' # Information regarding the caches cachedir = '/sys/devices/system/cpu/cpu0/cache' if exists(cachedir): self.content += '

Caches:
' 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
' self.content += '

' # Input file self.content += '
Input file: ' + \ '%s' % (basename(inputfile), cfg.inputfile) + \ '
%s
' % xmlescape(file(cfg.inputfile, 'r').read()) self.content += '
Logs: %s
' \ % cfg.logdir def addFig(self, title, image, descr='', alt='', width=None): self.content += '
' self.content += '

' + title + '

' if descr.strip() != '': self.content += '

' + descr + '

' self.content += '
' self.content += '' self.content += '