From 2b204402c5185d6cfcb8fa9ca7cff8051c3a76ef Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Thu, 31 Mar 2022 12:09:20 -0700 Subject: [PATCH 1/5] feat(console): surface dropped events if there are any During normal operation it won't show anything: ``` connection: http://127.0.0.1:6669/ (CONNECTED) ``` But if there are any drops detected, it will show a cumulative amount: ``` connection: http://127.0.0.1:6669/ (CONNECTED) dropped events: 2507 ``` --- tokio-console/src/main.rs | 9 +++++++++ tokio-console/src/state/async_ops.rs | 7 +++++++ tokio-console/src/state/mod.rs | 4 ++++ tokio-console/src/state/resources.rs | 7 +++++++ tokio-console/src/state/tasks.rs | 7 +++++++ 5 files changed, 34 insertions(+) diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index e41241d7c..f0594a972 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -127,6 +127,15 @@ async fn main() -> color_eyre::Result<()> { .0 .push(Span::styled(" PAUSED", view.styles.fg(Color::Red))); } + let dropped_updates = state.async_ops_state().dropped_events() + + state.tasks_state().dropped_events() + + state.resources_state().dropped_events(); + if dropped_updates > 0 { + header_text.0.push(Span::styled( + format!(" dropped updates: {}", dropped_updates), + view.styles.fg(Color::Red), + )); + } let header = Paragraph::new(header_text).wrap(Wrap { trim: true }); let view_controls = Paragraph::new(Spans::from(vec![ Span::raw("views: "), diff --git a/tokio-console/src/state/async_ops.rs b/tokio-console/src/state/async_ops.rs index 58662ef22..0c12d44d7 100644 --- a/tokio-console/src/state/async_ops.rs +++ b/tokio-console/src/state/async_ops.rs @@ -18,6 +18,7 @@ pub(crate) struct AsyncOpsState { async_ops: HashMap>>, ids: Ids, new_async_ops: Vec, + dropped_events: u64, } #[derive(Debug, Copy, Clone)] @@ -201,6 +202,8 @@ impl AsyncOpsState { } } } + + self.dropped_events += update.dropped_events; } pub(crate) fn retain_active(&mut self, now: SystemTime, retain_for: Duration) { @@ -217,6 +220,10 @@ impl AsyncOpsState { .unwrap_or(true) }) } + + pub(crate) fn dropped_events(&self) -> u64 { + self.dropped_events + } } impl AsyncOp { diff --git a/tokio-console/src/state/mod.rs b/tokio-console/src/state/mod.rs index 9c50cf6ab..c8f650994 100644 --- a/tokio-console/src/state/mod.rs +++ b/tokio-console/src/state/mod.rs @@ -200,6 +200,10 @@ impl State { &mut self.tasks_state } + pub(crate) fn resources_state(&mut self) -> &ResourcesState { + &self.resources_state + } + pub(crate) fn resources_state_mut(&mut self) -> &mut ResourcesState { &mut self.resources_state } diff --git a/tokio-console/src/state/resources.rs b/tokio-console/src/state/resources.rs index a654fd3ef..fea0c2f59 100644 --- a/tokio-console/src/state/resources.rs +++ b/tokio-console/src/state/resources.rs @@ -16,6 +16,7 @@ pub(crate) struct ResourcesState { resources: HashMap>>, pub(crate) ids: Ids, new_resources: Vec, + dropped_events: u64, } #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] @@ -206,6 +207,8 @@ impl ResourcesState { TypeVisibility::Public }; + self.dropped_events += update.dropped_events; + let resource = Resource { num, span_id, @@ -252,6 +255,10 @@ impl ResourcesState { .unwrap_or(true) }) } + + pub(crate) fn dropped_events(&self) -> u64 { + self.dropped_events + } } impl Resource { diff --git a/tokio-console/src/state/tasks.rs b/tokio-console/src/state/tasks.rs index 1fc16de95..78d19573b 100644 --- a/tokio-console/src/state/tasks.rs +++ b/tokio-console/src/state/tasks.rs @@ -22,6 +22,7 @@ pub(crate) struct TasksState { pub(crate) ids: Ids, new_tasks: Vec, pub(crate) linters: Vec>, + dropped_events: u64, } #[derive(Debug, Default)] @@ -197,6 +198,8 @@ impl TasksState { task.lint(linters); } } + + self.dropped_events += update.dropped_events; } pub(crate) fn retain_active(&mut self, now: SystemTime, retain_for: Duration) { @@ -220,6 +223,10 @@ impl TasksState { pub(crate) fn task(&self, id: u64) -> Option { self.tasks.get(&id).map(Rc::downgrade) } + + pub(crate) fn dropped_events(&self) -> u64 { + self.dropped_events + } } impl Details { From 4009539f6af178381c5508ac1d3aabd533356df0 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Tue, 12 Apr 2022 14:23:23 -0700 Subject: [PATCH 2/5] feat(console): split dropped events by category Before: ``` connection: http://127.0.0.1:6669/ (CONNECTED) dropped events: 2507 ``` After: ``` connection: http://127.0.0.1:6669/ (CONNECTED) dropped async_ops_state: 29172 dropped tasks_state: 72328 dropped resources_state: 240995304 ``` --- tokio-console/src/main.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index f0594a972..ebf618146 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -127,12 +127,24 @@ async fn main() -> color_eyre::Result<()> { .0 .push(Span::styled(" PAUSED", view.styles.fg(Color::Red))); } - let dropped_updates = state.async_ops_state().dropped_events() - + state.tasks_state().dropped_events() - + state.resources_state().dropped_events(); - if dropped_updates > 0 { + let dropped_async_ops_state = state.async_ops_state().dropped_events(); + if dropped_async_ops_state > 0 { header_text.0.push(Span::styled( - format!(" dropped updates: {}", dropped_updates), + format!(" dropped async_ops_state: {}", dropped_async_ops_state), + view.styles.fg(Color::Red), + )); + } + let dropped_tasks_state = state.tasks_state().dropped_events(); + if dropped_tasks_state > 0 { + header_text.0.push(Span::styled( + format!(" dropped tasks_state: {}", dropped_tasks_state), + view.styles.fg(Color::Red), + )); + } + let dropped_resources_state = state.resources_state().dropped_events(); + if dropped_resources_state > 0 { + header_text.0.push(Span::styled( + format!(" dropped resources_state: {}", dropped_resources_state), view.styles.fg(Color::Red), )); } From c4674a8082dd0c52824dde7f1ec7445702419c0f Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Tue, 12 Apr 2022 14:27:39 -0700 Subject: [PATCH 3/5] fix(console): do not overcount dropped resources_states updates The numbers are much more reasonable this way. Before: ``` connection: http://127.0.0.1:6669/ (CONNECTED) dropped async_ops_state: 29172 dropped tasks_state: 72328 dropped resources_state: 240995304 ``` After: ``` connection: http://127.0.0.1:6669/ (CONNECTED) dropped async_ops_state: 76 dropped tasks_state: 3388 dropped resources_state: 28956 ``` --- tokio-console/src/state/resources.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio-console/src/state/resources.rs b/tokio-console/src/state/resources.rs index fea0c2f59..7c40a352d 100644 --- a/tokio-console/src/state/resources.rs +++ b/tokio-console/src/state/resources.rs @@ -207,8 +207,6 @@ impl ResourcesState { TypeVisibility::Public }; - self.dropped_events += update.dropped_events; - let resource = Resource { num, span_id, @@ -228,6 +226,8 @@ impl ResourcesState { Some((num, resource)) }); + self.dropped_events += update.dropped_events; + self.resources.extend(new_resources); for (span_id, stats) in stats_update { From f0b30d945d6903eb67cef5d7ea99fc8653c223af Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Tue, 12 Apr 2022 14:59:24 -0700 Subject: [PATCH 4/5] fix(console): use better names for dropped counters Co-authored-by: Eliza Weisman --- tokio-console/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index ebf618146..3714fcddb 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -130,21 +130,21 @@ async fn main() -> color_eyre::Result<()> { let dropped_async_ops_state = state.async_ops_state().dropped_events(); if dropped_async_ops_state > 0 { header_text.0.push(Span::styled( - format!(" dropped async_ops_state: {}", dropped_async_ops_state), + format!(" dropped async ops: {}", dropped_async_ops_state), view.styles.fg(Color::Red), )); } let dropped_tasks_state = state.tasks_state().dropped_events(); if dropped_tasks_state > 0 { header_text.0.push(Span::styled( - format!(" dropped tasks_state: {}", dropped_tasks_state), + format!(" dropped tasks: {}", dropped_tasks_state), view.styles.fg(Color::Red), )); } let dropped_resources_state = state.resources_state().dropped_events(); if dropped_resources_state > 0 { header_text.0.push(Span::styled( - format!(" dropped resources_state: {}", dropped_resources_state), + format!(" dropped resources: {}", dropped_resources_state), view.styles.fg(Color::Red), )); } From df15b7228e6d423940d95d55888d838e05a3cec6 Mon Sep 17 00:00:00 2001 From: Ivan Babrou Date: Tue, 12 Apr 2022 15:06:42 -0700 Subject: [PATCH 5/5] fix(console): use more compact dropped counters Before: ``` connection: http://127.0.0.1:6669/ (CONNECTED) dropped async_ops_state: 76 dropped tasks_state: 3388 dropped resources_state: 28956 ``` After: ``` connection: http://127.0.0.1:6669/ (CONNECTED) dropped: 48 async_ops, 2073 tasks, 17852 resources ``` --- tokio-console/src/main.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index 3714fcddb..962750097 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -128,23 +128,21 @@ async fn main() -> color_eyre::Result<()> { .push(Span::styled(" PAUSED", view.styles.fg(Color::Red))); } let dropped_async_ops_state = state.async_ops_state().dropped_events(); - if dropped_async_ops_state > 0 { - header_text.0.push(Span::styled( - format!(" dropped async ops: {}", dropped_async_ops_state), - view.styles.fg(Color::Red), - )); - } let dropped_tasks_state = state.tasks_state().dropped_events(); - if dropped_tasks_state > 0 { - header_text.0.push(Span::styled( - format!(" dropped tasks: {}", dropped_tasks_state), - view.styles.fg(Color::Red), - )); - } let dropped_resources_state = state.resources_state().dropped_events(); - if dropped_resources_state > 0 { + if (dropped_async_ops_state + dropped_tasks_state + dropped_resources_state) > 0 { + let mut dropped_texts = vec![]; + if dropped_async_ops_state > 0 { + dropped_texts.push(format!("{} async_ops", dropped_async_ops_state)) + } + if dropped_tasks_state > 0 { + dropped_texts.push(format!("{} tasks", dropped_tasks_state)) + } + if dropped_resources_state > 0 { + dropped_texts.push(format!("{} resources", dropped_resources_state)) + } header_text.0.push(Span::styled( - format!(" dropped resources: {}", dropped_resources_state), + format!(" dropped: {}", dropped_texts.join(", ")), view.styles.fg(Color::Red), )); }