proxygen
QuantileEstimator-defs.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 
22 
23 namespace folly {
24 namespace detail {
25 
26 QuantileEstimates estimatesFromDigest(
27  const TDigest& digest,
28  Range<const double*> quantiles);
29 
30 } // namespace detail
31 
32 template <typename ClockT>
34  : bufferedDigest_(std::chrono::seconds{1}, 1000, 100) {}
35 
36 template <typename ClockT>
38  Range<const double*> quantiles,
39  TimePoint now) {
40  auto digest = bufferedDigest_.get(now);
41  return detail::estimatesFromDigest(digest, quantiles);
42 }
43 
44 template <typename ClockT>
46  bufferedDigest_.append(value, now);
47 }
48 
49 template <typename ClockT>
51  std::chrono::seconds windowDuration,
52  size_t nWindows)
53  : bufferedSlidingWindow_(nWindows, windowDuration, 1000, 100) {}
54 
55 template <typename ClockT>
57  Range<const double*> quantiles,
58  TimePoint now) {
59  auto digests = bufferedSlidingWindow_.get(now);
60  auto digest = TDigest::merge(digests);
61  return detail::estimatesFromDigest(digest, quantiles);
62 }
63 
64 template <typename ClockT>
66  double value,
67  TimePoint now) {
68  bufferedSlidingWindow_.append(value, now);
69 }
70 
71 } // namespace folly
void addValue(double value, TimePoint now=ClockT::now())
chrono
Definition: CMakeCache.txt:563
QuantileEstimates estimateQuantiles(Range< const double * > quantiles, TimePoint now=ClockT::now())
std::chrono::steady_clock::time_point now()
SlidingWindowQuantileEstimator(std::chrono::seconds windowDuration, size_t nWindows=60)
STL namespace.
detail::BufferedDigest< TDigest, ClockT > bufferedDigest_
typename ClockT::time_point TimePoint
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void addValue(double value, TimePoint now=ClockT::now())
detail::BufferedSlidingWindow< TDigest, ClockT > bufferedSlidingWindow_
TDigest merge(presorted_t, Range< const double * > sortedValues) const
Definition: TDigest.cpp:126
QuantileEstimates estimatesFromDigest(const TDigest &digest, Range< const double * > quantiles)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
typename ClockT::time_point TimePoint
QuantileEstimates estimateQuantiles(Range< const double * > quantiles, TimePoint now=ClockT::now())