Commit 0a24d9e3 authored by Wenbin Zhang's avatar Wenbin Zhang Committed by Chromium LUCI CQ

[benchmarking] parse "sections" in shard map to generate index range arguments

This CL added the parsing logic for the new shard map with "sections", which allow stories from multiple index ranges from the same benchmark to run on the same shard.

The generated argument will be: --story-shard-indexes=<range_string>

Bug: chromium:1140389
Change-Id: Ifcd9fc16b6ec1be1ea20e0d68687b0d14b5d1f65
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2617002
Commit-Queue: Wenbin Zhang <wenbinzhang@google.com>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842777}
parent 6d8acd76
...@@ -33,7 +33,8 @@ def main(argv): ...@@ -33,7 +33,8 @@ def main(argv):
'PRESUBMIT.py', 'PRESUBMIT.py',
'sizes_common.py', 'sizes_common.py',
'wpt_common.py', 'wpt_common.py',
'wpt_common_unittest.py'): 'wpt_common_unittest.py',
'run_performance_tests_unittest.py'):
continue continue
with common.temporary_file() as tempfile_path: with common.temporary_file() as tempfile_path:
......
...@@ -419,10 +419,37 @@ class TelemetryCommandGenerator(object): ...@@ -419,10 +419,37 @@ class TelemetryCommandGenerator(object):
if 'end' in self._story_selection_config: if 'end' in self._story_selection_config:
selection_args.append('--story-shard-end-index=%d' % ( selection_args.append('--story-shard-end-index=%d' % (
self._story_selection_config['end'])) self._story_selection_config['end']))
if 'sections' in self._story_selection_config:
range_string = self._generate_story_index_ranges(
self._story_selection_config['sections'])
if range_string:
selection_args.append('--story-shard-indexes=%s' % range_string)
if self._story_selection_config.get('abridged', True): if self._story_selection_config.get('abridged', True):
selection_args.append('--run-abridged-story-set') selection_args.append('--run-abridged-story-set')
return selection_args return selection_args
def _generate_story_index_ranges(self, sections):
range_string = ''
for section in sections:
begin = section.get('begin', '')
end = section.get('end', '')
# If there only one story in the range, we only keep its index.
# In general, we expect either begin or end, or both.
if begin != '' and end != '' and end - begin == 1:
new_range = str(begin)
elif begin != '' or end != '':
new_range = '%s-%s' % (str(begin), str(end))
else:
raise ValueError('Index ranges in "sections" in shard map should have'
'at least one of "begin" and "end": %s' % str(section))
if range_string:
range_string += ',%s' % new_range
else:
range_string = new_range
return range_string
def _generate_reference_build_args(self): def _generate_reference_build_args(self):
if self._is_reference: if self._is_reference:
reference_browser_flag = '--browser=reference' reference_browser_flag = '--browser=reference'
......
# Copyright (c) 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import unittest
import json
import run_performance_tests
from run_performance_tests import TelemetryCommandGenerator
# The path where the output of a wpt run was written. This is the file that
# gets processed by BaseWptScriptAdapter.
OUTPUT_JSON_FILENAME = "out.json"
class TelemetryCommandGeneratorTest(unittest.TestCase):
def setUp(self):
fake_args = [
'./run_benchmark',
'--isolated-script-test-output=output.json'
]
self._fake_options = run_performance_tests.parse_arguments(fake_args)
def testStorySelectionBeginEnd(self):
story_selection_config = json.loads(
'{"begin": 11, "end": 21, "abridged": false}')
generator = TelemetryCommandGenerator(
'benchmark_name', self._fake_options, story_selection_config
)
command = generator.generate('output_dir')
self.assertIn('--story-shard-begin-index=11', command)
self.assertIn('--story-shard-end-index=21', command)
self.assertNotIn('--run-abridged-story-set', command)
def testStorySelectionAbridgedDefault(self):
story_selection_config = json.loads(
'{"begin": 11, "end": 21}')
generator = TelemetryCommandGenerator(
'benchmark_name', self._fake_options, story_selection_config
)
command = generator.generate('output_dir')
self.assertIn('--run-abridged-story-set', command)
def testStorySelectionIndexSectionsSingleIndex(self):
story_selection_config = json.loads(
'{"sections": [{"begin": 11, "end": 21}, {"begin": 25, "end": 26}]}')
generator = TelemetryCommandGenerator(
'benchmark_name', self._fake_options, story_selection_config
)
command = generator.generate('output_dir')
self.assertIn('--story-shard-indexes=11-21,25', command)
def testStorySelectionIndexSectionsOpenEnds(self):
story_selection_config = json.loads(
'{"sections": [{"end": 10}, {"begin": 15, "end": 16}, {"begin": 20}]}')
generator = TelemetryCommandGenerator(
'benchmark_name', self._fake_options, story_selection_config
)
command = generator.generate('output_dir')
self.assertIn('--story-shard-indexes=-10,15,20-', command)
def testStorySelectionIndexSectionsIllegalRange(self):
with self.assertRaises(ValueError):
story_selection_config = json.loads(
'{"sections": [{"begin": 15, "end": 16}, {"foo": "bar"}]}')
generator = TelemetryCommandGenerator(
'benchmark_name', self._fake_options, story_selection_config
)
generator.generate('output_dir')
def testStorySelectionIndexSectionsEmpty(self):
story_selection_config = json.loads(
'{"sections": []}')
generator = TelemetryCommandGenerator(
'benchmark_name', self._fake_options, story_selection_config
)
command = generator.generate('output_dir')
self.assertNotIn('--story-shard-indexes=', command)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment