blob: 5b1b08c2a673c0b99212d22bb32c0d15dd7c7c4c [file] [log] [blame]
bnc91da9902022-03-15 18:14:48 -07001// Copyright 2018 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 QUICHE_COMMON_PLATFORM_API_QUICHE_CLIENT_STATS_H_
6#define QUICHE_COMMON_PLATFORM_API_QUICHE_CLIENT_STATS_H_
7
8#include <string>
9
10#include "quiche_platform_impl/quiche_client_stats_impl.h"
11
12namespace quiche {
13
14//------------------------------------------------------------------------------
15// Enumeration histograms.
16//
17// Sample usage:
18// // In Chrome, these values are persisted to logs. Entries should not be
19// // renumbered and numeric values should never be reused.
20// enum class MyEnum {
21// FIRST_VALUE = 0,
22// SECOND_VALUE = 1,
23// ...
24// FINAL_VALUE = N,
25// COUNT
26// };
27// QUICHE_CLIENT_HISTOGRAM_ENUM("My.Enumeration", MyEnum::SOME_VALUE,
28// MyEnum::COUNT, "Number of time $foo equals to some enum value");
29//
30// Note: The value in |sample| must be strictly less than |enum_size|.
31
32#define QUICHE_CLIENT_HISTOGRAM_ENUM(name, sample, enum_size, docstring) \
33 QUICHE_CLIENT_HISTOGRAM_ENUM_IMPL(name, sample, enum_size, docstring)
34
35//------------------------------------------------------------------------------
36// Histogram for boolean values.
37
38// Sample usage:
39// QUICHE_CLIENT_HISTOGRAM_BOOL("My.Boolean", bool,
40// "Number of times $foo is true or false");
41#define QUICHE_CLIENT_HISTOGRAM_BOOL(name, sample, docstring) \
42 QUICHE_CLIENT_HISTOGRAM_BOOL_IMPL(name, sample, docstring)
43
44//------------------------------------------------------------------------------
45// Timing histograms. These are used for collecting timing data (generally
46// latencies).
47
48// These macros create exponentially sized histograms (lengths of the bucket
49// ranges exponentially increase as the sample range increases). The units for
50// sample and max are unspecified, but they must be the same for one histogram.
51
52// Sample usage:
53// QUICHE_CLIENT_HISTOGRAM_TIMES("Very.Long.Timing.Histogram", time_delta,
54// QuicTime::Delta::FromSeconds(1), QuicTime::Delta::FromSecond(3600 *
55// 24), 100, "Time spent in doing operation.");
56#define QUICHE_CLIENT_HISTOGRAM_TIMES(name, sample, min, max, bucket_count, \
57 docstring) \
58 QUICHE_CLIENT_HISTOGRAM_TIMES_IMPL(name, sample, min, max, bucket_count, \
59 docstring)
60
61//------------------------------------------------------------------------------
62// Count histograms. These are used for collecting numeric data.
63
64// These macros default to exponential histograms - i.e. the lengths of the
65// bucket ranges exponentially increase as the sample range increases.
66
67// All of these macros must be called with |name| as a runtime constant.
68
69// Any data outside the range here will be put in underflow and overflow
70// buckets. Min values should be >=1 as emitted 0s will still go into the
71// underflow bucket.
72
73// Sample usage:
74// UMA_CLIENT_HISTOGRAM_CUSTOM_COUNTS("My.Histogram", 1, 100000000, 100,
75// "Counters of hitting certain code.");
76
77#define QUICHE_CLIENT_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count, \
78 docstring) \
79 QUICHE_CLIENT_HISTOGRAM_COUNTS_IMPL(name, sample, min, max, bucket_count, \
80 docstring)
81
82inline void QuicheClientSparseHistogram(const std::string& name, int sample) {
83 QuicheClientSparseHistogramImpl(name, sample);
84}
85
86} // namespace quiche
87
88#endif // QUICHE_COMMON_PLATFORM_API_QUICHE_CLIENT_STATS_H_