sample_stats.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2019 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. #ifndef RTC_BASE_NUMERICS_SAMPLE_STATS_H_
  11. #define RTC_BASE_NUMERICS_SAMPLE_STATS_H_
  12. #include "api/numerics/samples_stats_counter.h"
  13. #include "api/units/data_rate.h"
  14. #include "api/units/time_delta.h"
  15. #include "api/units/timestamp.h"
  16. namespace webrtc {
  17. template <typename T>
  18. class SampleStats;
  19. // TODO(srte): Merge this implementation with SamplesStatsCounter.
  20. template <>
  21. class SampleStats<double> : public SamplesStatsCounter {
  22. public:
  23. double Max();
  24. double Mean();
  25. double Median();
  26. double Quantile(double quantile);
  27. double Min();
  28. double Variance();
  29. double StandardDeviation();
  30. int Count();
  31. };
  32. template <>
  33. class SampleStats<TimeDelta> {
  34. public:
  35. void AddSample(TimeDelta delta);
  36. void AddSampleMs(double delta_ms);
  37. void AddSamples(const SampleStats<TimeDelta>& other);
  38. bool IsEmpty();
  39. TimeDelta Max();
  40. TimeDelta Mean();
  41. TimeDelta Median();
  42. TimeDelta Quantile(double quantile);
  43. TimeDelta Min();
  44. TimeDelta Variance();
  45. TimeDelta StandardDeviation();
  46. int Count();
  47. private:
  48. SampleStats<double> stats_;
  49. };
  50. template <>
  51. class SampleStats<DataRate> {
  52. public:
  53. void AddSample(DataRate rate);
  54. void AddSampleBps(double rate_bps);
  55. void AddSamples(const SampleStats<DataRate>& other);
  56. bool IsEmpty();
  57. DataRate Max();
  58. DataRate Mean();
  59. DataRate Median();
  60. DataRate Quantile(double quantile);
  61. DataRate Min();
  62. DataRate Variance();
  63. DataRate StandardDeviation();
  64. int Count();
  65. private:
  66. SampleStats<double> stats_;
  67. };
  68. } // namespace webrtc
  69. #endif // RTC_BASE_NUMERICS_SAMPLE_STATS_H_