diff --git a/dev/devicelab/lib/framework/metrics_center.dart b/dev/devicelab/lib/framework/metrics_center.dart index 6aa1c754ed..1f5adda62a 100644 --- a/dev/devicelab/lib/framework/metrics_center.dart +++ b/dev/devicelab/lib/framework/metrics_center.dart @@ -133,5 +133,49 @@ Future uploadToSkiaPerf(String? resultsPath, String? commitTime, String? t resultsJson = json.decode(await resultFile.readAsString()) as Map; final List metricPoints = parse(resultsJson, benchmarkTagsMap, taskName); final FlutterDestination metricsDestination = await connectFlutterDestination(); - await upload(metricsDestination, metricPoints, commitTimeSinceEpoch, taskName); + await upload( + metricsDestination, + metricPoints, + commitTimeSinceEpoch, + metricFileName(taskName, benchmarkTagsMap), + ); +} + +/// Create metric file name based on `taskName`, `arch`, `host type`, and `device type`. +/// +/// Same `taskName` may run on different platforms. Considering host/device tags to +/// use different metric file names. +/// +/// This affects only the metric file name which contains metric data, and does not affect +/// real host/device tags. +/// +/// For example: +/// Old file name: `backdrop_filter_perf__timeline_summary` +/// New file name: `backdrop_filter_perf__timeline_summary_intel_linux_motoG4` +String metricFileName( + String taskName, + Map benchmarkTagsMap, +) { + final StringBuffer fileName = StringBuffer(taskName); + if (benchmarkTagsMap.containsKey('arch')) { + fileName + ..write('_') + ..write(_fileNameFormat(benchmarkTagsMap['arch'] as String)); + } + if (benchmarkTagsMap.containsKey('host_type')) { + fileName + ..write('_') + ..write(_fileNameFormat(benchmarkTagsMap['host_type'] as String)); + } + if (benchmarkTagsMap.containsKey('device_type')) { + fileName + ..write('_') + ..write(_fileNameFormat(benchmarkTagsMap['device_type'] as String)); + } + return fileName.toString(); +} + +/// Format `fileName` removing non letter and number characters. +String _fileNameFormat(String fileName) { + return fileName.replaceAll(RegExp('[^a-zA-Z0-9]'), ''); } diff --git a/dev/devicelab/test/metrics_center_test.dart b/dev/devicelab/test/metrics_center_test.dart index a7dfff782d..8963d23b8c 100644 --- a/dev/devicelab/test/metrics_center_test.dart +++ b/dev/devicelab/test/metrics_center_test.dart @@ -155,4 +155,24 @@ void main() { expect(flutterDestination.name, taskName); }); }); + + group('metric file name', () { + test('without tags', () async { + final Map tags = {}; + final String fileName = metricFileName('test', tags); + expect(fileName, 'test'); + }); + + test('with device tags', () async { + final Map tags = {'device_type': 'ab-c'}; + final String fileName = metricFileName('test', tags); + expect(fileName, 'test_abc'); + }); + + test('with device host and arch tags', () async { + final Map tags = {'device_type': 'ab-c', 'host_type': 'de-f', 'arch': 'm1'}; + final String fileName = metricFileName('test', tags); + expect(fileName, 'test_m1_def_abc'); + }); + }); }