diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index e26f4e1425..33f819e5e7 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -341,6 +341,23 @@ TaskFunction createFramePolicyIntegrationTest() { }; } +Map _average(List> results, int iterations) { + final Map tally = {}; + for (final Map item in results) { + item.forEach((String key, dynamic value) { + if (tally.containsKey(key)) { + tally[key] = (tally[key] as int) + (value as int); + } else { + tally[key] = value; + } + }); + } + tally.forEach((String key, dynamic value) { + tally[key] = (value as int) ~/ iterations; + }); + return tally; +} + /// Measure application startup performance. class StartupTest { const StartupTest(this.testDirectory, { this.reportMetrics = true }); @@ -353,21 +370,28 @@ class StartupTest { final String deviceId = (await devices.workingDevice).deviceId; await flutter('packages', options: ['get']); - await flutter('run', options: [ - '--verbose', - '--profile', - '--trace-startup', - '-d', - deviceId, - ]); - final Map data = json.decode( - file('$testDirectory/build/start_up_info.json').readAsStringSync(), - ) as Map; + const int iterations = 3; + final List> results = >[]; + for (int i = 0; i < iterations; ++i) { + await flutter('run', options: [ + '--verbose', + '--profile', + '--trace-startup', + '-d', + deviceId, + ]); + final Map data = json.decode( + file('$testDirectory/build/start_up_info.json').readAsStringSync(), + ) as Map; + results.add(data); + } + + final Map averageResults = _average(results, iterations); if (!reportMetrics) - return TaskResult.success(data); + return TaskResult.success(averageResults); - return TaskResult.success(data, benchmarkScoreKeys: [ + return TaskResult.success(averageResults, benchmarkScoreKeys: [ 'timeToFirstFrameMicros', 'timeToFirstFrameRasterizedMicros', ]);