blob: c3a2689d1e648852c0a100e4abfcc1a81424272b [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart=2.12
// This file implements the perf test results schema.
//
// See https://fuchsia.dev/fuchsia-src/development/performance/fuchsiaperf_format
// for more details.
/// The set of valid Unit constants.
///
/// This should be kept in sync with the list of supported units in the
/// results schema docs linked at the top of this file.
enum Unit {
// Time-based units.
nanoseconds,
milliseconds,
// Size-based units.
bytes,
bytesPerSecond,
// Frequency-based units.
framesPerSecond,
// Percentage-based units.
percent,
// Count-based units.
countSmallerIsBetter,
countBiggerIsBetter,
// Power-based units.
watts,
}
const _unitToCatapultConverterString = {
Unit.nanoseconds: 'nanoseconds',
Unit.milliseconds: 'milliseconds',
Unit.bytes: 'bytes',
Unit.bytesPerSecond: 'bytes/second',
Unit.framesPerSecond: 'frames/second',
Unit.percent: 'percent',
Unit.countSmallerIsBetter: 'count_smallerIsBetter',
Unit.countBiggerIsBetter: 'count_biggerIsBetter',
Unit.watts: 'Watts',
};
/// Map [unit] to the corresponding string expected in catapult converter.
String unitToCatapultConverterString(Unit unit) =>
_unitToCatapultConverterString[unit] ??
(throw ArgumentError('Failed to map $unit to catapult converter string'));
/// TestCaseResults represents the results for a single test case.
///
/// See the link at the top of this file for documentation.
class TestCaseResults {
String metric;
// This field below is being renamed from "label" to "metric".
// It is duplicated as a transitional measure so that it can be accessed via
// either name. TODO(https://fxbug.dev/42137976): Remove the "label" field."
String? label;
Unit unit;
List<double> values;
TestCaseResults(this.metric, this.unit, this.values) {
// TODO(https://fxbug.dev/42137976): Remove the statement below when "label" is removed.
label = metric;
}
Map<String, dynamic> toJson({required String testSuite}) => {
'label': label,
'test_suite': testSuite,
'unit': unitToCatapultConverterString(unit),
'values': values,
};
}