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