Skip to content

Commit 0fd010f

Browse files
committed
rename to 'alive_tasks'
1 parent 8dff8c1 commit 0fd010f

File tree

5 files changed

+14
-104
lines changed

5 files changed

+14
-104
lines changed

tokio/src/runtime/metrics/runtime.rs

+8-31
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ impl RuntimeMetrics {
4747
self.handle.inner.num_workers()
4848
}
4949

50-
/// Returns the current number of active tasks in the runtime.
50+
/// Returns the current number of alive tasks in the runtime.
5151
///
52-
/// This value increases and decreases over time as tasks are spawned and as they are completed or cancelled.
53-
///
54-
/// To see the total number of spawned tasks, see `spawned_tasks_count`.
52+
/// This counter increases when a task is spawned and decreases when a
53+
/// task exits.
5554
///
5655
/// # Examples
5756
///
@@ -62,12 +61,12 @@ impl RuntimeMetrics {
6261
/// async fn main() {
6362
/// let metrics = Handle::current().metrics();
6463
///
65-
/// let n = metrics.num_active_tasks();
66-
/// println!("Runtime has {} active tasks", n);
64+
/// let n = metrics.num_alive_tasks();
65+
/// println!("Runtime has {} alive tasks", n);
6766
/// }
6867
/// ```
69-
pub fn num_active_tasks(&self) -> usize {
70-
self.handle.inner.num_active_tasks()
68+
pub fn num_alive_tasks(&self) -> usize {
69+
self.handle.inner.num_alive_tasks()
7170
}
7271

7372
cfg_unstable_metrics! {
@@ -101,29 +100,7 @@ impl RuntimeMetrics {
101100
#[deprecated = "Renamed to num_alive_tasks"]
102101
/// Renamed to [`RuntimeMetrics::num_alive_tasks`]
103102
pub fn active_tasks_count(&self) -> usize {
104-
self.num_active_tasks()
105-
}
106-
107-
/// Returns the current number of alive tasks in the runtime.
108-
///
109-
/// This counter increases when a task is spawned and decreases when a
110-
/// task exits.
111-
///
112-
/// # Examples
113-
///
114-
/// ```
115-
/// use tokio::runtime::Handle;
116-
///
117-
/// #[tokio::main]
118-
/// async fn main() {
119-
/// let metrics = Handle::current().metrics();
120-
///
121-
/// let n = metrics.num_alive_tasks();
122-
/// println!("Runtime has {} alive tasks", n);
123-
/// }
124-
/// ```
125-
pub fn num_alive_tasks(&self) -> usize {
126-
self.handle.inner.alive_tasks_count()
103+
self.num_alive_tasks()
127104
}
128105

129106
/// Returns the number of idle threads, which have spawned by the runtime

tokio/src/runtime/scheduler/current_thread/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ impl Handle {
501501
self.shared.woken.swap(false, AcqRel)
502502
}
503503

504-
pub(crate) fn num_active_tasks(&self) -> usize {
505-
self.shared.owned.num_active_tasks()
504+
pub(crate) fn alive_tasks_count(&self) -> usize {
505+
self.shared.owned.alive_tasks_count()
506506
}
507507
}
508508

tokio/src/runtime/scheduler/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ cfg_rt! {
174174
}
175175
}
176176

177-
pub(crate) fn num_active_tasks(&self) -> usize {
178-
match_flavor!(self, Handle(handle) => handle.num_active_tasks())
177+
pub(crate) fn num_alive_tasks(&self) -> usize {
178+
match_flavor!(self, Handle(handle) => handle.alive_tasks_count())
179179
}
180180
}
181181

tokio/src/runtime/scheduler/multi_thread/handle/metrics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ impl Handle {
99
self.shared.worker_metrics.len()
1010
}
1111

12-
pub(crate) fn num_active_tasks(&self) -> usize {
13-
self.shared.owned.num_active_tasks()
12+
pub(crate) fn alive_tasks_count(&self) -> usize {
13+
self.shared.owned.alive_tasks_count()
1414
}
1515

1616
cfg_unstable_metrics! {

tokio/tests/rt_metrics.rs

-67
Original file line numberDiff line numberDiff line change
@@ -13,73 +13,6 @@ fn num_workers() {
1313
assert_eq!(2, rt.metrics().num_workers());
1414
}
1515

16-
#[test]
17-
fn num_blocking_threads() {
18-
let rt = current_thread();
19-
assert_eq!(0, rt.metrics().num_blocking_threads());
20-
let _ = rt.block_on(rt.spawn_blocking(move || {}));
21-
assert_eq!(1, rt.metrics().num_blocking_threads());
22-
23-
let rt = threaded();
24-
assert_eq!(0, rt.metrics().num_blocking_threads());
25-
let _ = rt.block_on(rt.spawn_blocking(move || {}));
26-
assert_eq!(1, rt.metrics().num_blocking_threads());
27-
}
28-
29-
#[test]
30-
fn num_idle_blocking_threads() {
31-
let rt = current_thread();
32-
assert_eq!(0, rt.metrics().num_idle_blocking_threads());
33-
let _ = rt.block_on(rt.spawn_blocking(move || {}));
34-
rt.block_on(async {
35-
time::sleep(Duration::from_millis(5)).await;
36-
});
37-
38-
// We need to wait until the blocking thread has become idle. Usually 5ms is
39-
// enough for this to happen, but not always. When it isn't enough, sleep
40-
// for another second. We don't always wait for a whole second since we want
41-
// the test suite to finish quickly.
42-
//
43-
// Note that the timeout for idle threads to be killed is 10 seconds.
44-
if 0 == rt.metrics().num_idle_blocking_threads() {
45-
rt.block_on(async {
46-
time::sleep(Duration::from_secs(1)).await;
47-
});
48-
}
49-
50-
assert_eq!(1, rt.metrics().num_idle_blocking_threads());
51-
}
52-
53-
#[test]
54-
fn blocking_queue_depth() {
55-
let rt = tokio::runtime::Builder::new_current_thread()
56-
.enable_all()
57-
.max_blocking_threads(1)
58-
.build()
59-
.unwrap();
60-
61-
assert_eq!(0, rt.metrics().blocking_queue_depth());
62-
63-
let ready = Arc::new(Mutex::new(()));
64-
let guard = ready.lock().unwrap();
65-
66-
let ready_cloned = ready.clone();
67-
let wait_until_ready = move || {
68-
let _unused = ready_cloned.lock().unwrap();
69-
};
70-
71-
let h1 = rt.spawn_blocking(wait_until_ready.clone());
72-
let h2 = rt.spawn_blocking(wait_until_ready);
73-
assert!(rt.metrics().blocking_queue_depth() > 0);
74-
75-
drop(guard);
76-
77-
let _ = rt.block_on(h1);
78-
let _ = rt.block_on(h2);
79-
80-
assert_eq!(0, rt.metrics().blocking_queue_depth());
81-
}
82-
8316
#[test]
8417
fn num_alive_tasks() {
8518
let rt = current_thread();

0 commit comments

Comments
 (0)