22
33#include < chrono>
44#include < cstdint>
5+ #include < functional>
56#include < list>
67#include < memory>
78#include < string>
@@ -114,6 +115,11 @@ class Metric {
114115 * Returns the name of the Metric with the portions designated as tags removed.
115116 */
116117 virtual const std::string& tagExtractedName () const PURE;
118+
119+ /* *
120+ * Indicates whether this metric has been updated since the server was started.
121+ */
122+ virtual bool used () const PURE;
117123};
118124
119125/* *
@@ -128,7 +134,6 @@ class Counter : public virtual Metric {
128134 virtual void inc () PURE;
129135 virtual uint64_t latch () PURE;
130136 virtual void reset () PURE;
131- virtual bool used () const PURE;
132137 virtual uint64_t value () const PURE;
133138};
134139
@@ -146,12 +151,34 @@ class Gauge : public virtual Metric {
146151 virtual void inc () PURE;
147152 virtual void set (uint64_t value) PURE;
148153 virtual void sub (uint64_t amount) PURE;
149- virtual bool used () const PURE;
150154 virtual uint64_t value () const PURE;
151155};
152156
153157typedef std::shared_ptr<Gauge> GaugeSharedPtr;
154158
159+ /* *
160+ * Holds the computed statistics for a histogram.
161+ */
162+ class HistogramStatistics {
163+ public:
164+ virtual ~HistogramStatistics () {}
165+
166+ /* *
167+ * Returns summary representation of the histogram.
168+ */
169+ virtual std::string summary () const PURE;
170+
171+ /* *
172+ * Returns supported quantiles.
173+ */
174+ virtual const std::vector<double >& supportedQuantiles () const PURE;
175+
176+ /* *
177+ * Returns computed quantile values during the period.
178+ */
179+ virtual const std::vector<double >& computedQuantiles () const PURE;
180+ };
181+
155182/* *
156183 * A histogram that records values one at a time.
157184 * Note: Histograms now incorporate what used to be timers because the only difference between the
@@ -171,6 +198,32 @@ class Histogram : public virtual Metric {
171198
172199typedef std::shared_ptr<Histogram> HistogramSharedPtr;
173200
201+ /* *
202+ * A histogram that is stored in main thread and provides summary view of the histogram.
203+ */
204+ class ParentHistogram : public virtual Histogram {
205+ public:
206+ virtual ~ParentHistogram () {}
207+
208+ /* *
209+ * This method is called during the main stats flush process for each of the histograms and used
210+ * to merge the histogram values.
211+ */
212+ virtual void merge () PURE;
213+
214+ /* *
215+ * Returns the interval histogram summary statistics for the flush interval.
216+ */
217+ virtual const HistogramStatistics& intervalStatistics () const PURE;
218+
219+ /* *
220+ * Returns the cumulative histogram summary statistics.
221+ */
222+ virtual const HistogramStatistics& cumulativeStatistics () const PURE;
223+ };
224+
225+ typedef std::shared_ptr<ParentHistogram> ParentHistogramSharedPtr;
226+
174227/* *
175228 * A sink for stats. Each sink is responsible for writing stats to a backing store.
176229 */
@@ -194,6 +247,11 @@ class Sink {
194247 */
195248 virtual void flushGauge (const Gauge& gauge, uint64_t value) PURE;
196249
250+ /* *
251+ * Flush a histogram.
252+ */
253+ virtual void flushHistogram (const ParentHistogram& histogram) PURE;
254+
197255 /* *
198256 * This will be called after beginFlush(), some number of flushCounter(), and some number of
199257 * flushGauge(). Sinks can use this to optimize writing if desired.
@@ -263,10 +321,20 @@ class Store : public Scope {
263321 * @return a list of all known gauges.
264322 */
265323 virtual std::list<GaugeSharedPtr> gauges () const PURE;
324+
325+ /* *
326+ * @return a list of all known histograms.
327+ */
328+ virtual std::list<ParentHistogramSharedPtr> histograms () const PURE;
266329};
267330
268331typedef std::unique_ptr<Store> StorePtr;
269332
333+ /* *
334+ * Callback invoked when a store's mergeHistogram() runs.
335+ */
336+ typedef std::function<void ()> PostMergeCb;
337+
270338/* *
271339 * The root of the stat store.
272340 */
@@ -294,6 +362,15 @@ class StoreRoot : public Store {
294362 * down.
295363 */
296364 virtual void shutdownThreading () PURE;
365+
366+ /* *
367+ * Called during the flush process to merge all the thread local histograms. The passed in
368+ * callback will be called on the main thread, but it will happen after the method returns
369+ * which means that the actual flush process will happen on the main thread after this method
370+ * returns. It is expected that only one merge runs at any time and concurrent calls to this
371+ * method would be asserted.
372+ */
373+ virtual void mergeHistograms (PostMergeCb merge_complete_cb) PURE;
297374};
298375
299376typedef std::unique_ptr<StoreRoot> StoreRootPtr;
0 commit comments