summaryrefslogtreecommitdiff
path: root/obbench
blob: 63cce319826f0c424602562bc7c13550e4582fc3 (plain)
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
#!/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 <http://www.gnu.org/licenses/>.
#
# =*= License: GPL-3+ =*=


import os

import cliapp
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):
        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()