xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/platform/api/quic_client_stats.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // 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_QUIC_PLATFORM_API_QUIC_CLIENT_STATS_H_
6 #define QUICHE_QUIC_PLATFORM_API_QUIC_CLIENT_STATS_H_
7 
8 #include <string>
9 
10 #include "quiche/common/platform/api/quiche_client_stats.h"
11 
12 namespace quic {
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 //   QUIC_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 QUIC_CLIENT_HISTOGRAM_ENUM(name, sample, enum_size, docstring) \
33   QUICHE_CLIENT_HISTOGRAM_ENUM(name, sample, enum_size, docstring)
34 
35 //------------------------------------------------------------------------------
36 // Histogram for boolean values.
37 
38 // Sample usage:
39 //   QUIC_CLIENT_HISTOGRAM_BOOL("My.Boolean", bool,
40 //   "Number of times $foo is true or false");
41 #define QUIC_CLIENT_HISTOGRAM_BOOL(name, sample, docstring) \
42   QUICHE_CLIENT_HISTOGRAM_BOOL(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 //   QUIC_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 QUIC_CLIENT_HISTOGRAM_TIMES(name, sample, min, max, bucket_count, \
57                                     docstring)                            \
58   QUICHE_CLIENT_HISTOGRAM_TIMES(name, sample, min, max, bucket_count, docstring)
59 
60 //------------------------------------------------------------------------------
61 // Count histograms. These are used for collecting numeric data.
62 
63 // These macros default to exponential histograms - i.e. the lengths of the
64 // bucket ranges exponentially increase as the sample range increases.
65 
66 // All of these macros must be called with |name| as a runtime constant.
67 
68 // Any data outside the range here will be put in underflow and overflow
69 // buckets. Min values should be >=1 as emitted 0s will still go into the
70 // underflow bucket.
71 
72 // Sample usage:
73 //   UMA_CLIENT_HISTOGRAM_CUSTOM_COUNTS("My.Histogram", 1, 100000000, 100,
74 //      "Counters of hitting certian code.");
75 
76 #define QUIC_CLIENT_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count, \
77                                      docstring)                            \
78   QUICHE_CLIENT_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count,     \
79                                  docstring)
80 
QuicClientSparseHistogram(const std::string & name,int sample)81 inline void QuicClientSparseHistogram(const std::string& name, int sample) {
82   quiche::QuicheClientSparseHistogram(name, sample);
83 }
84 
85 }  // namespace quic
86 
87 #endif  // QUICHE_QUIC_PLATFORM_API_QUIC_CLIENT_STATS_H_
88