tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

metric.h (2920B)


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