#!/usr/bin/python # Copyright 2015 Lars Wirzenius # # 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 3 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, see . # # =*= License: GPL-3+ =*= import os import cliapp import ttystatus import yaml import obbenchlib class ObnamBenchmarker(cliapp.Application): def add_settings(self): self.settings.string( ['state'], 'keep state in DIR between runs', metavar='DIR', default='.') def process_args(self, args): spec = self.read_benchmark_spec(args[0]) statedir = self.create_state_directory() self.clone_or_update_git(statedir, spec) self.run_benchmarks(statedir, spec, args[1:]) self.produce_html(statedir, spec) def read_benchmark_spec(self, filename): with open(filename) as f: return yaml.safe_load(f) def create_state_directory(self): statedir = self.settings['state'] if not os.path.exists(statedir): os.mkdir(statedir) return statedir def clone_or_update_git(self, statedir, spec): gitdir = self.gitdir(statedir) if os.path.exists(gitdir): cliapp.runcmd(['git', 'pull'], cwd=gitdir) else: cliapp.runcmd(['git', 'clone', spec['git'], gitdir]) def gitdir(self, statedir): return os.path.join(statedir, 'git') def run_benchmarks(self, statedir, spec, refs): benchmarker = obbenchlib.Benchmarker() benchmarker.statedir = statedir benchmarker.gitdir = self.gitdir(statedir) benchmarker.resultdir = self.resultdir(statedir) benchmarker.spec = spec for ref in refs: benchmarker.run_benchmarks(ref) def resultdir(self, statedir): return os.path.join(statedir, 'results') def produce_html(self, statedir, spec): print 'Producing HTML' gen = obbenchlib.HtmlGenerator() gen.statedir = statedir gen.resultdir = self.resultdir(statedir) gen.gitdir = self.gitdir(statedir) gen.spec = spec gen.generate_html() if __name__ == '__main__': ObnamBenchmarker().run()