Commit 2579f0f7 authored by Caleb Rouleau's avatar Caleb Rouleau Committed by Commit Bot

[Benchmarking] Allocate processing time to stories for more accurate sharding.

Bug: 1035696
Change-Id: Ifb123b04337f3a899422ee0337dfde8ecf4f57d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1975158
Commit-Queue: Caleb Rouleau <crouleau@chromium.org>
Reviewed-by: default avatarMikhail Khokhlov <khokhlov@google.com>
Cr-Commit-Position: refs/heads/master@{#726497}
parent be6d2c2d
......@@ -19,6 +19,7 @@ import posixpath
import random
import re
import shutil
import time
from py_utils import cloud_storage
from core.results_processor import command_line
......@@ -76,6 +77,7 @@ def ProcessResults(options):
should_compute_metrics = any(
fmt in FORMATS_WITH_METRICS for fmt in options.output_formats)
begin_time = time.time()
util.ApplyInParallel(
lambda result: ProcessTestResult(
result, upload_bucket, results_label, run_identifier,
......@@ -84,6 +86,8 @@ def ProcessResults(options):
test_results,
on_failure=util.SetUnexpectedFailure,
)
processing_duration = time.time() - begin_time
_AmortizeProcessingDuration(processing_duration, test_results)
if should_compute_metrics:
histogram_dicts = ExtractHistograms(test_results)
......@@ -100,6 +104,20 @@ def ProcessResults(options):
return GenerateExitCode(test_results)
def _AmortizeProcessingDuration(processing_duration, test_results):
test_results_count = len(test_results)
if test_results_count:
per_story_cost = processing_duration / len(test_results)
logging.info(
'Amortizing processing cost to story runtimes: %.2fs per story.',
per_story_cost)
for result in test_results:
if 'runDuration' in result and result['runDuration']:
current_duration = float(result['runDuration'].rstrip('s'))
new_story_cost = current_duration + per_story_cost
result['runDuration'] = unicode(str(new_story_cost) + 's', 'utf-8')
def ProcessTestResult(test_result, upload_bucket, results_label,
run_identifier, test_suite_start, should_compute_metrics,
max_num_values, test_path_format, trace_processor_path):
......
......@@ -127,8 +127,12 @@ class ResultsProcessorIntegrationTests(unittest.TestCase):
self.assertEqual(test_result['actual'], 'PASS')
self.assertEqual(test_result['expected'], 'PASS')
self.assertEqual(test_result['times'], [1.1, 1.2])
self.assertEqual(test_result['time'], 1.1)
# Amortization of processing time across test durations prevents us from
# being exact here.
self.assertGreaterEqual(test_result['times'][0], 1.1)
self.assertGreaterEqual(test_result['times'][1], 1.2)
self.assertEqual(len(test_result['times']), 2)
self.assertGreaterEqual(test_result['time'], 1.1)
self.assertEqual(test_result['shard'], 7)
def testJson3OutputWithArtifacts(self):
......
......@@ -179,3 +179,20 @@ class ResultsProcessorUnitTests(unittest.TestCase):
test_result = testing.TestResult('benchmark/story')
url = processor.GetTraceUrl(test_result)
self.assertIsNone(url)
def testAmortizeProcessingDuration_UndefinedDuration(self):
test_results = [testing.TestResult('benchmark/story')]
del test_results[0]['runDuration']
# pylint: disable=protected-access
processor._AmortizeProcessingDuration(1.0, test_results)
# pylint: enable=protected-access
self.assertNotIn('runDuration', test_results[0])
self.assertEqual(len(test_results), 1)
def testAmortizeProcessingDuration_OneResult(self):
test_results = [testing.TestResult('benchmark/story', run_duration='1.0s')]
# pylint: disable=protected-access
processor._AmortizeProcessingDuration(1.0, test_results)
# pylint: enable=protected-access
self.assertEqual(str(test_results[0]['runDuration']), '2.0s')
self.assertEqual(len(test_results), 1)
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