Skip to content

Commit 68d0e3c

Browse files
authored
metrics: rename num_active_tasks to num_alive_tasks (#6667)
1 parent 65d0e08 commit 68d0e3c

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

tokio/src/runtime/metrics/runtime.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,16 @@ impl RuntimeMetrics {
7575
self.handle.inner.num_blocking_threads()
7676
}
7777

78-
#[deprecated = "Renamed to num_active_tasks"]
79-
/// Renamed to [`RuntimeMetrics::num_active_tasks`]
78+
#[deprecated = "Renamed to num_alive_tasks"]
79+
/// Renamed to [`RuntimeMetrics::num_alive_tasks`]
8080
pub fn active_tasks_count(&self) -> usize {
81-
self.num_active_tasks()
81+
self.num_alive_tasks()
8282
}
8383

84-
/// Returns the current number of active tasks in the runtime.
84+
/// Returns the current number of alive tasks in the runtime.
8585
///
86-
/// This value increases and decreases over time as tasks are spawned and as they are completed or cancelled.
86+
/// This counter increases when a task is spawned and decreases when a
87+
/// task exits.
8788
///
8889
/// # Examples
8990
///
@@ -94,12 +95,12 @@ impl RuntimeMetrics {
9495
/// async fn main() {
9596
/// let metrics = Handle::current().metrics();
9697
///
97-
/// let n = metrics.num_active_tasks();
98-
/// println!("Runtime has {} active tasks", n);
98+
/// let n = metrics.num_alive_tasks();
99+
/// println!("Runtime has {} alive tasks", n);
99100
/// }
100101
/// ```
101-
pub fn num_active_tasks(&self) -> usize {
102-
self.handle.inner.active_tasks_count()
102+
pub fn num_alive_tasks(&self) -> usize {
103+
self.handle.inner.alive_tasks_count()
103104
}
104105

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,8 @@ cfg_unstable_metrics! {
533533
self.blocking_spawner.queue_depth()
534534
}
535535

536-
pub(crate) fn active_tasks_count(&self) -> usize {
537-
self.shared.owned.active_tasks_count()
536+
pub(crate) fn alive_tasks_count(&self) -> usize {
537+
self.shared.owned.alive_tasks_count()
538538
}
539539

540540
cfg_64bit_metrics! {

tokio/src/runtime/scheduler/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ cfg_rt! {
193193
match_flavor!(self, Handle(handle) => handle.num_idle_blocking_threads())
194194
}
195195

196-
pub(crate) fn active_tasks_count(&self) -> usize {
197-
match_flavor!(self, Handle(handle) => handle.active_tasks_count())
196+
pub(crate) fn alive_tasks_count(&self) -> usize {
197+
match_flavor!(self, Handle(handle) => handle.alive_tasks_count())
198198
}
199199

200200
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ impl Handle {
2727
self.blocking_spawner.num_idle_threads()
2828
}
2929

30-
pub(crate) fn active_tasks_count(&self) -> usize {
31-
self.shared.owned.active_tasks_count()
30+
pub(crate) fn alive_tasks_count(&self) -> usize {
31+
self.shared.owned.alive_tasks_count()
3232
}
3333

3434
pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ impl Handle {
1818
self.blocking_spawner.num_idle_threads()
1919
}
2020

21-
pub(crate) fn active_tasks_count(&self) -> usize {
22-
self.shared.owned.active_tasks_count()
21+
pub(crate) fn alive_tasks_count(&self) -> usize {
22+
self.shared.owned.alive_tasks_count()
2323
}
2424

2525
cfg_64bit_metrics! {

tokio/src/runtime/task/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<S: 'static> OwnedTasks<S> {
166166
self.list.shard_size()
167167
}
168168

169-
pub(crate) fn active_tasks_count(&self) -> usize {
169+
pub(crate) fn alive_tasks_count(&self) -> usize {
170170
self.list.len()
171171
}
172172

tokio/tests/rt_metrics.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,35 +93,35 @@ fn blocking_queue_depth() {
9393
}
9494

9595
#[test]
96-
fn num_active_tasks() {
96+
fn num_alive_tasks() {
9797
let rt = current_thread();
9898
let metrics = rt.metrics();
99-
assert_eq!(0, metrics.num_active_tasks());
99+
assert_eq!(0, metrics.num_alive_tasks());
100100
rt.block_on(rt.spawn(async move {
101-
assert_eq!(1, metrics.num_active_tasks());
101+
assert_eq!(1, metrics.num_alive_tasks());
102102
}))
103103
.unwrap();
104104

105-
assert_eq!(0, rt.metrics().num_active_tasks());
105+
assert_eq!(0, rt.metrics().num_alive_tasks());
106106

107107
let rt = threaded();
108108
let metrics = rt.metrics();
109-
assert_eq!(0, metrics.num_active_tasks());
109+
assert_eq!(0, metrics.num_alive_tasks());
110110
rt.block_on(rt.spawn(async move {
111-
assert_eq!(1, metrics.num_active_tasks());
111+
assert_eq!(1, metrics.num_alive_tasks());
112112
}))
113113
.unwrap();
114114

115115
// try for 10 seconds to see if this eventually succeeds.
116116
// wake_join() is called before the task is released, so in multithreaded
117117
// code, this means we sometimes exit the block_on before the counter decrements.
118118
for _ in 0..100 {
119-
if rt.metrics().num_active_tasks() == 0 {
119+
if rt.metrics().num_alive_tasks() == 0 {
120120
break;
121121
}
122122
std::thread::sleep(std::time::Duration::from_millis(100));
123123
}
124-
assert_eq!(0, rt.metrics().num_active_tasks());
124+
assert_eq!(0, rt.metrics().num_alive_tasks());
125125
}
126126

127127
#[test]

0 commit comments

Comments
 (0)