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