proxygen
QuantileEstimator.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
20 
21 namespace folly {
22 
24  public:
25  double sum;
26  double count;
27 
28  // vector of {quantile, value}
29  std::vector<std::pair<double, double>> quantiles;
30 };
31 
32 /*
33  * A QuantileEstimator that buffers writes for 1 second.
34  */
35 template <typename ClockT = std::chrono::steady_clock>
37  public:
38  using TimePoint = typename ClockT::time_point;
39 
41 
42  QuantileEstimates estimateQuantiles(
45 
46  void addValue(double value, TimePoint now = ClockT::now());
47 
49  void flush() {
50  bufferedDigest_.flush();
51  }
52 
53  private:
55 };
56 
57 /*
58  * A QuantileEstimator that keeps values for nWindows * windowDuration (see
59  * constructor). Values are buffered for windowDuration.
60  */
61 template <typename ClockT = std::chrono::steady_clock>
63  public:
64  using TimePoint = typename ClockT::time_point;
65 
67  std::chrono::seconds windowDuration,
68  size_t nWindows = 60);
69 
70  QuantileEstimates estimateQuantiles(
71  Range<const double*> quantiles,
73 
74  void addValue(double value, TimePoint now = ClockT::now());
75 
77  void flush() {
78  bufferedSlidingWindow_.flush();
79  }
80 
81  private:
83 };
84 
87 
88 } // namespace folly
std::chrono::steady_clock::time_point now()
detail::BufferedDigest< TDigest, ClockT > bufferedDigest_
typename ClockT::time_point TimePoint
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void flush()
Flush buffered values.
detail::BufferedSlidingWindow< TDigest, ClockT > bufferedSlidingWindow_
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
void addValue(unsigned int iters, seconds duration, size_t numBuckets, size_t callsPerSecond)
std::vector< std::pair< double, double > > quantiles
void flush()
Flush buffered values.
typename ClockT::time_point TimePoint