summaryrefslogtreecommitdiffstats
path: root/rteval/hackbench.py
blob: df28bec28b15dfbb4f831f9978c6f7227b1545e3 (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
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
#  
#   hackbench.py - class to manage an instance of hackbench load
#
#   Copyright 2009   Clark Williams <williams@redhat.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
#
#   For the avoidance of doubt the "preferred form" of this code is one which
#   is in an open unpatent encumbered format. Where cryptographic key signing
#   forms part of the process of creating an executable the information
#   including keys needed to generate an equivalently functional executable
#   are deemed to be part of the source code.
#

import sys
import os
import time
import glob
import subprocess
from signal import SIGTERM
sys.pathconf = "."
import load

class Hackbench(load.Load):
    def __init__(self, builddir=None, srcdir=None, debug=False, num_cpus=1, params={}):
        load.Load.__init__(self, "hackbench", builddir, srcdir, debug, num_cpus, params)

    def __del__(self):
        null = open("/dev/null", "w")
        subprocess.call(['killall', '-9', 'hackbench'], 
                        stdout=null, stderr=null)

    def setup(self):
        # find our tarball
        if self.params.has_key('source'):
            self.source = os.path.join(self.srcdir, self.params.source)
            if not os.path.exists(self.source):
                raise RuntimeError, "hackbench: source %s does not exist!" % self.source
        else:
            tarfiles = glob.glob(os.path.join(self.srcdir, "hackbench*"))
            if len(tarfiles):
                self.source = tarfiles[0]
        # check for existing directory
        self.mydir = os.path.join(self.builddir, "hackbench")
        if not os.path.exists(self.mydir):
            self.debug("setting up hackbench self.source")
            tarargs = ['tar', '-C', self.builddir, '-x']
            if self.source.endswith(".bz2"):
                tarargs.append("-j")
            elif self.source.endswith(".gz"):
                tarargs.append("-z")
            tarargs.append("-f")
            tarargs.append(self.source)

            self.debug("unpacking %s into %s" % (self.source, self.mydir))
            try:
                subprocess.call(tarargs)
            except:
                print "untar'ing hackbench failed!"
                sys.exit(-1)
            if not os.path.exists(self.mydir):
                raise RuntimeError, 'no hackbench directory!'

    def build(self):
        self.debug("building")
        null = os.open("/dev/null", os.O_RDWR)
        # clean up from potential previous run
        exe = os.path.join(self.mydir, "hackbench")
        if os.path.exists(exe):
            os.remove(exe)
        subprocess.call(["make", "-C", self.mydir], 
                              stdin=null, stdout=null, stderr=null)
        self.debug("built")
        self.ready = True

    def runload(self):
        exe = os.path.join(self.mydir, "hackbench")
        if not os.path.exists(exe):
            self.debug("Can't find exe!")
            return
        mult = 1
        if self.params.has_key('jobspercore'):
            mult = int(self.params.jobspercore)
        jobs = self.num_cpus * mult
        null = os.open("/dev/null", os.O_RDWR)
        self.debug("starting loop (jobs: %d)" % jobs)
        self.args = [exe, str(jobs)]
        p = subprocess.Popen(self.args, stdin=null,stdout=null,stderr=null)
        while not self.stopevent.isSet():
            time.sleep(1.0)
            if p.poll() != None:
                p.wait()
                p = subprocess.Popen(self.args,stdin=null,stdout=null,stderr=null)
        self.debug("stopping")
        os.kill(p.pid, SIGTERM)

    def genxml(self, x):
        x.taggedvalue('command_line', ' '.join(self.args), {'name':'hackbench'})

def create(builddir, srcdir, debug, num_cpus, params = {}):
    return Hackbench(builddir, srcdir, debug, num_cpus, params)