Skip to content

Commit fbfeb9a

Browse files
authored
metrics: rename *_poll_count_* to *_poll_time_* (#6924)
A consistent bit of feedback I've heard is that the `poll_count_histogram` name is a little confusing since the value customers actually get out of it is `poll_times`. This renames all public APIs from `poll_count` to `poll_time`. The existing APIs were deprecated with one exception: the newly added `poll_count_histogram_configuration` which hasn't been released yet was simply renamed.
1 parent da745ff commit fbfeb9a

File tree

3 files changed

+119
-82
lines changed

3 files changed

+119
-82
lines changed

tokio/src/runtime/builder.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,12 @@ impl Builder {
10991099
///
11001100
/// The histogram uses fixed bucket sizes. In other words, the histogram
11011101
/// buckets are not dynamic based on input values. Use the
1102-
/// `metrics_poll_count_histogram_` builder methods to configure the
1102+
/// `metrics_poll_time_histogram` builder methods to configure the
11031103
/// histogram details.
11041104
///
11051105
/// By default, a linear histogram with 10 buckets each 100 microseconds wide will be used.
11061106
/// This has an extremely low memory footprint, but may not provide enough granularity. For
1107-
/// better granularity with low memory usage, use [`metrics_poll_count_histogram_configuration()`]
1107+
/// better granularity with low memory usage, use [`metrics_poll_time_histogram_configuration()`]
11081108
/// to select [`LogHistogram`] instead.
11091109
///
11101110
/// # Examples
@@ -1113,26 +1113,35 @@ impl Builder {
11131113
/// use tokio::runtime;
11141114
///
11151115
/// let rt = runtime::Builder::new_multi_thread()
1116-
/// .enable_metrics_poll_count_histogram()
1116+
/// .enable_metrics_poll_time_histogram()
11171117
/// .build()
11181118
/// .unwrap();
11191119
/// # // Test default values here
11201120
/// # fn us(n: u64) -> std::time::Duration { std::time::Duration::from_micros(n) }
11211121
/// # let m = rt.handle().metrics();
1122-
/// # assert_eq!(m.poll_count_histogram_num_buckets(), 10);
1123-
/// # assert_eq!(m.poll_count_histogram_bucket_range(0), us(0)..us(100));
1124-
/// # assert_eq!(m.poll_count_histogram_bucket_range(1), us(100)..us(200));
1122+
/// # assert_eq!(m.poll_time_histogram_num_buckets(), 10);
1123+
/// # assert_eq!(m.poll_time_histogram_bucket_range(0), us(0)..us(100));
1124+
/// # assert_eq!(m.poll_time_histogram_bucket_range(1), us(100)..us(200));
11251125
/// ```
11261126
///
11271127
/// [`Handle::metrics()`]: crate::runtime::Handle::metrics
11281128
/// [`Instant::now()`]: std::time::Instant::now
11291129
/// [`LogHistogram`]: crate::runtime::LogHistogram
1130-
/// [`metrics_poll_count_histogram_configuration()`]: Builder::metrics_poll_count_histogram_configuration
1131-
pub fn enable_metrics_poll_count_histogram(&mut self) -> &mut Self {
1130+
/// [`metrics_poll_time_histogram_configuration()`]: Builder::metrics_poll_time_histogram_configuration
1131+
pub fn enable_metrics_poll_time_histogram(&mut self) -> &mut Self {
11321132
self.metrics_poll_count_histogram_enable = true;
11331133
self
11341134
}
11351135

1136+
/// Deprecated. Use [`enable_metrics_poll_time_histogram()`] instead.
1137+
///
1138+
/// [`enable_metrics_poll_time_histogram()`]: Builder::enable_metrics_poll_time_histogram
1139+
#[deprecated(note = "`poll_count_histogram` related methods have been renamed `poll_time_histogram` to better reflect their functionality.")]
1140+
#[doc(hidden)]
1141+
pub fn enable_metrics_poll_count_histogram(&mut self) -> &mut Self {
1142+
self.enable_metrics_poll_time_histogram()
1143+
}
1144+
11361145
/// Sets the histogram scale for tracking the distribution of task poll
11371146
/// times.
11381147
///
@@ -1151,12 +1160,12 @@ impl Builder {
11511160
///
11521161
/// # #[allow(deprecated)]
11531162
/// let rt = runtime::Builder::new_multi_thread()
1154-
/// .enable_metrics_poll_count_histogram()
1163+
/// .enable_metrics_poll_time_histogram()
11551164
/// .metrics_poll_count_histogram_scale(HistogramScale::Log)
11561165
/// .build()
11571166
/// .unwrap();
11581167
/// ```
1159-
#[deprecated(note = "use metrics_poll_count_histogram_configuration")]
1168+
#[deprecated(note = "use `metrics_poll_time_histogram_configuration`")]
11601169
pub fn metrics_poll_count_histogram_scale(&mut self, histogram_scale: crate::runtime::HistogramScale) -> &mut Self {
11611170
self.metrics_poll_count_histogram.legacy_mut(|b|b.scale = histogram_scale);
11621171
self
@@ -1175,8 +1184,8 @@ impl Builder {
11751184
/// use tokio::runtime::{HistogramConfiguration, LogHistogram};
11761185
///
11771186
/// let rt = runtime::Builder::new_multi_thread()
1178-
/// .enable_metrics_poll_count_histogram()
1179-
/// .metrics_poll_count_histogram_configuration(
1187+
/// .enable_metrics_poll_time_histogram()
1188+
/// .metrics_poll_time_histogram_configuration(
11801189
/// HistogramConfiguration::log(LogHistogram::default())
11811190
/// )
11821191
/// .build()
@@ -1190,8 +1199,8 @@ impl Builder {
11901199
/// use tokio::runtime::HistogramConfiguration;
11911200
///
11921201
/// let rt = runtime::Builder::new_multi_thread()
1193-
/// .enable_metrics_poll_count_histogram()
1194-
/// .metrics_poll_count_histogram_configuration(
1202+
/// .enable_metrics_poll_time_histogram()
1203+
/// .metrics_poll_time_histogram_configuration(
11951204
/// HistogramConfiguration::linear(Duration::from_micros(10), 100)
11961205
/// )
11971206
/// .build()
@@ -1208,8 +1217,8 @@ impl Builder {
12081217
/// use tokio::runtime::{HistogramConfiguration, LogHistogram};
12091218
///
12101219
/// let rt = runtime::Builder::new_multi_thread()
1211-
/// .enable_metrics_poll_count_histogram()
1212-
/// .metrics_poll_count_histogram_configuration(
1220+
/// .enable_metrics_poll_time_histogram()
1221+
/// .metrics_poll_time_histogram_configuration(
12131222
/// HistogramConfiguration::log(LogHistogram::builder()
12141223
/// .max_value(Duration::from_secs(120))
12151224
/// .min_value(Duration::from_nanos(100))
@@ -1224,7 +1233,7 @@ impl Builder {
12241233
///
12251234
/// [`LogHistogram`]: crate::runtime::LogHistogram
12261235
/// [default configuration]: crate::runtime::LogHistogramBuilder
1227-
pub fn metrics_poll_count_histogram_configuration(&mut self, configuration: HistogramConfiguration) -> &mut Self {
1236+
pub fn metrics_poll_time_histogram_configuration(&mut self, configuration: HistogramConfiguration) -> &mut Self {
12281237
self.metrics_poll_count_histogram.histogram_type = configuration.inner;
12291238
self
12301239
}
@@ -1251,12 +1260,12 @@ impl Builder {
12511260
///
12521261
/// # #[allow(deprecated)]
12531262
/// let rt = runtime::Builder::new_multi_thread()
1254-
/// .enable_metrics_poll_count_histogram()
1263+
/// .enable_metrics_poll_time_histogram()
12551264
/// .metrics_poll_count_histogram_resolution(Duration::from_micros(100))
12561265
/// .build()
12571266
/// .unwrap();
12581267
/// ```
1259-
#[deprecated(note = "use metrics_poll_count_histogram_configuration")]
1268+
#[deprecated(note = "use `metrics_poll_time_histogram_configuration`")]
12601269
pub fn metrics_poll_count_histogram_resolution(&mut self, resolution: Duration) -> &mut Self {
12611270
assert!(resolution > Duration::from_secs(0));
12621271
// Sanity check the argument and also make the cast below safe.
@@ -1285,12 +1294,12 @@ impl Builder {
12851294
///
12861295
/// # #[allow(deprecated)]
12871296
/// let rt = runtime::Builder::new_multi_thread()
1288-
/// .enable_metrics_poll_count_histogram()
1297+
/// .enable_metrics_poll_time_histogram()
12891298
/// .metrics_poll_count_histogram_buckets(15)
12901299
/// .build()
12911300
/// .unwrap();
12921301
/// ```
1293-
#[deprecated(note = "use `metrics_poll_count_histogram_configuration")]
1302+
#[deprecated(note = "use `metrics_poll_time_histogram_configuration`")]
12941303
pub fn metrics_poll_count_histogram_buckets(&mut self, buckets: usize) -> &mut Self {
12951304
self.metrics_poll_count_histogram.legacy_mut(|b|b.num_buckets = buckets);
12961305
self

tokio/src/runtime/metrics/runtime.rs

+56-25
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl RuntimeMetrics {
731731
///
732732
/// Task poll times are not instrumented by default as doing so requires
733733
/// calling [`Instant::now()`] twice per task poll. The feature is enabled
734-
/// by calling [`enable_metrics_poll_count_histogram()`] when building the
734+
/// by calling [`enable_metrics_poll_time_histogram()`] when building the
735735
/// runtime.
736736
///
737737
/// # Examples
@@ -741,33 +741,39 @@ impl RuntimeMetrics {
741741
///
742742
/// fn main() {
743743
/// runtime::Builder::new_current_thread()
744-
/// .enable_metrics_poll_count_histogram()
744+
/// .enable_metrics_poll_time_histogram()
745745
/// .build()
746746
/// .unwrap()
747747
/// .block_on(async {
748748
/// let metrics = Handle::current().metrics();
749-
/// let enabled = metrics.poll_count_histogram_enabled();
749+
/// let enabled = metrics.poll_time_histogram_enabled();
750750
///
751751
/// println!("Tracking task poll time distribution: {:?}", enabled);
752752
/// });
753753
/// }
754754
/// ```
755755
///
756-
/// [`enable_metrics_poll_count_histogram()`]: crate::runtime::Builder::enable_metrics_poll_count_histogram
756+
/// [`enable_metrics_poll_time_histogram()`]: crate::runtime::Builder::enable_metrics_poll_time_histogram
757757
/// [`Instant::now()`]: std::time::Instant::now
758-
pub fn poll_count_histogram_enabled(&self) -> bool {
758+
pub fn poll_time_histogram_enabled(&self) -> bool {
759759
self.handle
760760
.inner
761761
.worker_metrics(0)
762762
.poll_count_histogram
763763
.is_some()
764764
}
765765

766+
#[deprecated(note = "Renamed to `poll_time_histogram_enabled`")]
767+
#[doc(hidden)]
768+
pub fn poll_count_histogram_enabled(&self) -> bool {
769+
self.poll_time_histogram_enabled()
770+
}
771+
766772
/// Returns the number of histogram buckets tracking the distribution of
767773
/// task poll times.
768774
///
769775
/// This value is configured by calling
770-
/// [`metrics_poll_count_histogram_configuration()`] when building the runtime.
776+
/// [`metrics_poll_time_histogram_configuration()`] when building the runtime.
771777
///
772778
/// # Examples
773779
///
@@ -776,21 +782,21 @@ impl RuntimeMetrics {
776782
///
777783
/// fn main() {
778784
/// runtime::Builder::new_current_thread()
779-
/// .enable_metrics_poll_count_histogram()
785+
/// .enable_metrics_poll_time_histogram()
780786
/// .build()
781787
/// .unwrap()
782788
/// .block_on(async {
783789
/// let metrics = Handle::current().metrics();
784-
/// let buckets = metrics.poll_count_histogram_num_buckets();
790+
/// let buckets = metrics.poll_time_histogram_num_buckets();
785791
///
786792
/// println!("Histogram buckets: {:?}", buckets);
787793
/// });
788794
/// }
789795
/// ```
790796
///
791-
/// [`metrics_poll_count_histogram_configuration()`]:
792-
/// crate::runtime::Builder::metrics_poll_count_histogram_configuration
793-
pub fn poll_count_histogram_num_buckets(&self) -> usize {
797+
/// [`metrics_poll_time_histogram_configuration()`]:
798+
/// crate::runtime::Builder::metrics_poll_time_histogram_configuration
799+
pub fn poll_time_histogram_num_buckets(&self) -> usize {
794800
self.handle
795801
.inner
796802
.worker_metrics(0)
@@ -800,15 +806,24 @@ impl RuntimeMetrics {
800806
.unwrap_or_default()
801807
}
802808

809+
/// Deprecated. Use [`poll_time_histogram_num_buckets()`] instead.
810+
///
811+
/// [`poll_time_histogram_num_buckets()`]: Self::poll_time_histogram_num_buckets
812+
#[doc(hidden)]
813+
#[deprecated(note = "renamed to `poll_time_histogram_num_buckets`.")]
814+
pub fn poll_count_histogram_num_buckets(&self) -> usize {
815+
self.poll_time_histogram_num_buckets()
816+
}
817+
803818
/// Returns the range of task poll times tracked by the given bucket.
804819
///
805820
/// This value is configured by calling
806-
/// [`metrics_poll_count_histogram_configuration()`] when building the runtime.
821+
/// [`metrics_poll_time_histogram_configuration()`] when building the runtime.
807822
///
808823
/// # Panics
809824
///
810825
/// The method panics if `bucket` represents an invalid bucket index, i.e.
811-
/// is greater than or equal to `poll_count_histogram_num_buckets()`.
826+
/// is greater than or equal to `poll_time_histogram_num_buckets()`.
812827
///
813828
/// # Examples
814829
///
@@ -817,25 +832,25 @@ impl RuntimeMetrics {
817832
///
818833
/// fn main() {
819834
/// runtime::Builder::new_current_thread()
820-
/// .enable_metrics_poll_count_histogram()
835+
/// .enable_metrics_poll_time_histogram()
821836
/// .build()
822837
/// .unwrap()
823838
/// .block_on(async {
824839
/// let metrics = Handle::current().metrics();
825-
/// let buckets = metrics.poll_count_histogram_num_buckets();
840+
/// let buckets = metrics.poll_time_histogram_num_buckets();
826841
///
827842
/// for i in 0..buckets {
828-
/// let range = metrics.poll_count_histogram_bucket_range(i);
843+
/// let range = metrics.poll_time_histogram_bucket_range(i);
829844
/// println!("Histogram bucket {} range: {:?}", i, range);
830845
/// }
831846
/// });
832847
/// }
833848
/// ```
834849
///
835-
/// [`metrics_poll_count_histogram_configuration()`]:
836-
/// crate::runtime::Builder::metrics_poll_count_histogram_configuration
850+
/// [`metrics_poll_time_histogram_configuration()`]:
851+
/// crate::runtime::Builder::metrics_poll_time_histogram_configuration
837852
#[track_caller]
838-
pub fn poll_count_histogram_bucket_range(&self, bucket: usize) -> Range<Duration> {
853+
pub fn poll_time_histogram_bucket_range(&self, bucket: usize) -> Range<Duration> {
839854
self.handle
840855
.inner
841856
.worker_metrics(0)
@@ -851,6 +866,16 @@ impl RuntimeMetrics {
851866
.unwrap_or_default()
852867
}
853868

869+
/// Deprecated. Use [`poll_time_histogram_bucket_range()`] instead.
870+
///
871+
/// [`poll_time_histogram_bucket_range()`]: Self::poll_time_histogram_bucket_range
872+
#[track_caller]
873+
#[doc(hidden)]
874+
#[deprecated(note = "renamed to `poll_time_histogram_bucket_range`")]
875+
pub fn poll_count_histogram_bucket_range(&self, bucket: usize) -> Range<Duration> {
876+
self.poll_time_histogram_bucket_range(bucket)
877+
}
878+
854879
cfg_64bit_metrics! {
855880
/// Returns the number of times the given worker polled tasks with a poll
856881
/// duration within the given bucket's range.
@@ -872,7 +897,7 @@ impl RuntimeMetrics {
872897
///
873898
/// `bucket` is the index of the bucket being queried. The bucket is scoped
874899
/// to the worker. The range represented by the bucket can be queried by
875-
/// calling [`poll_count_histogram_bucket_range()`]. Each worker maintains
900+
/// calling [`poll_time_histogram_bucket_range()`]. Each worker maintains
876901
/// identical bucket ranges.
877902
///
878903
/// # Panics
@@ -888,26 +913,26 @@ impl RuntimeMetrics {
888913
///
889914
/// fn main() {
890915
/// runtime::Builder::new_current_thread()
891-
/// .enable_metrics_poll_count_histogram()
916+
/// .enable_metrics_poll_time_histogram()
892917
/// .build()
893918
/// .unwrap()
894919
/// .block_on(async {
895920
/// let metrics = Handle::current().metrics();
896-
/// let buckets = metrics.poll_count_histogram_num_buckets();
921+
/// let buckets = metrics.poll_time_histogram_num_buckets();
897922
///
898923
/// for worker in 0..metrics.num_workers() {
899924
/// for i in 0..buckets {
900-
/// let count = metrics.poll_count_histogram_bucket_count(worker, i);
925+
/// let count = metrics.poll_time_histogram_bucket_count(worker, i);
901926
/// println!("Poll count {}", count);
902927
/// }
903928
/// }
904929
/// });
905930
/// }
906931
/// ```
907932
///
908-
/// [`poll_count_histogram_bucket_range()`]: crate::runtime::RuntimeMetrics::poll_count_histogram_bucket_range
933+
/// [`poll_time_histogram_bucket_range()`]: crate::runtime::RuntimeMetrics::poll_time_histogram_bucket_range
909934
#[track_caller]
910-
pub fn poll_count_histogram_bucket_count(&self, worker: usize, bucket: usize) -> u64 {
935+
pub fn poll_time_histogram_bucket_count(&self, worker: usize, bucket: usize) -> u64 {
911936
self.handle
912937
.inner
913938
.worker_metrics(worker)
@@ -917,6 +942,12 @@ impl RuntimeMetrics {
917942
.unwrap_or_default()
918943
}
919944

945+
#[doc(hidden)]
946+
#[deprecated(note = "use `poll_time_histogram_bucket_count` instead")]
947+
pub fn poll_count_histogram_bucket_count(&self, worker: usize, bucket: usize) -> u64 {
948+
self.poll_time_histogram_bucket_count(worker, bucket)
949+
}
950+
920951
/// Returns the mean duration of task polls, in nanoseconds.
921952
///
922953
/// This is an exponentially weighted moving average. Currently, this metric

0 commit comments

Comments
 (0)