Skip to content

Commit 1501559

Browse files
committed
[metrics] Add H2 Histogram option to improve histogram granularity
1 parent 679d765 commit 1501559

File tree

8 files changed

+727
-115
lines changed

8 files changed

+727
-115
lines changed

tokio/src/runtime/builder.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::runtime::TaskMeta;
66
use crate::runtime::{blocking, driver, Callback, HistogramBuilder, Runtime, TaskCallback};
77
use crate::util::rand::{RngSeed, RngSeedGenerator};
88

9+
#[cfg(tokio_unstable)]
10+
use crate::runtime::metrics::HistogramConfiguration;
911
use std::fmt;
1012
use std::io;
1113
use std::time::Duration;
@@ -1114,8 +1116,29 @@ impl Builder {
11141116
/// .build()
11151117
/// .unwrap();
11161118
/// ```
1119+
#[deprecated(note = "use metrics_poll_count_histogram_configuration")]
11171120
pub fn metrics_poll_count_histogram_scale(&mut self, histogram_scale: crate::runtime::HistogramScale) -> &mut Self {
1118-
self.metrics_poll_count_histogram.scale = histogram_scale;
1121+
self.metrics_poll_count_histogram.legacy_mut(|b|b.scale = histogram_scale);
1122+
self
1123+
}
1124+
1125+
/// Configure the poll_count histogram
1126+
///
1127+
/// # Examples
1128+
/// Configure the default `LogHistogram`:
1129+
/// ```
1130+
/// use tokio::runtime;
1131+
/// use std::time::Duration;
1132+
/// use tokio::runtime::{HistogramConfiguration, LogHistogram};
1133+
///
1134+
/// let rt = runtime::Builder::new_multi_thread()
1135+
/// .enable_metrics_poll_count_histogram()
1136+
/// .metrics_poll_count_histogram_configuration(HistogramConfiguration::log(LogHistogram::default()))
1137+
/// .build()
1138+
/// .unwrap();
1139+
/// ```
1140+
pub fn metrics_poll_count_histogram_configuration(&mut self, configuration: HistogramConfiguration) -> &mut Self {
1141+
self.metrics_poll_count_histogram.histogram_type = configuration.inner;
11191142
self
11201143
}
11211144

@@ -1145,13 +1168,15 @@ impl Builder {
11451168
/// .build()
11461169
/// .unwrap();
11471170
/// ```
1171+
#[deprecated(note = "use metrics_poll_count_histogram_configuration")]
11481172
pub fn metrics_poll_count_histogram_resolution(&mut self, resolution: Duration) -> &mut Self {
11491173
assert!(resolution > Duration::from_secs(0));
11501174
// Sanity check the argument and also make the cast below safe.
11511175
assert!(resolution <= Duration::from_secs(1));
11521176

11531177
let resolution = resolution.as_nanos() as u64;
1154-
self.metrics_poll_count_histogram.resolution = resolution;
1178+
1179+
self.metrics_poll_count_histogram.legacy_mut(|b|b.resolution = resolution);
11551180
self
11561181
}
11571182

@@ -1176,8 +1201,9 @@ impl Builder {
11761201
/// .build()
11771202
/// .unwrap();
11781203
/// ```
1204+
#[deprecated(note = "use `metrics_poll_count_histogram_configuration")]
11791205
pub fn metrics_poll_count_histogram_buckets(&mut self, buckets: usize) -> &mut Self {
1180-
self.metrics_poll_count_histogram.num_buckets = buckets;
1206+
self.metrics_poll_count_histogram.legacy_mut(|b|b.num_buckets = buckets);
11811207
self
11821208
}
11831209
}

tokio/src/runtime/metrics/batch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,6 @@ cfg_rt_multi_thread! {
171171
}
172172
}
173173

174-
fn duration_as_u64(dur: Duration) -> u64 {
174+
pub(crate) fn duration_as_u64(dur: Duration) -> u64 {
175175
u64::try_from(dur.as_nanos()).unwrap_or(u64::MAX)
176176
}

0 commit comments

Comments
 (0)