public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Andrea Arteaga" <andyspiros@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/auto-numerical-bench:master commit in: /, app-benchmarks/autobench/files/python/
Date: Fri,  1 Jul 2011 19:01:12 +0000 (UTC)	[thread overview]
Message-ID: <ad64b45944c791e851d724a75ed4d5da87440af8.spiros@gentoo> (raw)

commit:     ad64b45944c791e851d724a75ed4d5da87440af8
Author:     spiros <andyspiros <AT> gmail <DOT> com>
AuthorDate: Fri Jul  1 19:00:44 2011 +0000
Commit:     Andrea Arteaga <andyspiros <AT> gmail <DOT> com>
CommitDate: Fri Jul  1 19:00:44 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/auto-numerical-bench.git;a=commit;h=ad64b459

Added html report.

---
 .gitignore                                         |    2 -
 app-benchmarks/autobench/files/python/btlbase.py   |   86 ++++++++++++++++++--
 app-benchmarks/autobench/files/python/btlutils.py  |   41 ---------
 .../autobench/files/python/htmlreport.py           |   57 +++++++++++++
 4 files changed, 136 insertions(+), 50 deletions(-)

diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 38ab2bd..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/.project
-/.pydevproject
\ No newline at end of file

diff --git a/app-benchmarks/autobench/files/python/btlbase.py b/app-benchmarks/autobench/files/python/btlbase.py
index d9a911a..d71650e 100644
--- a/app-benchmarks/autobench/files/python/btlbase.py
+++ b/app-benchmarks/autobench/files/python/btlbase.py
@@ -2,6 +2,7 @@ import sys, os, shlex
 import commands as cmd
 import subprocess as sp
 from os.path import join as pjoin
+from htmlreport import HTMLreport
 
 try:
     import matplotlib.pyplot as plt
@@ -12,11 +13,75 @@ except ImportError:
       'in order to generate the reports!\n')
     sys.stderr.write('Continue anyway.\n\n')    
     with_images = False
-    
-import btlutils as btl
 
 run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0]
 
+def btlcompile(exe, source, btldir, includes, defines, libs, libdirs, other, \
+  logfile=None):
+    """
+    Helper function that compiles a C++ source based on btl. The function
+    sets the compiler flags that are needed by btl (include directives, link
+    with rt,...). More options are accepted as arguments:
+    
+    exe: the generated executable
+    
+    source: the C++ source
+    
+    btldir: the base directory of the btl sources
+    
+    includes: an iterable containing the include directories (without -I)
+    
+    defines: an iterable of strings with define directives (without -D). In case
+    of key-value pairs, the equal sign and the value have to be in the same
+    string as the key: ['NDEBUG', 'FOO=BAR'] is transormed to
+    '-DNDEBUD -DFOO=BAR'
+    
+    libs: the libraries to link against (without -l)
+    
+    libdirs: the directories where the libraries are seeked (without -L)
+    
+    other: an iterable with compiler flags
+    
+    logfile: the path of the file where the log is saved. The directory must
+    exist. If None, no log is generated.
+    """
+    
+    incs = (
+      "%s/actions" % btldir,
+      "%s/generic_bench" % btldir,
+      "%s/generic_bench/utils" % btldir,
+      "%s/libs/STL" % btldir
+    ) + tuple(includes)
+    incs = ' '.join(['-I'+i for i in incs])
+    
+    defs = ' '.join(['-D'+d for d in ["NDEBUG"] + defines])
+    
+    libs = ' '.join(['-l'+l for l in ["rt"] + libs])
+    
+    libdirs = ' '.join(['-L'+L for L in libdirs])
+    
+    cxxflags = run_cmd(['portageq', 'envvar', 'CXXFLAGS']).strip()
+    
+    otherflags = ' '.join(other)
+    
+    # TODO: use CXX instead of g++
+    cl = "g++ -o %s %s %s %s %s %s %s %s" \
+        % (exe, source, incs, defs, libs, libdirs, cxxflags, otherflags)
+        
+    if logfile is None:
+        fout = sp.PIPE
+    else:
+        fout = file(logfile, 'w')
+        fout.write(cl + "\n" + 80*'-' + "\n")
+        fout.flush()
+    cl = shlex.split(cl)
+    cp = sp.Popen(cl, stdout=fout, stderr=sp.STDOUT)
+    cp.communicate()
+    if logfile is not None:
+        fout.close()
+    return (cp.returncode, ' '.join(cl))
+
+
 class BTLBase:
     def __init__(self, Print, libdir, args):
         self.Print = Print
@@ -97,7 +162,7 @@ class BTLBase:
         # TODO: use CXX instead of g++
         btldir = 'btl/'
         logfile = os.path.join(logdir, name+"_comp.log")
