Skip to content

[benchmark] BenchmarkDriver check --markdown #21477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions benchmark/scripts/Benchmark_Driver
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,15 @@ class BenchmarkDoctor(object):
super(BenchmarkDoctor, self).__init__()
self.driver = driver or BenchmarkDriver(args)
self.results = {}
self.console_handler = logging.StreamHandler(sys.stdout)
self.console_handler.setLevel(logging.DEBUG if args.verbose else
logging.INFO)
self.console_handler.setFormatter(
LoggingReportFormatter(use_color=sys.stdout.isatty()))

if hasattr(args, 'markdown') and args.markdown:
self.console_handler = MarkdownReportHandler(sys.stdout)
else:
self.console_handler = logging.StreamHandler(sys.stdout)
self.console_handler.setFormatter(
LoggingReportFormatter(use_color=sys.stdout.isatty()))
self.console_handler.setLevel(logging.DEBUG if args.verbose else
logging.INFO)
self.log.addHandler(self.console_handler)
self.log.debug('Checking tests: %s', ', '.join(self.driver.tests))
self.requirements = [
Expand All @@ -350,6 +354,7 @@ class BenchmarkDoctor(object):
"""Close log handlers on exit."""
for handler in list(self.log.handlers):
handler.close()
self.log.removeHandler(self.console_handler)

benchmark_naming_convention_re = re.compile(r'[A-Z][a-zA-Z0-9\-.!?]+')
camel_humps_re = re.compile(r'[a-z][A-Z]')
Expand Down Expand Up @@ -703,9 +708,13 @@ def parse_args(args):
'check',
help='',
parents=[shared_benchmarks_parser])
check_parser.add_argument(
check_group = check_parser.add_mutually_exclusive_group()
check_group.add_argument(
'-v', '--verbose', action='store_true',
help='show more details during benchmark analysis',)
help='show more details during benchmark analysis')
check_group.add_argument(
'-md', '--markdown', action='store_true',
help='format report as Markdown table')
check_parser.set_defaults(func=BenchmarkDoctor.run_check)

compare_parser = subparsers.add_parser(
Expand Down
27 changes: 25 additions & 2 deletions benchmark/scripts/test_Benchmark_Driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ def test_check_supports_vebose_output(self):
self.assertTrue(parse_args(['check', '-v']).verbose)
self.assertTrue(parse_args(['check', '--verbose']).verbose)

def test_check_supports_mardown_output(self):
self.assertFalse(parse_args(['check']).markdown)
self.assertTrue(parse_args(['check', '-md']).markdown)
self.assertTrue(parse_args(['check', '--markdown']).markdown)

def test_check_flags_are_mutually_exclusive(self):
with captured_output() as (out, err):
self.assertRaises(SystemExit,
parse_args, ['check', '-md', '-v'])
self.assert_contains(
['error:', 'argument -v/--verbose: ' +
'not allowed with argument -md/--markdown'],
err.getvalue())


class ArgsStub(object):
def __init__(self):
Expand Down Expand Up @@ -497,7 +511,7 @@ def setUpClass(cls):

def setUp(self):
super(TestBenchmarkDoctor, self).setUp()
self.args = Stub(verbose=False)
self.args = Stub(verbose=False, markdown=False)
self._doctor_log_handler.reset()
self.logs = self._doctor_log_handler.messages

Expand All @@ -516,8 +530,9 @@ def test_uses_logging(self):
def test_supports_verbose_output(self):
driver = BenchmarkDriverMock(tests=['B1', 'B2'])
driver.verbose = True
self.args.verbose = True
with captured_output() as (out, _):
BenchmarkDoctor(Stub(verbose=True), driver)
BenchmarkDoctor(self.args, driver)
self.assert_contains(['Checking tests: B1, B2'], out.getvalue())

def test_uses_report_formatter(self):
Expand All @@ -528,6 +543,14 @@ def test_uses_report_formatter(self):
self.assertTrue(isinstance(console_handler.formatter,
LoggingReportFormatter))

def test_uses_optional_markdown_report_formatter(self):
self.args.markdown = True
with captured_output() as (_, _):
doc = BenchmarkDoctor(self.args, BenchmarkDriverMock(tests=['B1']))
self.assertTrue(doc)
console_handler = logging.getLogger('BenchmarkDoctor').handlers[1]
self.assertTrue(isinstance(console_handler, MarkdownReportHandler))

def test_measure_10_independent_1s_benchmark_series(self):
"""Measurement strategy takes 5 i2 and 5 i1 series.

Expand Down