| 1 | /* |
| 2 | * Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef API_TEST_METRICS_METRIC_H_ |
| 12 | #define API_TEST_METRICS_METRIC_H_ |
| 13 | |
| 14 | #include <map> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "absl/types/optional.h" |
| 19 | #include "api/units/timestamp.h" |
| 20 | |
| 21 | namespace webrtc { |
| 22 | namespace test { |
| 23 | |
| 24 | enum class Unit { |
| 25 | kMilliseconds, |
| 26 | kPercent, |
| 27 | kBytes, |
| 28 | kKilobitsPerSecond, |
| 29 | kHertz, |
| 30 | // General unitless value. Can be used either for dimensionless quantities |
| 31 | // (ex ratio) or for units not presented in this enum and too specific to add |
| 32 | // to this enum. |
| 33 | kUnitless, |
| 34 | kCount |
| 35 | }; |
| 36 | |
| 37 | absl::string_view ToString(Unit unit); |
| 38 | |
| 39 | enum class ImprovementDirection { |
| 40 | kBiggerIsBetter, |
| 41 | kNeitherIsBetter, |
| 42 | kSmallerIsBetter |
| 43 | }; |
| 44 | |
| 45 | absl::string_view ToString(ImprovementDirection direction); |
| 46 | |
| 47 | struct Metric { |
| 48 | struct TimeSeries { |
| 49 | struct Sample { |
| 50 | // Timestamp in microseconds associated with a sample. For example, |
| 51 | // the timestamp when the sample was collected. |
| 52 | webrtc::Timestamp timestamp; |
| 53 | double value; |
| 54 | // Metadata associated with this particular sample. |
| 55 | std::map<std::string, std::string> sample_metadata; |
| 56 | }; |
| 57 | |
| 58 | // All samples collected for this metric. It can be empty if the Metric |
| 59 | // object only contains `stats`. |
| 60 | std::vector<Sample> samples; |
| 61 | }; |
| 62 | |
| 63 | // Contains metric's precomputed statistics based on the `time_series` or if |
| 64 | // `time_series` is omitted (has 0 samples) contains precomputed statistics |
| 65 | // provided by the metric's calculator. |
| 66 | struct Stats { |
| 67 | // Sample mean of the metric |
| 68 | // (https://en.wikipedia.org/wiki/Sample_mean_and_covariance). |
| 69 | absl::optional<double> mean; |
| 70 | // Standard deviation (https://en.wikipedia.org/wiki/Standard_deviation). |
| 71 | // Is undefined if `time_series` contains only a single value. |
| 72 | absl::optional<double> stddev; |
| 73 | absl::optional<double> min; |
| 74 | absl::optional<double> max; |
| 75 | }; |
| 76 | |
| 77 | // Metric name, for example PSNR, SSIM, decode_time, etc. |
| 78 | std::string name; |
| 79 | Unit unit; |
| 80 | ImprovementDirection improvement_direction; |
| 81 | // If the metric is generated by a test, this field can be used to specify |
| 82 | // this information. |
| 83 | std::string test_case; |
| 84 | // Metadata associated with the whole metric. |
| 85 | std::map<std::string, std::string> metric_metadata; |
| 86 | // Contains all samples of the metric collected during test execution. |
| 87 | // It can be empty if the user only stores precomputed statistics into |
| 88 | // `stats`. |
| 89 | TimeSeries time_series; |
| 90 | Stats stats; |
| 91 | }; |
| 92 | |
| 93 | } // namespace test |
| 94 | } // namespace webrtc |
| 95 | |
| 96 | #endif // API_TEST_METRICS_METRIC_H_ |
| 97 | |