-        returncode, compilecl = btl.btlcompile(
+        returncode, compilecl = btlcompile(
           exe = testdir + "/test",
           source = btldir + self._btl_source(),
           btldir = btldir,
@@ -163,7 +228,11 @@ class BTLBase:
             for nameimpl in results:
                 nameimplstr = "%s/%s" % nameimpl
                 resdat = results[nameimpl][test]
-                newresults[test][nameimplstr] = resdat       
+                newresults[test][nameimplstr] = resdat
+        
+        # Begin the HTML report
+        htmlfname = pjoin(figdir, 'index.html')
+        html = HTMLreport(htmlfname)
         
         # Generate summary - a single image with all plots
         if self.summary or self.summary_only:
@@ -178,22 +247,25 @@ class BTLBase:
                     plt.semilogx(x,y, label=impl, hold=True)
                 plt.legend(loc='best')
                 plt.grid(True)
-            fname = figdir+ '/summary.png'
+            fname = pjoin(figdir, 'summary.png')
             plt.savefig(fname, format='png')
+            html.addFig("Summary", image=os.path.basename(fname), width='95%')
             self.Print('Summary figure saved: ' + fname)
                 
         # Generate plots
         if not self.summary_only:
             for test in self.tests:
                 plt.figure(figsize=(12,9), dpi=300)
-                plt.title(test)
                 for impl in newresults[test]:
                     x,y = np.loadtxt(newresults[test][impl], unpack=True)
                     plt.semilogx(x,y, label=impl, hold=True)
                 plt.legend(loc='best')
                 plt.grid(True)
-                fname = os.path.join(figdir, test+".png")
+                fname = pjoin(figdir, test+".png")
                 plt.savefig(fname, format='png')
+                html.addFig(test, image=os.path.basename(fname))
                 self.Print('Figure ' + fname + ' saved')
+        
+        html.close()
             
             

diff --git a/app-benchmarks/autobench/files/python/btlutils.py b/app-benchmarks/autobench/files/python/btlutils.py
deleted file mode 100644
index d2207cd..0000000
--- a/app-benchmarks/autobench/files/python/btlutils.py
+++ /dev/null
@@ -1,41 +0,0 @@
-import subprocess as sp
-import shlex
-
-run_cmd = lambda c : sp.Popen(c, stdout=sp.PIPE).communicate()[0]
-
-def btlcompile(exe, source, btldir, includes, defines, libs, libdirs, other, \
-  logfile=None):
-    incs = (
-      "%s/actions" % btldir,
-      "%s/generic_bench" % btldir,
-      "%s/generic_bench/utils" % btldir,
-      "%s/libs/STL" % btldir
-    ) + tuple(includes)
-    incs = ' '.join(['-I'+i for i in incs])
-    
-    defs = ' '.join(['-D'+d for d in ["NDEBUG"] + defines])
-    
-    libs = ' '.join(['-l'+l for l in ["rt"] + libs])
-    
-    libdirs = ' '.join(['-L'+L for L in libdirs])
-    
-    cxxflags = run_cmd(['portageq', 'envvar', 'CXXFLAGS']).strip()
-    
-    otherflags = ' '.join(other)
-    
-    # TODO: use CXX instead of g++
-    cl = "g++ -o %s %s %s %s %s %s %s %s" \
-        % (exe, source, incs, defs, libs, libdirs, cxxflags, otherflags)
-        
-    if logfile is None:
-        fout = sp.PIPE
-    else:
-        fout = file(logfile, 'w')
-        fout.write(cl + "\n" + 80*'-' + "\n")
-        fout.flush()
-    cl = shlex.split(cl)
-    cp = sp.Popen(cl, stdout=fout, stderr=sp.STDOUT)
-    cp.communicate()
-    if logfile is not None:
-        fout.close()
-    return (cp.returncode, ' '.join(cl))

diff --git a/app-benchmarks/autobench/files/python/htmlreport.py b/app-benchmarks/autobench/files/python/htmlreport.py
new file mode 100644
index 0000000..8241bdc
--- /dev/null
+++ b/app-benchmarks/autobench/files/python/htmlreport.py
@@ -0,0 +1,57 @@
+import time
+
+class HTMLreport:
+    def __init__(self, fname, title="Benchmarks report"):
+        self.fname = fname
+        self.content = """
+<html>
+<head>
+<title>Benchmarks report</title>
+<style type="text/css">
+body {
+  background-color: #FFFFFF;
+}
+
+img {
+  width:80%;
+}
+
+h1, h2, .plot, .descr, .date {
+  text-align: center;
+}
+
+.fig {
+   background-color: #CCCCCC;
+   margin-bottom: 50px;
+   padding-top: 20px;
+   padding-bottom: 20px;
+}
+</style>
+</head>
+<body>
+<h1>
+"""
+        self.content += title + "</h1>"
+        date = time.strftime('%Y-%m-%d, %I:%M %p')
+        self.content += '<p class="date">Generated on ' + date + '</p>'
+        
+        
+    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 += '<img src="' + image + '" alt="' + alt + '"'
+        if width is not None:
+            self.content += ' style="width:' + str(width) + '"'
+        self.content += ' />'
+        self.content += '</div>'
+        self.content += '</div>'
+        
+    def close(self):
+        self.content += "</body></html>"
+        f = file(self.fname, 'w')
+        f.write(self.content)
+        f.close()
+        self.content = ''



                 reply	other threads:[~2011-07-01 19:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ad64b45944c791e851d724a75ed4d5da87440af8.spiros@gentoo \
    --to=andyspiros@gmail.com \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox