xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/platform/api/quic_exported_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_EXPORTED_STATS_H_
6 #define QUICHE_QUIC_PLATFORM_API_QUIC_EXPORTED_STATS_H_
7 
8 #include "quiche/quic/platform/api/quic_client_stats.h"
9 #include "quiche/quic/platform/api/quic_server_stats.h"
10 
11 namespace quic {
12 
13 // TODO(wub): Add support for counters. Only histograms are supported for now.
14 
15 //------------------------------------------------------------------------------
16 // Enumeration histograms.
17 //
18 // Sample usage:
19 //   // In Chrome, these values are persisted to logs. Entries should not be
20 //   // renumbered and numeric values should never be reused.
21 //   enum class MyEnum {
22 //     FIRST_VALUE = 0,
23 //     SECOND_VALUE = 1,
24 //     ...
25 //     FINAL_VALUE = N,
26 //     COUNT
27 //   };
28 //   QUIC_HISTOGRAM_ENUM("My.Enumeration", MyEnum::SOME_VALUE, MyEnum::COUNT,
29 //                       "Number of time $foo equals to some enum value");
30 //
31 // Note: The value in |sample| must be strictly less than |enum_size|.
32 
33 #define QUIC_HISTOGRAM_ENUM(name, sample, enum_size, docstring)     \
34   do {                                                              \
35     QUIC_CLIENT_HISTOGRAM_ENUM(name, sample, enum_size, docstring); \
36     QUIC_SERVER_HISTOGRAM_ENUM(name, sample, enum_size, docstring); \
37   } while (0)
38 
39 //------------------------------------------------------------------------------
40 // Histogram for boolean values.
41 
42 // Sample usage:
43 //   QUIC_HISTOGRAM_BOOL("My.Boolean", bool,
44 //                       "Number of times $foo is true or false");
45 #define QUIC_HISTOGRAM_BOOL(name, sample, docstring)     \
46   do {                                                   \
47     QUIC_CLIENT_HISTOGRAM_BOOL(name, sample, docstring); \
48     QUIC_SERVER_HISTOGRAM_BOOL(name, sample, docstring); \
49   } while (0)
50 
51 //------------------------------------------------------------------------------
52 // Timing histograms. These are used for collecting timing data (generally
53 // latencies).
54 
55 // These macros create exponentially sized histograms (lengths of the bucket
56 // ranges exponentially increase as the sample range increases). The units for
57 // sample and max are unspecified, but they must be the same for one histogram.
58 
59 // Sample usage:
60 //   QUIC_HISTOGRAM_TIMES("My.Timing.Histogram.InMs", time_delta,
61 //       QuicTime::Delta::FromSeconds(1), QuicTime::Delta::FromSecond(3600 *
62 //       24), 100, "Time spent in doing operation.");
63 
64 #define QUIC_HISTOGRAM_TIMES(name, sample, min, max, bucket_count, docstring) \
65   do {                                                                        \
66     QUIC_CLIENT_HISTOGRAM_TIMES(name, sample, min, max, bucket_count,         \
67                                 docstring);                                   \
68     QUIC_SERVER_HISTOGRAM_TIMES(name, sample, min, max, bucket_count,         \
69                                 docstring);                                   \
70   } while (0)
71 
72 //------------------------------------------------------------------------------
73 // Count histograms. These are used for collecting numeric data.
74 
75 // These macros default to exponential histograms - i.e. the lengths of the
76 // bucket ranges exponentially increase as the sample range increases.
77 
78 // All of these macros must be called with |name| as a runtime constant.
79 
80 // Sample usage:
81 //   QUIC_HISTOGRAM_COUNTS("My.Histogram",
82 //                         sample,    // Number of something in this event.
83 //                         1000,      // Record up to 1K of something.
84 //                         "Number of something.");
85 
86 #define QUIC_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count, docstring) \
87   do {                                                                         \
88     QUIC_CLIENT_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count,         \
89                                  docstring);                                   \
90     QUIC_SERVER_HISTOGRAM_COUNTS(name, sample, min, max, bucket_count,         \
91                                  docstring);                                   \
92   } while (0)
93 
94 }  // namespace quic
95 
96 #endif  // QUICHE_QUIC_PLATFORM_API_QUIC_EXPORTED_STATS_H_
97