diff options
author | David Sommerseth <davids@redhat.com> | 2012-12-05 01:49:46 +0100 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2012-12-05 02:11:50 +0100 |
commit | bb12bc71d37688e01749368467c256f662d4f937 (patch) | |
tree | 62675681a869c86ea757c3aec0b6facb5fa6a40a /rteval/modules/loads | |
parent | 36fa5034206c96ad8f053146b48e0f69de7d7998 (diff) | |
download | rteval-bb12bc71d37688e01749368467c256f662d4f937.tar.gz rteval-bb12bc71d37688e01749368467c256f662d4f937.tar.xz rteval-bb12bc71d37688e01749368467c256f662d4f937.zip |
Adopted kcompile and hackbench modules to use the new API from rtevalModulePrototype
These modules also need some more clean-up when we get further.
Signed-off-by: David Sommerseth <davids@redhat.com>
Diffstat (limited to 'rteval/modules/loads')
-rw-r--r-- | rteval/modules/loads/hackbench.py | 136 | ||||
-rw-r--r-- | rteval/modules/loads/kcompile.py | 105 |
2 files changed, 131 insertions, 110 deletions
diff --git a/rteval/modules/loads/hackbench.py b/rteval/modules/loads/hackbench.py index 12ca47d..bf514b9 100644 --- a/rteval/modules/loads/hackbench.py +++ b/rteval/modules/loads/hackbench.py @@ -1,8 +1,8 @@ # # hackbench.py - class to manage an instance of hackbench load # -# Copyright 2009,2010 Clark Williams <williams@redhat.com> -# Copyright 2009,2010 David Sommerseth <davids@redhat.com> +# Copyright 2009 - 2012 Clark Williams <williams@redhat.com> +# Copyright 2009 - 2012 David Sommerseth <davids@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 @@ -25,29 +25,18 @@ # are deemed to be part of the source code. # -import sys -import os -import time -import glob -import subprocess -import errno -from signal import SIGTERM -from signal import SIGKILL +import sys, os, time, glob, subprocess, errno +from signal import SIGTERM, SIGKILL from modules.loads import CommandLineLoad from Log import Log class Hackbench(CommandLineLoad): - def __init__(self, params, logger): - CommandLineLoad.__init__(self, "hackbench", params, logger) + def __init__(self, config, logger): + CommandLineLoad.__init__(self, "hackbench", config, logger) - def __del__(self): - null = open("/dev/null", "w") - subprocess.call(['killall', '-9', 'hackbench'], - stdout=null, stderr=null) - os.close(null) - def setup(self): + def _WorkloadSetup(self): 'calculate arguments based on input parameters' (mem, units) = self.memsize if units == 'KB': @@ -58,7 +47,7 @@ class Hackbench(CommandLineLoad): mem = mem * 1024 ratio = float(mem) / float(self.num_cpus) if ratio >= 0.75: - mult = float(self.params.setdefault('jobspercore', 2)) + mult = float(self._cfg.setdefault('jobspercore', 2)) else: self._log(Log.INFO, "hackbench: low memory system (%f GB/core)! Not running\n" % ratio) mult = 0 @@ -66,62 +55,79 @@ class Hackbench(CommandLineLoad): self.args = ['hackbench', '-P', '-g', str(self.jobs), - '-l', str(self.params.setdefault('loops', '100')), - '-s', str(self.params.setdefault('datasize', '100')) + '-l', str(self._cfg.setdefault('loops', '100')), + '-s', str(self._cfg.setdefault('datasize', '100')) ] - self.err_sleep = 5.0 + self.__err_sleep = 5.0 - def build(self): - self.ready = True - def start_hackbench(self, inf, outf, errf): - self._log(Log.DEBUG, "running: %s" % " ".join(self.args)) - return subprocess.Popen(self.args, stdin=inf, stdout=outf, stderr=errf) + def _WorkloadBuild(self): + # Nothing to build, so we're basically ready + self._setReady() + - def runload(self): + def _WorkloadPrepare(self): # if we don't have any jobs just wait for the stop event and return if self.jobs == 0: - self.stopevent.wait() + self.WaitForCompletion() return - null = os.open("/dev/null", os.O_RDWR) - if self.logging: - out = self.open_logfile("hackbench.stdout") - err = self.open_logfile("hackbench.stderr") + + self.__nullfp = os.open("/dev/null", os.O_RDWR) + if self._logging: + self._out = self.open_logfile("hackbench.stdout") + self._err = self.open_logfile("hackbench.stderr") else: - out = err = null + self.__out = self.__err = self.__nullfp + self._log(Log.DEBUG, "starting loop (jobs: %d)" % self.jobs) - p = self.start_hackbench(null, out, err) - while not self.stopevent.isSet(): - try: - # if poll() returns an exit status, restart - if p.poll() != None: - p = self.start_hackbench(null, out, err) - time.sleep(1.0) - except OSError, e: - if e.errno != errno.ENOMEM: - raise e - # Catch out-of-memory errors and wait a bit to (hopefully) - # ease memory pressure - self._log(Log.DEBUG, "hackbench: %s, sleeping for %f seconds" % (e.strerror, self.err_sleep)) - time.sleep(self.err_sleep) - if self.err_sleep < 60.0: - self.err_sleep *= 2.0 - if self.err_sleep > 60.0: - self.err_sleep = 60.0 - - self._log(Log.DEBUG, "stopping") - if p.poll() == None: - os.kill(p.pid, SIGKILL) - p.wait() - self._log(Log.DEBUG, "returning from runload()") - os.close(null) - if self.logging: - os.close(out) - os.close(err) - -def create(params, logger): - return Hackbench(params, logger) + + def _WorkloadTask(self): + if self.shouldStop(): + return + + self._log(Log.DEBUG, "running: %s" % " ".join(self.args)) + try: + self.__hbproc = subprocess.Popen(self.args, + stdin=self.__nullfp, + stdout=self.__out, + stderr=self.__err) + except OSError, e: + if e.errno != errno.ENOMEM: + raise e + # Catch out-of-memory errors and wait a bit to (hopefully) + # ease memory pressure + self._log(Log.DEBUG, "hackbench: %s, sleeping for %f seconds" % (e.strerror, self.__err_sleep)) + time.sleep(self.__err_sleep) + if self.__err_sleep < 60.0: + self.__err_sleep *= 2.0 + if self.__err_sleep > 60.0: + self.__err_sleep = 60.0 + + + def _WorkloadAlive(self): + # As hackbench is short-lived, lets pretend it is always alive + return True + + + def _WorkloadCleanup(self): + if self.__hbproc.poll() == None: + os.kill(self.__hbproc.pid, SIGKILL) + self.__hbproc.wait() + + os.close(self.__nullfp) + if self._logging: + os.close(self.__out) + del self.__out + os.close(self.__err) + del self.__err + + del self.__hbproc + del self.__nullfp + + +def create(config, logger): + return Hackbench(config, logger) if __name__ == '__main__': diff --git a/rteval/modules/loads/kcompile.py b/rteval/modules/loads/kcompile.py index 1c8146a..d43e523 100644 --- a/rteval/modules/loads/kcompile.py +++ b/rteval/modules/loads/kcompile.py @@ -1,5 +1,6 @@ # -# Copyright 2009,2010 Clark Williams <williams@redhat.com> +# Copyright 2009 - 2012 Clark Williams <williams@redhat.com> +# Copyright 2012 David Sommerseth <davids@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 @@ -21,11 +22,7 @@ # 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 +import sys, os, glob, subprocess from signal import SIGTERM from modules.loads import CommandLineLoad from Log import Log @@ -33,14 +30,14 @@ from Log import Log kernel_prefix="linux-2.6" class Kcompile(CommandLineLoad): - def __init__(self, params, logger): - CommandLineLoad.__init__(self, "kcompile", params, logger) + def __init__(self, config, logger): + CommandLineLoad.__init__(self, "kcompile", config, logger) - def setup(self): + def _WorkloadSetup(self): # find our source tarball - if self.params.has_key('tarball'): - tarfile = os.path.join(self.srcdir, self.params.tarfile) + if self._cfg.has_key('tarball'): + tarfile = os.path.join(self.srcdir, self._cfg.tarfile) if not os.path.exists(tarfile): raise RuntimeError, " tarfile %s does not exist!" % tarfile self.source = tarfile @@ -85,10 +82,10 @@ class Kcompile(CommandLineLoad): self._log(Log.DEBUG, "mydir = %s" % self.mydir) - def build(self): + def _WorkloadBuild(self): self._log(Log.DEBUG, "setting up all module config file in %s" % self.mydir) null = os.open("/dev/null", os.O_RDWR) - if self.logging: + if self._logging: out = self.open_logfile("kcompile-build.stdout") err = self.open_logfile("kcompile-build.stderr") else: @@ -104,15 +101,15 @@ class Kcompile(CommandLineLoad): self._log(Log.DEBUG, "keyboard interrupt, aborting") return self._log(Log.DEBUG, "ready to run") - self.ready = True os.close(null) - if self.logging: + if self._logging: os.close(out) os.close(err) + self._setReady() - def calc_numjobs(self): - mult = int(self.params.setdefault('jobspercore', 1)) + def __calc_numjobs(self): + mult = int(self._cfg.setdefault('jobspercore', 1)) mem = self.memsize[0] if self.memsize[1] == 'KB': mem = mem / (1024.0 * 1024.0) @@ -128,37 +125,55 @@ class Kcompile(CommandLineLoad): njobs = self.num_cpus return njobs - def runload(self): - null = os.open("/dev/null", os.O_RDWR) - if self.logging: - out = self.open_logfile("kcompile.stdout") - err = self.open_logfile("kcompile.stderr") + + def _WorkloadPrepare(self): + self.__nullfd = os.open("/dev/null", os.O_RDWR) + if self._logging: + self.__outfd = self.open_logfile("kcompile.stdout") + self.__errfd = self.open_logfile("kcompile.stderr") else: - out = err = null + self.__outfd = self.__errfd = self.__nullfd + + self.jobs = self.__calc_numjobs() + self._log(Log.DEBUG, "starting loop (jobs: %d)" % self.jobs) + self.args = ["make", "-C", self.mydir, + "-j%d" % self.jobs ] + self.__kcompileproc = None + + + def _WorkloadTask(self): + if not self.__kcompileproc or self.__kcompileproc.poll() is not None: + # If kcompile has not been kicked off yet, or have completed, + # restart it + self._log(Log.DEBUG, "Kicking off kcompile: %s" % " ".join(self.args)) + self.__kcompileproc = subprocess.Popen(self.args, + stdin=self.__nullfd, + stdout=self.__outfd, + stderr=self.__errfd) - njobs = self.calc_numjobs() - self._log(Log.DEBUG, "starting loop (jobs: %d)" % njobs) - self.args = ["make", "-C", self.mydir, - "-j%d" % njobs ] - p = subprocess.Popen(self.args, - stdin=null,stdout=out,stderr=err) - while not self.stopevent.isSet(): - time.sleep(1.0) - if p.poll() != None: - r = p.wait() - self._log(Log.DEBUG, "restarting compile job (exit status: %s)" % r) - p = subprocess.Popen(self.args, - stdin=null,stdout=out,stderr=err) + + def _WorkloadAlive(self): + # Let _WorkloadTask() kick off new runs, if it stops - thus + # kcompile will always be alive + return True + + + def _WorkloadCleanup(self): self._log(Log.DEBUG, "out of stopevent loop") - if p.poll() == None: + if self.__kcompileproc.poll() == None: self._log(Log.DEBUG, "killing compile job with SIGTERM") - os.kill(p.pid, SIGTERM) - p.wait() - os.close(null) - if self.logging: - os.close(out) - os.close(err) + os.kill(self.__kcompileproc.pid, SIGTERM) + self.__kcompileproc.wait() + os.close(self.__nullfd) + del self.__nullfd + if self._logging: + os.close(self.__outfd) + del self.__outfd + os.close(self.__errfd) + del self.__errfd + del self.__kcompileproc + self._setFinished() -def create(params, logger): - return Kcompile(params, logger) +def create(config, logger): + return Kcompile(config, logger) |