From f1b64b8535c73381d819d8c74c16dca067caf69c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 2 Aug 2013 19:30:58 +0100 Subject: Add yarn --timings option --- yarn | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/yarn b/yarn index 2d9f52b..ce0b9cb 100755 --- a/yarn +++ b/yarn @@ -69,6 +69,10 @@ class YarnRunner(cliapp.Application): 'after each scenario step; you probably ' 'want to use this with --tempdir') + self.settings.boolean( + ['timings'], + 'report wall clock time for each scenario and step') + def info(self, msg): if self.settings['verbose']: logging.info(msg) @@ -113,6 +117,7 @@ class YarnRunner(cliapp.Application): self.scenarios_run = 0 self.steps_run = 0 + self.timings = [] start_time = time.time() failed_scenarios = [] @@ -136,6 +141,9 @@ class YarnRunner(cliapp.Application): 'in %.1f seconds' % (self.scenarios_run, self.steps_run, duration)) + if self.settings['timings']: + self.report_timings() + def parse_scenarios(self, filenames): mdparser = yarnlib.MarkdownParser() for filename in filenames: @@ -210,6 +218,9 @@ class YarnRunner(cliapp.Application): return scenarios def run_scenario(self, scenario, shell_prelude): + self.start_scenario_timing(scenario.name) + started = time.time() + self.info('Running scenario %s' % scenario.name) self.ts['scenario'] = scenario self.ts['scenario_name'] = scenario.name @@ -218,6 +229,7 @@ class YarnRunner(cliapp.Application): if self.settings['no-act']: self.info('Pretending everything went OK') + self.remember_scenario_timing(time.time() - started) return True if self.settings['tempdir']: @@ -270,6 +282,7 @@ class YarnRunner(cliapp.Application): if not self.settings['snapshot']: shutil.rmtree(tempdir) + self.remember_scenario_timing(time.time() - started) return ok def clean_env(self): @@ -298,6 +311,8 @@ class YarnRunner(cliapp.Application): return env def run_step(self, datadir, scenario, step, shell_prelude, report_error): + started = time.time() + self.info('Running step "%s %s"' % (step.what, step.text)) self.ts['step'] = step self.ts['step_name'] = '%s %s' % (step.what, step.text) @@ -335,6 +350,9 @@ class YarnRunner(cliapp.Application): (scenario.name, step.what, step.text, exit, self.indent(stdout), self.indent(stderr))) + self.remember_step_timing( + '%s %s' % (step.what, step.text), time.time() - started) + return exit def scenario_dir(self, tempdir, scenario): @@ -371,5 +389,23 @@ class YarnRunner(cliapp.Application): def indent(self, s): return ''.join(' %s\n' % line for line in s.splitlines()) + def start_scenario_timing(self, scenario_name): + self.timings.append((scenario_name, None, [])) + + def remember_scenario_timing(self, duration): + scenario_name, _, step_tuples = self.timings[-1] + self.timings[-1] = (scenario_name, duration, step_tuples) + + def remember_step_timing(self, step_name, step_duration): + scenario_name, scenario_duration, step_tuples = self.timings[-1] + step_tuples = step_tuples + [(step_name, step_duration)] + self.timings[-1] = (scenario_name, scenario_duration, step_tuples) + + def report_timings(self): + for scenario_name, scenario_duration, step_tuples in self.timings: + print '%5.1f %s' % (scenario_duration, scenario_name) + for step_name, step_duration in step_tuples: + print ' %5.1f %s' % (step_duration, step_name) + YarnRunner(version=cmdtestlib.__version__).run() -- cgit v1.2.1 From 3ee1542566627fb33eae7edcb67b97e28de7f975 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 2 Aug 2013 19:31:38 +0100 Subject: Update NEWS about yarn --timings --- NEWS | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS b/NEWS index 4951f4c..35bbc38 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,9 @@ Version 0.10, released UNRELEASED to point at the root of the source tree (the directory where yarn was invoked from). +* A new option, `--timings`, has been added to yarn to report how long + each scenario and each step took. + Version 0.9, released 2013-07-23 -------------------------------- -- cgit v1.2.1