@@ -6,6 +6,8 @@ use crate::runtime::TaskMeta;
6
6
use crate :: runtime:: { blocking, driver, Callback , HistogramBuilder , Runtime , TaskCallback } ;
7
7
use crate :: util:: rand:: { RngSeed , RngSeedGenerator } ;
8
8
9
+ #[ cfg( tokio_unstable) ]
10
+ use crate :: runtime:: metrics:: HistogramConfiguration ;
9
11
use std:: fmt;
10
12
use std:: io;
11
13
use std:: time:: Duration ;
@@ -1068,6 +1070,11 @@ impl Builder {
1068
1070
/// `metrics_poll_count_histogram_` builder methods to configure the
1069
1071
/// histogram details.
1070
1072
///
1073
+ /// By default, a linear histogram with 10 buckets each 100 microseconds wide will be used.
1074
+ /// This has an extremely low memory footprint, but may not provide enough granularity. For
1075
+ /// better granularity with low memory usage, use [`metrics_poll_count_histogram_configuration()`]
1076
+ /// to select [`LogHistogram`] instead.
1077
+ ///
1071
1078
/// # Examples
1072
1079
///
1073
1080
/// ```
@@ -1087,6 +1094,8 @@ impl Builder {
1087
1094
///
1088
1095
/// [`Handle::metrics()`]: crate::runtime::Handle::metrics
1089
1096
/// [`Instant::now()`]: std::time::Instant::now
1097
+ /// [`LogHistogram`]: crate::runtime::LogHistogram
1098
+ /// [`metrics_poll_count_histogram_configuration()`]: Builder::metrics_poll_count_histogram_configuration
1090
1099
pub fn enable_metrics_poll_count_histogram( & mut self ) -> & mut Self {
1091
1100
self . metrics_poll_count_histogram_enable = true ;
1092
1101
self
@@ -1108,14 +1117,58 @@ impl Builder {
1108
1117
/// ```
1109
1118
/// use tokio::runtime::{self, HistogramScale};
1110
1119
///
1120
+ /// # #[allow(deprecated)]
1111
1121
/// let rt = runtime::Builder::new_multi_thread()
1112
1122
/// .enable_metrics_poll_count_histogram()
1113
1123
/// .metrics_poll_count_histogram_scale(HistogramScale::Log)
1114
1124
/// .build()
1115
1125
/// .unwrap();
1116
1126
/// ```
1127
+ #[ deprecated( note = "use metrics_poll_count_histogram_configuration" ) ]
1117
1128
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;
1129
+ self . metrics_poll_count_histogram. legacy_mut( |b|b. scale = histogram_scale) ;
1130
+ self
1131
+ }
1132
+
1133
+ /// Configure the histogram for tracking poll times
1134
+ ///
1135
+ /// By default, a linear histogram with 10 buckets each 100 microseconds wide will be used.
1136
+ /// This has an extremely low memory footprint, but may not provide enough granularity. For
1137
+ /// better granularity with low memory usage, use [`LogHistogram`] instead.
1138
+ ///
1139
+ /// # Examples
1140
+ /// Configure a `LogHistogram` with default configuration:
1141
+ /// ```
1142
+ /// use tokio::runtime;
1143
+ /// use tokio::runtime::{HistogramConfiguration, LogHistogram};
1144
+ ///
1145
+ /// let rt = runtime::Builder::new_multi_thread()
1146
+ /// .enable_metrics_poll_count_histogram()
1147
+ /// .metrics_poll_count_histogram_configuration(
1148
+ /// HistogramConfiguration::log(LogHistogram::default())
1149
+ /// )
1150
+ /// .build()
1151
+ /// .unwrap();
1152
+ /// ```
1153
+ ///
1154
+ /// Configure a linear histogram
1155
+ /// ```
1156
+ /// use tokio::runtime;
1157
+ /// use std::time::Duration;
1158
+ /// use tokio::runtime::HistogramConfiguration;
1159
+ ///
1160
+ /// let rt = runtime::Builder::new_multi_thread()
1161
+ /// .enable_metrics_poll_count_histogram()
1162
+ /// .metrics_poll_count_histogram_configuration(
1163
+ /// HistogramConfiguration::linear(Duration::from_micros(10), 100)
1164
+ /// )
1165
+ /// .build()
1166
+ /// .unwrap();
1167
+ /// ```
1168
+ ///
1169
+ /// [`LogHistogram`]: crate::runtime::LogHistogram
1170
+ pub fn metrics_poll_count_histogram_configuration( & mut self , configuration: HistogramConfiguration ) -> & mut Self {
1171
+ self . metrics_poll_count_histogram. histogram_type = configuration. inner;
1119
1172
self
1120
1173
}
1121
1174
@@ -1139,19 +1192,22 @@ impl Builder {
1139
1192
/// use tokio::runtime;
1140
1193
/// use std::time::Duration;
1141
1194
///
1195
+ /// # #[allow(deprecated)]
1142
1196
/// let rt = runtime::Builder::new_multi_thread()
1143
1197
/// .enable_metrics_poll_count_histogram()
1144
1198
/// .metrics_poll_count_histogram_resolution(Duration::from_micros(100))
1145
1199
/// .build()
1146
1200
/// .unwrap();
1147
1201
/// ```
1202
+ #[ deprecated( note = "use metrics_poll_count_histogram_configuration" ) ]
1148
1203
pub fn metrics_poll_count_histogram_resolution( & mut self , resolution: Duration ) -> & mut Self {
1149
1204
assert!( resolution > Duration :: from_secs( 0 ) ) ;
1150
1205
// Sanity check the argument and also make the cast below safe.
1151
1206
assert!( resolution <= Duration :: from_secs( 1 ) ) ;
1152
1207
1153
1208
let resolution = resolution. as_nanos( ) as u64 ;
1154
- self . metrics_poll_count_histogram. resolution = resolution;
1209
+
1210
+ self . metrics_poll_count_histogram. legacy_mut( |b|b. resolution = resolution) ;
1155
1211
self
1156
1212
}
1157
1213
@@ -1170,14 +1226,16 @@ impl Builder {
1170
1226
/// ```
1171
1227
/// use tokio::runtime;
1172
1228
///
1229
+ /// # #[allow(deprecated)]
1173
1230
/// let rt = runtime::Builder::new_multi_thread()
1174
1231
/// .enable_metrics_poll_count_histogram()
1175
1232
/// .metrics_poll_count_histogram_buckets(15)
1176
1233
/// .build()
1177
1234
/// .unwrap();
1178
1235
/// ```
1236
+ #[ deprecated( note = "use `metrics_poll_count_histogram_configuration" ) ]
1179
1237
pub fn metrics_poll_count_histogram_buckets( & mut self , buckets: usize ) -> & mut Self {
1180
- self . metrics_poll_count_histogram. num_buckets = buckets;
1238
+ self . metrics_poll_count_histogram. legacy_mut ( |b|b . num_buckets = buckets) ;
1181
1239
self
1182
1240
}
1183
1241
}
0 commit comments