-
-
Notifications
You must be signed in to change notification settings - Fork 163
feat: add flags and configurations for warnings #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
773d1f3
d20ebbd
06c08dc
c0fcd18
4375b6b
a9723d4
ed610e6
750c4f6
e5c39e0
a359250
35eb524
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,5 +53,5 @@ toml = "0.5" | |
| dirs = "5" | ||
|
|
||
| [dev-dependencies] | ||
| # Use 1.64.0 compatible version of `[email protected].4`. | ||
| trycmd = "=0.13.4" | ||
| # Use 1.64.0 compatible version of `[email protected].6`. | ||
| trycmd = "=0.13.6" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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,27 @@ pub struct Config { | |
| #[clap(long = "log", env = "RUST_LOG")] | ||
| log_filter: Option<LogFilter>, | ||
|
|
||
| /// Enable lint warnings. | ||
| /// | ||
| /// This is a comma-separated list of warnings to enable. | ||
| /// | ||
| /// 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. | ||
| /// | ||
| /// * `never-yielded` -- Warns when a task has never yielded. | ||
| /// | ||
| #[clap(long = "warn", short = 'W', value_delimiter = ',', num_args = 1..)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if i understand correctly, the use of
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed on Discord, we will add the |
||
| #[clap(default_values_t = vec![ | ||
| KnownWarnings::SelfWakes, | ||
| KnownWarnings::LostWaker, | ||
| KnownWarnings::NeverYielded | ||
| ])] | ||
| pub(crate) warnings: Vec<KnownWarnings>, | ||
|
|
||
| /// Path to a directory to write the console's internal logs to. | ||
| /// | ||
| /// [default: /tmp/tokio-console/logs] | ||
|
|
@@ -98,6 +121,35 @@ pub struct Config { | |
| pub subcmd: Option<OptionalCmd>, | ||
| } | ||
|
|
||
| /// Known warnings that can be enabled or disabled. | ||
| #[derive(clap::ValueEnum, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord)] | ||
| #[serde(rename_all = "kebab-case")] | ||
| pub(crate) enum KnownWarnings { | ||
| SelfWakes, | ||
| LostWaker, | ||
| NeverYielded, | ||
| } | ||
|
|
||
| impl From<&KnownWarnings> for warnings::Linter<Task> { | ||
| fn from(warning: &KnownWarnings) -> Self { | ||
| match warning { | ||
| KnownWarnings::SelfWakes => warnings::Linter::new(warnings::SelfWakePercent::default()), | ||
| KnownWarnings::LostWaker => warnings::Linter::new(warnings::LostWaker), | ||
| KnownWarnings::NeverYielded => warnings::Linter::new(warnings::NeverYielded::default()), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for KnownWarnings { | ||
0xPoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| match self { | ||
| KnownWarnings::SelfWakes => write!(f, "self-wakes"), | ||
| 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 | ||
|
|
@@ -240,6 +292,7 @@ impl FromStr for LogFilter { | |
| struct ConfigFile { | ||
| default_target_addr: Option<String>, | ||
| log: Option<String>, | ||
| warnings: Vec<KnownWarnings>, | ||
| log_directory: Option<PathBuf>, | ||
| retention: Option<RetainFor>, | ||
| charset: Option<CharsetConfig>, | ||
|
|
@@ -428,6 +481,13 @@ 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), | ||
| warnings: { | ||
| let mut warns: Vec<KnownWarnings> = other.warnings; | ||
| warns.extend(self.warnings); | ||
| warns.sort_unstable(); | ||
| warns.dedup(); | ||
| warns | ||
|
Comment on lines
+491
to
+495
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potentially, we might want to store the list of known warnings as a On the other hand, I'm not sure whether that changes how it's deserialized from TOML...so, just a thought.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }, | ||
| 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 +502,11 @@ impl Default for Config { | |
| log_filter: Some(LogFilter( | ||
| filter::Targets::new().with_default(filter::LevelFilter::OFF), | ||
| )), | ||
| warnings: vec![ | ||
| KnownWarnings::SelfWakes, | ||
| KnownWarnings::LostWaker, | ||
| KnownWarnings::NeverYielded, | ||
| ], | ||
0xPoe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| log_directory: Some(default_log_directory()), | ||
| retain_for: Some(RetainFor::default()), | ||
| view_options: ViewOptions::default(), | ||
|
|
@@ -677,6 +742,7 @@ impl From<Config> 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, | ||
| warnings: config.warnings, | ||
| retention: config.retain_for, | ||
| charset: Some(CharsetConfig { | ||
| lang: config.view_options.lang, | ||
|
|
@@ -699,6 +765,7 @@ impl TryFrom<ConfigFile> for Config { | |
| Ok(Config { | ||
| target_addr: value.target_addr()?, | ||
| log_filter: value.log_filter()?, | ||
| warnings: value.warnings.clone(), | ||
| log_directory: value.log_directory.take(), | ||
| retain_for: value.retain_for(), | ||
| view_options: ViewOptions { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.