Skip to content

Commit

Permalink
[metrics] Add H2 Histogram option to improve histogram granularity
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Oct 9, 2024
1 parent 679d765 commit 62290e9
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 115 deletions.
1 change: 1 addition & 0 deletions tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ tokio-stream = { version = "0.1", path = "../tokio-stream" }
futures = { version = "0.3.0", features = ["async-await"] }
mockall = "0.11.1"
async-stream = "0.3"
proptest = "1.5.0"

[target.'cfg(not(target_family = "wasm"))'.dev-dependencies]
socket2 = "0.5.5"
Expand Down
32 changes: 29 additions & 3 deletions tokio/src/runtime/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use crate::runtime::TaskMeta;
use crate::runtime::{blocking, driver, Callback, HistogramBuilder, Runtime, TaskCallback};
use crate::util::rand::{RngSeed, RngSeedGenerator};

#[cfg(tokio_unstable)]
use crate::runtime::metrics::HistogramConfiguration;
use std::fmt;
use std::io;
use std::time::Duration;
Expand Down Expand Up @@ -1114,8 +1116,29 @@ impl Builder {
/// .build()
/// .unwrap();
/// ```
#[deprecated(note = "use metrics_poll_count_histogram_configuration")]
pub fn metrics_poll_count_histogram_scale(&mut self, histogram_scale: crate::runtime::HistogramScale) -> &mut Self {
self.metrics_poll_count_histogram.scale = histogram_scale;
self.metrics_poll_count_histogram.legacy_mut(|b|b.scale = histogram_scale);
self
}

/// Configure the poll_count histogram
///
/// # Examples
/// Configure the default `LogHistogram`:
/// ```
/// use tokio::runtime;
/// use std::time::Duration;
/// use tokio::runtime::{HistogramConfiguration, LogHistogram};
///
/// let rt = runtime::Builder::new_multi_thread()
/// .enable_metrics_poll_count_histogram()
/// .metrics_poll_count_histogram_configuration(HistogramConfiguration::log(LogHistogram::default()))
/// .build()
/// .unwrap();
/// ```
pub fn metrics_poll_count_histogram_configuration(&mut self, configuration: HistogramConfiguration) -> &mut Self {
self.metrics_poll_count_histogram.histogram_type = configuration.inner;
self
}

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

let resolution = resolution.as_nanos() as u64;
self.metrics_poll_count_histogram.resolution = resolution;

self.metrics_poll_count_histogram.legacy_mut(|b|b.resolution = resolution);
self
}

Expand All @@ -1176,8 +1201,9 @@ impl Builder {
/// .build()
/// .unwrap();
/// ```
#[deprecated(note = "use `metrics_poll_count_histogram_configuration")]
pub fn metrics_poll_count_histogram_buckets(&mut self, buckets: usize) -> &mut Self {
self.metrics_poll_count_histogram.num_buckets = buckets;
self.metrics_poll_count_histogram.legacy_mut(|b|b.num_buckets = buckets);
self
}
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/metrics/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ cfg_rt_multi_thread! {
}
}

fn duration_as_u64(dur: Duration) -> u64 {
pub(crate) fn duration_as_u64(dur: Duration) -> u64 {
u64::try_from(dur.as_nanos()).unwrap_or(u64::MAX)
}
Loading

0 comments on commit 62290e9

Please sign in to comment.