blob: 3c0929fd4d14e9838c8d57f9f65663a800861b61 [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
// 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.
// Size-based units.
// Frequency-based units.
// Percentage-based units.
// Count-based units.
// Power-based units.
const _unitToCatapultConverterString = {
Unit.nanoseconds: 'nanoseconds',
Unit.milliseconds: 'milliseconds',
Unit.bytes: 'bytes',
Unit.bytesPerSecond: 'bytes/second',
Unit.framesPerSecond: 'frames/second',
Unit.percent: 'percent',
Unit.count: 'count',
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( Remove the "label" field."
String? label;
Unit unit;
List<double> values;
TestCaseResults(this.metric, this.unit, this.values) {
// TODO( 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,