From 773d1f3e4d37a58f525dea8a3016bbfc6110cae6 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sat, 25 Nov 2023 18:46:36 +0800 Subject: [PATCH 01/11] feat: add args and configurations for linters Signed-off-by: hi-rustin --- tokio-console/console.example.toml | 5 +++ tokio-console/src/config.rs | 50 ++++++++++++++++++++++++++++++ tokio-console/src/main.rs | 8 +---- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/tokio-console/console.example.toml b/tokio-console/console.example.toml index f899e878e..8a482d8f6 100644 --- a/tokio-console/console.example.toml +++ b/tokio-console/console.example.toml @@ -1,5 +1,10 @@ default_target_addr = 'http://127.0.0.1:6669/' log = 'off' +linters = [ + 'SelfWakePercent', + 'LostWaker', + 'NeverYielded', +] log_directory = '/tmp/tokio-console/logs' retention = '6s' diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 7e2fd2f6e..9d4f27837 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -1,4 +1,6 @@ +use crate::state::tasks::Task; use crate::view::Palette; +use crate::warnings; use clap::builder::{PossibleValuesParser, TypedValueParser}; use clap::{ArgAction, ArgGroup, CommandFactory, Parser as Clap, Subcommand, ValueHint}; use clap_complete::Shell; @@ -48,6 +50,20 @@ pub struct Config { #[clap(long = "log", env = "RUST_LOG")] log_filter: Option, + /// Enable or disable specific linters. + /// + /// This is a comma-separated list of linters to enable or disable. + /// + /// Each linter is specified by its name, which is one of: + /// * `self-wake-percent` -- Warns when a task wakes itself more than a + /// certain percentage of its total wakeups. + /// * `lost-waker` -- Warns when a task is dropped without being woken. + /// * `never-yielded` -- Warns when a task has never yielded. + /// + /// [default: self-wake-percent, lost-waker, never-yielded] + #[clap(long = "linters")] + pub(crate) linters: Vec, + /// Path to a directory to write the console's internal logs to. /// /// [default: /tmp/tokio-console/logs] @@ -98,6 +114,26 @@ pub struct Config { pub subcmd: Option, } +/// Known warnings that can be enabled or disabled. +#[derive(clap::ValueEnum, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] +pub(crate) enum KnownWarnings { + SelfWakePercent, + LostWaker, + NeverYielded, +} + +impl From<&KnownWarnings> for warnings::Linter { + fn from(warning: &KnownWarnings) -> Self { + match warning { + KnownWarnings::SelfWakePercent => { + warnings::Linter::new(warnings::SelfWakePercent::default()) + } + KnownWarnings::LostWaker => warnings::Linter::new(warnings::LostWaker), + KnownWarnings::NeverYielded => warnings::Linter::new(warnings::NeverYielded::default()), + } + } +} + #[derive(Debug, Subcommand, PartialEq, Eq)] pub enum OptionalCmd { /// Generate a `console.toml` config file with the default configuration @@ -240,6 +276,7 @@ impl FromStr for LogFilter { struct ConfigFile { default_target_addr: Option, log: Option, + linters: Vec, log_directory: Option, retention: Option, charset: Option, @@ -428,6 +465,12 @@ impl Config { log_directory: other.log_directory.or(self.log_directory), target_addr: other.target_addr.or(self.target_addr), log_filter: other.log_filter.or(self.log_filter), + linters: { + let mut linters = other.linters; + linters.extend(self.linters); + linters.dedup(); + linters + }, retain_for: other.retain_for.or(self.retain_for), view_options: self.view_options.merge_with(other.view_options), subcmd: other.subcmd.or(self.subcmd), @@ -442,6 +485,11 @@ impl Default for Config { log_filter: Some(LogFilter( filter::Targets::new().with_default(filter::LevelFilter::OFF), )), + linters: vec![ + KnownWarnings::SelfWakePercent, + KnownWarnings::LostWaker, + KnownWarnings::NeverYielded, + ], log_directory: Some(default_log_directory()), retain_for: Some(RetainFor::default()), view_options: ViewOptions::default(), @@ -677,6 +725,7 @@ impl From for ConfigFile { default_target_addr: config.target_addr.map(|addr| addr.to_string()), log: config.log_filter.map(|filter| filter.to_string()), log_directory: config.log_directory, + linters: config.linters, retention: config.retain_for, charset: Some(CharsetConfig { lang: config.view_options.lang, @@ -699,6 +748,7 @@ impl TryFrom for Config { Ok(Config { target_addr: value.target_addr()?, log_filter: value.log_filter()?, + linters: value.linters.clone(), log_directory: value.log_directory.take(), retain_for: value.retain_for(), view_options: ViewOptions { diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index 9f2fc6aa3..445efdb2f 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -66,13 +66,7 @@ async fn main() -> color_eyre::Result<()> { let (details_tx, mut details_rx) = mpsc::channel::(2); let mut state = State::default() - // TODO(eliza): allow configuring the list of linters via the - // CLI/possibly a config file? - .with_task_linters(vec![ - warnings::Linter::new(warnings::SelfWakePercent::default()), - warnings::Linter::new(warnings::LostWaker), - warnings::Linter::new(warnings::NeverYielded::default()), - ]) + .with_task_linters(args.linters.iter().map(|lint| lint.into())) .with_retain_for(retain_for); let mut input = Box::pin(input::EventStream::new().try_filter(|event| { future::ready(!matches!( From d20ebbd9d92bbc0e9085119d0a57dc9b21345804 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Sat, 25 Nov 2023 18:56:44 +0800 Subject: [PATCH 02/11] test: fix broken cases Signed-off-by: hi-rustin --- README.md | 21 +++++++++++++++++++++ tokio-console/src/config.rs | 6 ++++-- tokio-console/tests/cli-ui.stdout | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 809038005..3f1a7b2f1 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,27 @@ Options: [env: RUST_LOG=] + --linters + Enable or disable specific linters. + + This is a comma-separated list of linters to enable or + disable. + + Each linter is specified by its name, which is one of: + + * `self-wake-percent` -- Warns when a task wakes itself more + than a certain percentage of its total wakeups. + + * `lost-waker` -- Warns when a task is dropped without being + woken. + + * `never-yielded` -- Warns when a task has never yielded. + + [default: self-wake-percent, lost-waker, never-yielded] + + [possible values: self-wake-percent, lost-waker, + never-yielded] + --log-dir Path to a directory to write the console's internal logs to. diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 9d4f27837..6ddf2c6fc 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -55,9 +55,11 @@ pub struct Config { /// This is a comma-separated list of linters to enable or disable. /// /// Each linter is specified by its name, which is one of: - /// * `self-wake-percent` -- Warns when a task wakes itself more than a - /// certain percentage of its total wakeups. + /// + /// * `self-wake-percent` -- Warns when a task wakes itself more than a certain percentage of its total wakeups. + /// /// * `lost-waker` -- Warns when a task is dropped without being woken. + /// /// * `never-yielded` -- Warns when a task has never yielded. /// /// [default: self-wake-percent, lost-waker, never-yielded] diff --git a/tokio-console/tests/cli-ui.stdout b/tokio-console/tests/cli-ui.stdout index 237a12641..856a95d8f 100644 --- a/tokio-console/tests/cli-ui.stdout +++ b/tokio-console/tests/cli-ui.stdout @@ -39,6 +39,27 @@ Options: [env: RUST_LOG=] + --linters + Enable or disable specific linters. + + This is a comma-separated list of linters to enable or + disable. + + Each linter is specified by its name, which is one of: + + * `self-wake-percent` -- Warns when a task wakes itself more + than a certain percentage of its total wakeups. + + * `lost-waker` -- Warns when a task is dropped without being + woken. + + * `never-yielded` -- Warns when a task has never yielded. + + [default: self-wake-percent, lost-waker, never-yielded] + + [possible values: self-wake-percent, lost-waker, + never-yielded] + --log-dir Path to a directory to write the console's internal logs to. From 06c08dc5baa29c571988e06443fcfafd2e67ffec Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 29 Nov 2023 21:23:12 +0800 Subject: [PATCH 03/11] fix: add default values Signed-off-by: hi-rustin --- README.md | 3 +-- tokio-console/console.example.toml | 6 +++--- tokio-console/src/config.rs | 20 ++++++++++++++++++-- tokio-console/tests/cli-ui.stdout | 3 +-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3f1a7b2f1..b2727b1a5 100644 --- a/README.md +++ b/README.md @@ -226,8 +226,7 @@ Options: * `never-yielded` -- Warns when a task has never yielded. - [default: self-wake-percent, lost-waker, never-yielded] - + [default: self-wake-percent lost-waker never-yielded] [possible values: self-wake-percent, lost-waker, never-yielded] diff --git a/tokio-console/console.example.toml b/tokio-console/console.example.toml index 8a482d8f6..f8b646231 100644 --- a/tokio-console/console.example.toml +++ b/tokio-console/console.example.toml @@ -1,9 +1,9 @@ default_target_addr = 'http://127.0.0.1:6669/' log = 'off' linters = [ - 'SelfWakePercent', - 'LostWaker', - 'NeverYielded', + 'self-wake-percent', + 'lost-waker', + 'never-yielded', ] log_directory = '/tmp/tokio-console/logs' retention = '6s' diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 6ddf2c6fc..a895642a1 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -62,8 +62,12 @@ pub struct Config { /// /// * `never-yielded` -- Warns when a task has never yielded. /// - /// [default: self-wake-percent, lost-waker, never-yielded] #[clap(long = "linters")] + #[clap(default_values_t = vec![ + KnownWarnings::SelfWakePercent, + KnownWarnings::LostWaker, + KnownWarnings::NeverYielded + ])] pub(crate) linters: Vec, /// Path to a directory to write the console's internal logs to. @@ -117,7 +121,8 @@ pub struct Config { } /// Known warnings that can be enabled or disabled. -#[derive(clap::ValueEnum, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] +#[derive(clap::ValueEnum, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] +#[serde(rename_all = "kebab-case")] pub(crate) enum KnownWarnings { SelfWakePercent, LostWaker, @@ -136,6 +141,16 @@ impl From<&KnownWarnings> for warnings::Linter { } } +impl fmt::Display for KnownWarnings { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + KnownWarnings::SelfWakePercent => write!(f, "self-wake-percent"), + KnownWarnings::LostWaker => write!(f, "lost-waker"), + KnownWarnings::NeverYielded => write!(f, "never-yielded"), + } + } +} + #[derive(Debug, Subcommand, PartialEq, Eq)] pub enum OptionalCmd { /// Generate a `console.toml` config file with the default configuration @@ -470,6 +485,7 @@ impl Config { linters: { let mut linters = other.linters; linters.extend(self.linters); + linters.sort_unstable(); linters.dedup(); linters }, diff --git a/tokio-console/tests/cli-ui.stdout b/tokio-console/tests/cli-ui.stdout index 856a95d8f..3782a2914 100644 --- a/tokio-console/tests/cli-ui.stdout +++ b/tokio-console/tests/cli-ui.stdout @@ -55,8 +55,7 @@ Options: * `never-yielded` -- Warns when a task has never yielded. - [default: self-wake-percent, lost-waker, never-yielded] - + [default: self-wake-percent lost-waker never-yielded] [possible values: self-wake-percent, lost-waker, never-yielded] From c0fcd18e9df833140c5e915c0429c74ee7020fbd Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 29 Nov 2023 21:30:02 +0800 Subject: [PATCH 04/11] feat: use delimiter Signed-off-by: hi-rustin --- README.md | 2 +- tokio-console/src/config.rs | 2 +- tokio-console/tests/cli-ui.stdout | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b2727b1a5..12abe1604 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ Options: [env: RUST_LOG=] - --linters + --linters ... Enable or disable specific linters. This is a comma-separated list of linters to enable or diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index a895642a1..577ecc154 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -62,7 +62,7 @@ pub struct Config { /// /// * `never-yielded` -- Warns when a task has never yielded. /// - #[clap(long = "linters")] + #[clap(long = "linters", value_delimiter = ',', num_args = 1..)] #[clap(default_values_t = vec![ KnownWarnings::SelfWakePercent, KnownWarnings::LostWaker, diff --git a/tokio-console/tests/cli-ui.stdout b/tokio-console/tests/cli-ui.stdout index 3782a2914..806e7b66a 100644 --- a/tokio-console/tests/cli-ui.stdout +++ b/tokio-console/tests/cli-ui.stdout @@ -39,7 +39,7 @@ Options: [env: RUST_LOG=] - --linters + --linters ... Enable or disable specific linters. This is a comma-separated list of linters to enable or From 4375b6b9cae8bacaf66378ba46c4812cc71d72be Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 29 Nov 2023 21:41:43 +0800 Subject: [PATCH 05/11] refactor: rename to SelfWakes Signed-off-by: hi-rustin --- README.md | 9 ++++----- tokio-console/console.example.toml | 2 +- tokio-console/src/config.rs | 14 ++++++-------- tokio-console/tests/cli-ui.stdout | 9 ++++----- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 12abe1604..9c0d399f6 100644 --- a/README.md +++ b/README.md @@ -218,17 +218,16 @@ Options: Each linter is specified by its name, which is one of: - * `self-wake-percent` -- Warns when a task wakes itself more - than a certain percentage of its total wakeups. + * `self-wakes` -- Warns when a task wakes itself more than a + certain percentage of its total wakeups. * `lost-waker` -- Warns when a task is dropped without being woken. * `never-yielded` -- Warns when a task has never yielded. - [default: self-wake-percent lost-waker never-yielded] - [possible values: self-wake-percent, lost-waker, - never-yielded] + [default: self-wakes lost-waker never-yielded] + [possible values: self-wakes, lost-waker, never-yielded] --log-dir Path to a directory to write the console's internal logs to. diff --git a/tokio-console/console.example.toml b/tokio-console/console.example.toml index f8b646231..39ebf05f4 100644 --- a/tokio-console/console.example.toml +++ b/tokio-console/console.example.toml @@ -1,7 +1,7 @@ default_target_addr = 'http://127.0.0.1:6669/' log = 'off' linters = [ - 'self-wake-percent', + 'self-wakes', 'lost-waker', 'never-yielded', ] diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 577ecc154..3f6c16b94 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -56,7 +56,7 @@ pub struct Config { /// /// Each linter is specified by its name, which is one of: /// - /// * `self-wake-percent` -- Warns when a task wakes itself more than a certain percentage of its total wakeups. + /// * `self-wakes` -- Warns when a task wakes itself more than a certain percentage of its total wakeups. /// /// * `lost-waker` -- Warns when a task is dropped without being woken. /// @@ -64,7 +64,7 @@ pub struct Config { /// #[clap(long = "linters", value_delimiter = ',', num_args = 1..)] #[clap(default_values_t = vec![ - KnownWarnings::SelfWakePercent, + KnownWarnings::SelfWakes, KnownWarnings::LostWaker, KnownWarnings::NeverYielded ])] @@ -124,7 +124,7 @@ pub struct Config { #[derive(clap::ValueEnum, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] #[serde(rename_all = "kebab-case")] pub(crate) enum KnownWarnings { - SelfWakePercent, + SelfWakes, LostWaker, NeverYielded, } @@ -132,9 +132,7 @@ pub(crate) enum KnownWarnings { impl From<&KnownWarnings> for warnings::Linter { fn from(warning: &KnownWarnings) -> Self { match warning { - KnownWarnings::SelfWakePercent => { - warnings::Linter::new(warnings::SelfWakePercent::default()) - } + KnownWarnings::SelfWakes => warnings::Linter::new(warnings::SelfWakePercent::default()), KnownWarnings::LostWaker => warnings::Linter::new(warnings::LostWaker), KnownWarnings::NeverYielded => warnings::Linter::new(warnings::NeverYielded::default()), } @@ -144,7 +142,7 @@ impl From<&KnownWarnings> for warnings::Linter { impl fmt::Display for KnownWarnings { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - KnownWarnings::SelfWakePercent => write!(f, "self-wake-percent"), + KnownWarnings::SelfWakes => write!(f, "self-wakes"), KnownWarnings::LostWaker => write!(f, "lost-waker"), KnownWarnings::NeverYielded => write!(f, "never-yielded"), } @@ -504,7 +502,7 @@ impl Default for Config { filter::Targets::new().with_default(filter::LevelFilter::OFF), )), linters: vec![ - KnownWarnings::SelfWakePercent, + KnownWarnings::SelfWakes, KnownWarnings::LostWaker, KnownWarnings::NeverYielded, ], diff --git a/tokio-console/tests/cli-ui.stdout b/tokio-console/tests/cli-ui.stdout index 806e7b66a..29835982f 100644 --- a/tokio-console/tests/cli-ui.stdout +++ b/tokio-console/tests/cli-ui.stdout @@ -47,17 +47,16 @@ Options: Each linter is specified by its name, which is one of: - * `self-wake-percent` -- Warns when a task wakes itself more - than a certain percentage of its total wakeups. + * `self-wakes` -- Warns when a task wakes itself more than a + certain percentage of its total wakeups. * `lost-waker` -- Warns when a task is dropped without being woken. * `never-yielded` -- Warns when a task has never yielded. - [default: self-wake-percent lost-waker never-yielded] - [possible values: self-wake-percent, lost-waker, - never-yielded] + [default: self-wakes lost-waker never-yielded] + [possible values: self-wakes, lost-waker, never-yielded] --log-dir Path to a directory to write the console's internal logs to. From a9723d4d893373e58b8c91aa3fb63f418a9b0280 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 29 Nov 2023 22:08:07 +0800 Subject: [PATCH 06/11] refactor: rename to `warn` Signed-off-by: hi-rustin --- README.md | 9 ++++----- tokio-console/console.example.toml | 2 +- tokio-console/src/config.rs | 30 +++++++++++++++--------------- tokio-console/src/main.rs | 2 +- tokio-console/tests/cli-ui.stdout | 9 ++++----- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 9c0d399f6..a23dcdf52 100644 --- a/README.md +++ b/README.md @@ -210,13 +210,12 @@ Options: [env: RUST_LOG=] - --linters ... - Enable or disable specific linters. + -W, --warn ... + Enable lint warnings. - This is a comma-separated list of linters to enable or - disable. + This is a comma-separated list of warnings to enable. - Each linter is specified by its name, which is one of: + Each warning is specified by its name, which is one of: * `self-wakes` -- Warns when a task wakes itself more than a certain percentage of its total wakeups. diff --git a/tokio-console/console.example.toml b/tokio-console/console.example.toml index 39ebf05f4..eaff48de3 100644 --- a/tokio-console/console.example.toml +++ b/tokio-console/console.example.toml @@ -1,6 +1,6 @@ default_target_addr = 'http://127.0.0.1:6669/' log = 'off' -linters = [ +warns = [ 'self-wakes', 'lost-waker', 'never-yielded', diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 3f6c16b94..136af5254 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -50,11 +50,11 @@ pub struct Config { #[clap(long = "log", env = "RUST_LOG")] log_filter: Option, - /// Enable or disable specific linters. + /// Enable lint warnings. /// - /// This is a comma-separated list of linters to enable or disable. + /// This is a comma-separated list of warnings to enable. /// - /// Each linter is specified by its name, which is one of: + /// Each warning is specified by its name, which is one of: /// /// * `self-wakes` -- Warns when a task wakes itself more than a certain percentage of its total wakeups. /// @@ -62,13 +62,13 @@ pub struct Config { /// /// * `never-yielded` -- Warns when a task has never yielded. /// - #[clap(long = "linters", value_delimiter = ',', num_args = 1..)] + #[clap(long = "warn", short = 'W', value_delimiter = ',', num_args = 1..)] #[clap(default_values_t = vec![ KnownWarnings::SelfWakes, KnownWarnings::LostWaker, KnownWarnings::NeverYielded ])] - pub(crate) linters: Vec, + pub(crate) warns: Vec, /// Path to a directory to write the console's internal logs to. /// @@ -291,7 +291,7 @@ impl FromStr for LogFilter { struct ConfigFile { default_target_addr: Option, log: Option, - linters: Vec, + warns: Vec, log_directory: Option, retention: Option, charset: Option, @@ -480,12 +480,12 @@ impl Config { log_directory: other.log_directory.or(self.log_directory), target_addr: other.target_addr.or(self.target_addr), log_filter: other.log_filter.or(self.log_filter), - linters: { - let mut linters = other.linters; - linters.extend(self.linters); - linters.sort_unstable(); - linters.dedup(); - linters + warns: { + let mut warns: Vec = other.warns; + warns.extend(self.warns); + warns.sort_unstable(); + warns.dedup(); + warns }, retain_for: other.retain_for.or(self.retain_for), view_options: self.view_options.merge_with(other.view_options), @@ -501,7 +501,7 @@ impl Default for Config { log_filter: Some(LogFilter( filter::Targets::new().with_default(filter::LevelFilter::OFF), )), - linters: vec![ + warns: vec![ KnownWarnings::SelfWakes, KnownWarnings::LostWaker, KnownWarnings::NeverYielded, @@ -741,7 +741,7 @@ impl From for ConfigFile { default_target_addr: config.target_addr.map(|addr| addr.to_string()), log: config.log_filter.map(|filter| filter.to_string()), log_directory: config.log_directory, - linters: config.linters, + warns: config.warns, retention: config.retain_for, charset: Some(CharsetConfig { lang: config.view_options.lang, @@ -764,7 +764,7 @@ impl TryFrom for Config { Ok(Config { target_addr: value.target_addr()?, log_filter: value.log_filter()?, - linters: value.linters.clone(), + warns: value.warns.clone(), log_directory: value.log_directory.take(), retain_for: value.retain_for(), view_options: ViewOptions { diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index 445efdb2f..916af2d54 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -66,7 +66,7 @@ async fn main() -> color_eyre::Result<()> { let (details_tx, mut details_rx) = mpsc::channel::(2); let mut state = State::default() - .with_task_linters(args.linters.iter().map(|lint| lint.into())) + .with_task_linters(args.warns.iter().map(|lint| lint.into())) .with_retain_for(retain_for); let mut input = Box::pin(input::EventStream::new().try_filter(|event| { future::ready(!matches!( diff --git a/tokio-console/tests/cli-ui.stdout b/tokio-console/tests/cli-ui.stdout index 29835982f..3bb0bf960 100644 --- a/tokio-console/tests/cli-ui.stdout +++ b/tokio-console/tests/cli-ui.stdout @@ -39,13 +39,12 @@ Options: [env: RUST_LOG=] - --linters ... - Enable or disable specific linters. + -W, --warn ... + Enable lint warnings. - This is a comma-separated list of linters to enable or - disable. + This is a comma-separated list of warnings to enable. - Each linter is specified by its name, which is one of: + Each warning is specified by its name, which is one of: * `self-wakes` -- Warns when a task wakes itself more than a certain percentage of its total wakeups. From ed610e63bc94667b1a642371da056bfe5b85ed52 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 30 Nov 2023 20:15:17 +0800 Subject: [PATCH 07/11] refactor: rename to warnings Signed-off-by: hi-rustin --- README.md | 2 +- tokio-console/console.example.toml | 2 +- tokio-console/src/config.rs | 16 ++++++++-------- tokio-console/src/main.rs | 2 +- tokio-console/tests/cli-ui.stdout | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a23dcdf52..5f170f777 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ Options: [env: RUST_LOG=] - -W, --warn ... + -W, --warn ... Enable lint warnings. This is a comma-separated list of warnings to enable. diff --git a/tokio-console/console.example.toml b/tokio-console/console.example.toml index eaff48de3..4b0db2b4e 100644 --- a/tokio-console/console.example.toml +++ b/tokio-console/console.example.toml @@ -1,6 +1,6 @@ default_target_addr = 'http://127.0.0.1:6669/' log = 'off' -warns = [ +warnings = [ 'self-wakes', 'lost-waker', 'never-yielded', diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 136af5254..1eb176cdb 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -68,7 +68,7 @@ pub struct Config { KnownWarnings::LostWaker, KnownWarnings::NeverYielded ])] - pub(crate) warns: Vec, + pub(crate) warnings: Vec, /// Path to a directory to write the console's internal logs to. /// @@ -291,7 +291,7 @@ impl FromStr for LogFilter { struct ConfigFile { default_target_addr: Option, log: Option, - warns: Vec, + warnings: Vec, log_directory: Option, retention: Option, charset: Option, @@ -480,9 +480,9 @@ impl Config { log_directory: other.log_directory.or(self.log_directory), target_addr: other.target_addr.or(self.target_addr), log_filter: other.log_filter.or(self.log_filter), - warns: { - let mut warns: Vec = other.warns; - warns.extend(self.warns); + warnings: { + let mut warns: Vec = other.warnings; + warns.extend(self.warnings); warns.sort_unstable(); warns.dedup(); warns @@ -501,7 +501,7 @@ impl Default for Config { log_filter: Some(LogFilter( filter::Targets::new().with_default(filter::LevelFilter::OFF), )), - warns: vec![ + warnings: vec![ KnownWarnings::SelfWakes, KnownWarnings::LostWaker, KnownWarnings::NeverYielded, @@ -741,7 +741,7 @@ impl From for ConfigFile { default_target_addr: config.target_addr.map(|addr| addr.to_string()), log: config.log_filter.map(|filter| filter.to_string()), log_directory: config.log_directory, - warns: config.warns, + warnings: config.warnings, retention: config.retain_for, charset: Some(CharsetConfig { lang: config.view_options.lang, @@ -764,7 +764,7 @@ impl TryFrom for Config { Ok(Config { target_addr: value.target_addr()?, log_filter: value.log_filter()?, - warns: value.warns.clone(), + warnings: value.warnings.clone(), log_directory: value.log_directory.take(), retain_for: value.retain_for(), view_options: ViewOptions { diff --git a/tokio-console/src/main.rs b/tokio-console/src/main.rs index 916af2d54..4f99ee71a 100644 --- a/tokio-console/src/main.rs +++ b/tokio-console/src/main.rs @@ -66,7 +66,7 @@ async fn main() -> color_eyre::Result<()> { let (details_tx, mut details_rx) = mpsc::channel::(2); let mut state = State::default() - .with_task_linters(args.warns.iter().map(|lint| lint.into())) + .with_task_linters(args.warnings.iter().map(|lint| lint.into())) .with_retain_for(retain_for); let mut input = Box::pin(input::EventStream::new().try_filter(|event| { future::ready(!matches!( diff --git a/tokio-console/tests/cli-ui.stdout b/tokio-console/tests/cli-ui.stdout index 3bb0bf960..cc8da63cf 100644 --- a/tokio-console/tests/cli-ui.stdout +++ b/tokio-console/tests/cli-ui.stdout @@ -39,7 +39,7 @@ Options: [env: RUST_LOG=] - -W, --warn ... + -W, --warn ... Enable lint warnings. This is a comma-separated list of warnings to enable. From 750c4f6a20f573ec812d21ea4612226612bfb502 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Thu, 30 Nov 2023 20:23:32 +0800 Subject: [PATCH 08/11] docs: add default percentage Signed-off-by: hi-rustin --- README.md | 3 ++- tokio-console/src/config.rs | 1 + tokio-console/tests/cli-ui.stdout | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f170f777..b5a4db4d8 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,8 @@ Options: Each warning is specified by its name, which is one of: * `self-wakes` -- Warns when a task wakes itself more than a - certain percentage of its total wakeups. + certain percentage of its total wakeups. Default percentage is + 50%. * `lost-waker` -- Warns when a task is dropped without being woken. diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 1eb176cdb..2cc40d4eb 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -57,6 +57,7 @@ pub struct Config { /// Each warning is specified by its name, which is one of: /// /// * `self-wakes` -- Warns when a task wakes itself more than a certain percentage of its total wakeups. + /// Default percentage is 50%. /// /// * `lost-waker` -- Warns when a task is dropped without being woken. /// diff --git a/tokio-console/tests/cli-ui.stdout b/tokio-console/tests/cli-ui.stdout index cc8da63cf..519a82dbd 100644 --- a/tokio-console/tests/cli-ui.stdout +++ b/tokio-console/tests/cli-ui.stdout @@ -47,7 +47,8 @@ Options: Each warning is specified by its name, which is one of: * `self-wakes` -- Warns when a task wakes itself more than a - certain percentage of its total wakeups. + certain percentage of its total wakeups. Default percentage is + 50%. * `lost-waker` -- Warns when a task is dropped without being woken. From e5c39e09eed9b22d940ead5e23091deea0a57210 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 16 Jan 2024 22:11:18 +0800 Subject: [PATCH 09/11] trigger test From a359250fd1e45999742d96ebfbca28af299a8295 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Wed, 17 Jan 2024 21:52:37 +0800 Subject: [PATCH 10/11] fix: bump trycmd version to fix the stuck issue Signed-off-by: hi-rustin --- Cargo.lock | 12 ++++++------ tokio-console/Cargo.toml | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46290ab97..9fc6acbc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1552,9 +1552,9 @@ checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "snapbox" -version = "0.2.10" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "767a1d5da232b6959cd1bd5c9e8db8a7cce09c3038e89deedb49a549a2aefd93" +checksum = "44d199ccf8f606592df2d145db26f2aa45344e23c64b074cc5a4047f1d99b0f7" dependencies = [ "concolor", "content_inspector", @@ -1572,9 +1572,9 @@ dependencies = [ [[package]] name = "snapbox-macros" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c01dea7e04cbb27ef4c86e9922184608185f7cd95c1763bc30d727cda4a5e930" +checksum = "8a253e6f894cfa440cba00600a249fa90869d8e0ec45ab274a456e043a0ce8f2" [[package]] name = "socket2" @@ -1981,9 +1981,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "trycmd" -version = "0.13.4" +version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb4185126cc904642173a54c185083f410c86d1202ada6761aacf7c40829f13" +checksum = "9ac9fa73959e252e7c5a4e6260544b952f5bf3989e0b7ad229f4fd6f14671b02" dependencies = [ "glob", "humantime", diff --git a/tokio-console/Cargo.toml b/tokio-console/Cargo.toml index 564aa46fc..68740071a 100644 --- a/tokio-console/Cargo.toml +++ b/tokio-console/Cargo.toml @@ -53,5 +53,5 @@ toml = "0.5" dirs = "5" [dev-dependencies] -# Use 1.64.0 compatible version of `trycmd@0.13.4`. -trycmd = "=0.13.4" +# Use 1.64.0 compatible version of `trycmd@0.13.6`. +trycmd = "=0.13.6" From 35eb5248577f1b73058fb2941c748a524ee6476b Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Fri, 19 Jan 2024 22:53:55 +0800 Subject: [PATCH 11/11] fix: add default_enabled_warnings Signed-off-by: hi-rustin --- tokio-console/src/config.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tokio-console/src/config.rs b/tokio-console/src/config.rs index 2cc40d4eb..c470a22e9 100644 --- a/tokio-console/src/config.rs +++ b/tokio-console/src/config.rs @@ -64,11 +64,7 @@ pub struct Config { /// * `never-yielded` -- Warns when a task has never yielded. /// #[clap(long = "warn", short = 'W', value_delimiter = ',', num_args = 1..)] - #[clap(default_values_t = vec![ - KnownWarnings::SelfWakes, - KnownWarnings::LostWaker, - KnownWarnings::NeverYielded - ])] + #[clap(default_values_t = KnownWarnings::default_enabled_warnings())] pub(crate) warnings: Vec, /// Path to a directory to write the console's internal logs to. @@ -150,6 +146,16 @@ impl fmt::Display for KnownWarnings { } } +impl KnownWarnings { + fn default_enabled_warnings() -> Vec { + vec![ + KnownWarnings::SelfWakes, + KnownWarnings::LostWaker, + KnownWarnings::NeverYielded, + ] + } +} + #[derive(Debug, Subcommand, PartialEq, Eq)] pub enum OptionalCmd { /// Generate a `console.toml` config file with the default configuration @@ -502,11 +508,7 @@ impl Default for Config { log_filter: Some(LogFilter( filter::Targets::new().with_default(filter::LevelFilter::OFF), )), - warnings: vec![ - KnownWarnings::SelfWakes, - KnownWarnings::LostWaker, - KnownWarnings::NeverYielded, - ], + warnings: KnownWarnings::default_enabled_warnings(), log_directory: Some(default_log_directory()), retain_for: Some(RetainFor::default()), view_options: ViewOptions::default(),