From 03d6b58002fae1a1ba25caeb026ba79318ef8a22 Mon Sep 17 00:00:00 2001 From: Mouad Debbar Date: Fri, 28 Feb 2020 13:54:45 -0800 Subject: [PATCH] [web] Allow benchmarks to customize their score keys (#51493) --- .../macrobenchmarks/lib/src/web/recorder.dart | 1 + dev/devicelab/lib/tasks/web_benchmarks.dart | 31 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart index d93d89a167..4ebcf6d5aa 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart @@ -430,6 +430,7 @@ class Profile { Map toJson() { return { 'name': name, + 'scoreKeys': ['averageDrawFrameDuration'], 'averageDrawFrameDuration': averageDrawFrameDuration.inMicroseconds, 'drawFrameDurationNoise': drawFrameDurationNoise, 'frames': frames diff --git a/dev/devicelab/lib/tasks/web_benchmarks.dart b/dev/devicelab/lib/tasks/web_benchmarks.dart index ee1da2d21f..0211fe066c 100644 --- a/dev/devicelab/lib/tasks/web_benchmarks.dart +++ b/dev/devicelab/lib/tasks/web_benchmarks.dart @@ -124,10 +124,33 @@ Future runWebBenchmark({ @required bool useCanvasKit }) async { print('Received profile data'); for (final Map profile in profiles) { final String benchmarkName = profile['name'] as String; - final String benchmarkScoreKey = '$benchmarkName.$backend.averageDrawFrameDuration'; - taskResult[benchmarkScoreKey] = profile['averageDrawFrameDuration'].toDouble(); // micros - taskResult['$benchmarkName.$backend.drawFrameDurationNoise'] = profile['drawFrameDurationNoise'].toDouble(); // micros - benchmarkScoreKeys.add(benchmarkScoreKey); + if (benchmarkName.isEmpty) { + throw 'Benchmark name is empty'; + } + + final String namespace = '$benchmarkName.$backend'; + final List scoreKeys = List.from(profile['scoreKeys'] as List); + if (scoreKeys == null || scoreKeys.isEmpty) { + throw 'No score keys in benchmark "$benchmarkName"'; + } + for (final String scoreKey in scoreKeys) { + if (scoreKey == null || scoreKey.isEmpty) { + throw 'Score key is empty in benchmark "$benchmarkName". ' + 'Received [${scoreKeys.join(', ')}]'; + } + if (scoreKey.contains('.')) { + throw 'Score key contain dots in benchmark "$benchmarkName". ' + 'Received [${scoreKeys.join(', ')}]'; + } + benchmarkScoreKeys.add('$namespace.$scoreKey'); + } + + for (final String key in profile.keys) { + if (key == 'name' || key == 'scoreKeys') { + continue; + } + taskResult['$namespace.$key'] = profile[key]; + } } return TaskResult.success(taskResult, benchmarkScoreKeys: benchmarkScoreKeys); } finally {