# # # patch "speedtest.py" # from [bb4c94f9565f26aa6aeedf27477632185eba505b] # to [16e2fd46d49bca1500b688a446f7c7210198e864] # ============================================================ --- speedtest.py bb4c94f9565f26aa6aeedf27477632185eba505b +++ speedtest.py 16e2fd46d49bca1500b688a446f7c7210198e864 @@ -10,9 +10,6 @@ if not os.path.exists(path): os.makedirs(path) -def clear_caches(): - pass - class Process(object): # We stuff the called process into its own process group using the # preexec_fn hack. We need to do this so that we can clean up @@ -50,7 +47,7 @@ self.klass = klass self.repeats = repeats - def make(self, record_dir): + def new(self, record_dir): return self.klass(record_dir) class Instrumenter(object): @@ -289,73 +286,84 @@ class Driver(object): - def __init__(self, scratch, results, testables, benchmarks, instrumenters, debug): + def __init__(self, scratch, results, testables, benchmarks, instrumenters, + debug, cache_clearer): self.scratch = os.path.abspath(scratch) self.results = os.path.abspath(results) self.testables = testables self.benchmarks = benchmarks self.instrumenters = instrumenters self.debug = debug + self.cache_clearer = cache_clearer def run(self): startdir = os.getcwd() - # FIXME: now make it actually use the self.instrumenters variable... - # also, give things names -- I guess by turning these things into - # dicts - # also, figure out some instance/class/factory naming scheme that - # makes sense - instrumenter_factory = InstrumenterFactory(TimingInstrumenter, 2) - i = 0 - for benchmark in self.benchmarks: - i += 1 - benchdir = os.path.join(self.scratch, str(i)) + for benchmark_name, benchmark_obj in self.benchmarks.iteritems(): + benchdir = os.path.join(self.scratch, benchmark_name) - for j in xrange(len(self.testables)): - testable = self.testables[j].new(Instrumenter("")) - setupdir = os.path.join(benchdir, "setup-" + str(j)) + instrumenters = {} + for testable_name, testable_f in self.testables.iteritems(): + testable = testable_f.new(Instrumenter("")) + setupdir = os.path.join(benchdir, "setup-" + testable_name) ensure_dir(setupdir) os.chdir(setupdir) testable.setup() - benchmark.setup(testable) + benchmark_obj.setup(testable) - instrumenters = [] - for j in xrange(len(self.testables)): - recorddir = os.path.join(self.results, "%s-%s" % (i, j)) - instrumenters.append(instrumenter_factory.make(recorddir)) - for repeat in xrange(instrumenter_factory.repeats): - plan = range(len(self.testables)) - random.shuffle(plan) - for j in plan: - instrumenter = instrumenters[j] - testable = self.testables[j].new(instrumenter) - rundir = os.path.join(benchdir, "run-%s-%s" % (j, repeat)) - shutil.copytree(os.path.join(benchdir, "setup-" + str(j)), - rundir) - os.chdir(rundir) - clear_caches() - benchmark.run(testable) - instrumenter.flush() - if not self.debug: - os.chdir(startdir) - shutil.rmtree(rundir) + for instrumenter_name, instrumenter_f in self.instrumenters.iteritems(): + instrumenters = {} + for testable_name in self.testables: + recorddir = os.path.join(self.results, + "%s-%s-%s" % (benchmark_name, + testable_name, + instrumenter_name)) + instrumenters[testable_name] = instrumenter_f.new(recorddir) - if not self.debug: - for j in xrange(len(self.testables)): - shutil.rmtree(os.path.join(benchdir, "setup-" + str(j))) + for repeat in xrange(instrumenter_f.repeats): + plan = self.testables.keys() + random.shuffle(plan) + for testable_name in plan: + instrumenter = instrumenters[testable_name] + testable = self.testables[testable_name].new(instrumenter) + rundir = os.path.join(benchdir, + "run-%s-%s-%s" % (testable_name, + instrumenter_name, + repeat)) + shutil.copytree(os.path.join(benchdir, + "setup-" + testable_name), + rundir) + os.chdir(rundir) + self.cache_clearer() + benchmark_obj.run(testable) + instrumenter.flush() + if not self.debug: + os.chdir(startdir) + shutil.rmtree(rundir) + if not self.debug: + for testable_name in self.testables.iterkeys(): + shutil.rmtree(os.path.join(benchdir, "setup-" + testable_name)) + +# TODO: +# figure out some consistent class/object/factory naming scheme + def tryit(): scratch = "scratch" results = "results" shutil.rmtree(scratch, True) shutil.rmtree(results, True) - testables = [MtnFactory("/home/njs/src/monotone/opt/mtn")] - benchmarks = [PullBenchmark(ExistingRepo("/home/njs/src/monotone/speedtest/t.db"))] - instrumenters = [InstrumenterFactory(TimingInstrumenter, 2)] + testables = {"mtn": MtnFactory("/home/njs/src/monotone/opt/mtn")} + benchmarks = {"pull": PullBenchmark(ExistingRepo("/home/njs/src/monotone/speedtest/t.db"))} + instrumenters = {"time": InstrumenterFactory(TimingInstrumenter, 2)} debug = 1 - driver = Driver(scratch, results, testables, benchmarks, instrumenters, debug) + def clear_caches(): + pass + + driver = Driver(scratch, results, testables, benchmarks, instrumenters, + debug, clear_caches) driver.run() if __name__ == "__main__":