Skip to content

Commit 4a9d56e

Browse files
Jeremy Fitzhardingefacebook-github-bot
authored andcommitted
rust/stats: update documentation
Summary: Add docs to `define_stats` to document the different stats types and their parameters. Reviewed By: ryanthomasjohnson Differential Revision: D40997107 LaMa Project: L1122763 fbshipit-source-id: 2018112d7da7553a9f635ada8fbf0fe3315fed32
1 parent c08651b commit 4a9d56e

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

shed/stats/src/macros.rs

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ pub mod common_macro_prelude {
3939
pub use crate::thread_local_aggregator::create_map;
4040
}
4141

42-
/// The macro to define STATS module that contains static variables, one per counter you want to
43-
/// export. This is the main and recomended way to interact with statistics provided by this crate.
44-
/// If non empty prefix is passed then the exported counter name will be "{prefix}.{name}"
42+
/// The macro to define STATS module that contains static variables, one per
43+
/// counter you want to export. This is the main and recommended way to interact
44+
/// with statistics provided by this crate. If non empty prefix is passed then
45+
/// the exported counter name will be "{prefix}.{name}"
4546
///
4647
/// Examples:
4748
/// ```
@@ -91,6 +92,70 @@ pub mod common_macro_prelude {
9192
/// ALT_STATS::test_t2.add_value(1);
9293
/// }
9394
/// ```
95+
///
96+
/// # Reference
97+
///
98+
/// ## `singleton_counter`, `counter`
99+
/// Raw counter types. These take an optional key parameter - if it is not
100+
/// specified, then it's derived from the stat field name.
101+
///
102+
/// These are deprecated in favor of `timeseries`.
103+
///
104+
/// # `timeseries`
105+
/// The general syntax for `timeseries` is:
106+
/// ```text
107+
/// timeseries(<optional key>; <list of aggregations>; [optional intervals])
108+
/// ```
109+
///
110+
/// If "optional key" is omitted then key is derived from the stat key name;
111+
/// otherwise it's a string literal.
112+
///
113+
/// "List of aggregations" is a slice of
114+
/// [`AggregationType`](stats_traits::stats_manager::AggregationType) enum
115+
/// values.
116+
///
117+
/// "Optional intervals" is a slice of [`Duration`s](std::time::Duration). It
118+
/// specifies over what time periods the aggregations aggregate. If not
119+
/// specified, it typically defaults to 60 seconds.
120+
///
121+
/// This maps to a call to
122+
/// [`StatsManager::create_timeseries`](stats_traits::stats_manager::StatsManager::create_histogram).
123+
///
124+
/// # `histogram`
125+
/// The general syntax for `histogram` is:
126+
/// ```text
127+
/// histogram(<optional key>; bucket-width, min, max, <list of aggregations>; <P XX percentiles>)
128+
/// ```
129+
/// If "optional key" is omitted then key is derived from the stat key name;
130+
/// otherwise it's a string literal.
131+
///
132+
/// `bucket-width` specifies what range of values are accumulated into each
133+
/// bucket; the larger it is the fewer buckets there are.
134+
///
135+
/// `min` and `max` specify the min and max of the expected range of samples.
136+
/// Samples outside this range will be aggregated into out-of-range buckets,
137+
/// which means they're not lost entirely but they lead to inaccurate stats.
138+
///
139+
/// Together the min, max and bucket width parameters determine how many buckets
140+
/// are created.
141+
///
142+
/// "List of aggregations" is a slice of
143+
/// [`AggregationType`](stats_traits::stats_manager::AggregationType) enum
144+
/// values.
145+
///
146+
/// Percentiles are specified as `P NN` in a `;`-separated list, such as `P 20;
147+
/// P 50; P 90; P 99`...
148+
///
149+
/// This maps to a call to
150+
/// [`StatsManager::create_histogram`](stats_traits::stats_manager::StatsManager::create_histogram).
151+
///
152+
/// # `dynamic_counter`, `dynamic_timeseries`, `dynamic_histogram`
153+
///
154+
/// These are equivalent to the corresponding `counter`/`timeseries`/`histogram`
155+
/// above, except that they allow the key to have a dynamic component. The key
156+
/// is no longer optional, but is instead specified with `<format-string>,
157+
/// (variable:type, ...)`. The format string is standard
158+
/// [`format!`](std::format).
94159
#[macro_export]
95160
macro_rules! define_stats {
96161
// Fill the optional prefix with empty string, all matching is repeated here to avoid the

0 commit comments

Comments
 (0)