Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Side by Side Diff: net/base/percentile_estimator.h

Issue 2130493002: Implement THROTTLED priority semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@NetworkStreamThrottler
Patch Set: Fix use of message_loop_ in Android tests. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/network_throttle_manager_impl_unittest.cc ('k') | net/base/percentile_estimator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_BASE_PERCENTILE_ESTIMATOR_H_
6 #define NET_BASE_PERCENTILE_ESTIMATOR_H_
7
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "net/base/net_export.h"
11
12 namespace net {
13
14 // This class estimates statistical percentiles (e.g. 10%l, 50%l) for
15 // integer distributions presented in stream form. These estimates
16 // adjust automatically when the stream distribution changes.
17 // TODO(rdsmith): Expand the class to maintain floating point
18 // estimates rather than integer estimates, when there's a use case
19 // for that that deserves the extra complexity and pitfalls of
20 // floating point arithmetic.
21 class NET_EXPORT PercentileEstimator {
22 public:
23 using RandomNumberCallback = base::Callback<int(void)>;
24
25 static const int kMedianPercentile = 50;
26
27 // |percentile| is a number between 0 and 100 indicating what percentile
28 // should be estimated (e.g. 50 would be a median estimate).
29 // |initial_estimate| is the value the class is seeded with; in other
30 // words, if AddSample() is never called,
31 // |CurrentEstimate() == initial_estimate|.
32 PercentileEstimator(int percentile, int initial_estimate);
33
34 ~PercentileEstimator();
35
36 int current_estimate() const { return current_estimate_; }
37 void AddSample(int sample);
38
39 // Specify a callback that will generate a "random" number
40 // in the range [0,99] on each call. Used so that tests can
41 // rely on reproducible behavior.
42 void SetRandomNumberGeneratorForTesting(
43 RandomNumberCallback generator_callback);
44
45 private:
46 const int percentile_;
47
48 bool sign_positive_;
49 int current_estimate_;
50 int current_step_;
51
52 RandomNumberCallback generator_callback_;
53
54 DISALLOW_COPY_AND_ASSIGN(PercentileEstimator);
55 };
56
57 } // namespace net
58
59 #endif // NET_BASE_PERCENTILE_ESTIMATOR_H_
OLDNEW
« no previous file with comments | « net/base/network_throttle_manager_impl_unittest.cc ('k') | net/base/percentile_estimator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698