diff --git a/crates/nu-cli/src/commands.rs b/crates/nu-cli/src/commands.rs index 3188985ff7..3b107716a8 100644 --- a/crates/nu-cli/src/commands.rs +++ b/crates/nu-cli/src/commands.rs @@ -15,7 +15,6 @@ pub fn evaluate_commands( engine_state: &mut EngineState, stack: &mut Stack, input: PipelineData, - is_perf_true: bool, table_mode: Option, ) -> Result> { // Translate environment variables from Strings to Values @@ -68,9 +67,7 @@ pub fn evaluate_commands( } }; - if is_perf_true { - info!("evaluate {}:{}:{}", file!(), line!(), column!()); - } + info!("evaluate {}:{}:{}", file!(), line!(), column!()); Ok(exit_code) } diff --git a/crates/nu-cli/src/config_files.rs b/crates/nu-cli/src/config_files.rs index 2fd7836604..3767228428 100644 --- a/crates/nu-cli/src/config_files.rs +++ b/crates/nu-cli/src/config_files.rs @@ -23,7 +23,6 @@ pub fn read_plugin_file( stack: &mut Stack, plugin_file: Option>, storage_path: &str, - is_perf_true: bool, ) { // Reading signatures from signature file // The plugin.nu file stores the parsed signature collected from each registered plugin @@ -44,9 +43,7 @@ pub fn read_plugin_file( } } - if is_perf_true { - info!("read_plugin_file {}:{}:{}", file!(), line!(), column!()); - } + info!("read_plugin_file {}:{}:{}", file!(), line!(), column!()); } #[cfg(feature = "plugin")] diff --git a/crates/nu-cli/src/eval_file.rs b/crates/nu-cli/src/eval_file.rs index c1a481bbe6..cdddeb319a 100644 --- a/crates/nu-cli/src/eval_file.rs +++ b/crates/nu-cli/src/eval_file.rs @@ -19,7 +19,6 @@ pub fn evaluate_file( engine_state: &mut EngineState, stack: &mut Stack, input: PipelineData, - is_perf_true: bool, ) -> Result<()> { // Translate environment variables from Strings to Values if let Some(e) = convert_env_values(engine_state, stack) { @@ -54,9 +53,7 @@ pub fn evaluate_file( std::process::exit(1); } - if is_perf_true { - info!("evaluate {}:{}:{}", file!(), line!(), column!()); - } + info!("evaluate {}:{}:{}", file!(), line!(), column!()); Ok(()) } diff --git a/crates/nu-cli/src/prompt_update.rs b/crates/nu-cli/src/prompt_update.rs index 6877f57320..1adefd96c6 100644 --- a/crates/nu-cli/src/prompt_update.rs +++ b/crates/nu-cli/src/prompt_update.rs @@ -25,7 +25,6 @@ fn get_prompt_string( config: &Config, engine_state: &EngineState, stack: &mut Stack, - is_perf_true: bool, ) -> Option { stack .get_env_var(engine_state, prompt) @@ -44,14 +43,12 @@ fn get_prompt_string( block, PipelineData::new(Span::new(0, 0)), // Don't try this at home, 0 span is ignored ); - if is_perf_true { - info!( - "get_prompt_string (block) {}:{}:{}", - file!(), - line!(), - column!() - ); - } + info!( + "get_prompt_string (block) {}:{}:{}", + file!(), + line!(), + column!() + ); match ret_val { Ok(ret_val) => Some(ret_val), @@ -90,17 +87,10 @@ pub(crate) fn update_prompt<'prompt>( engine_state: &EngineState, stack: &Stack, nu_prompt: &'prompt mut NushellPrompt, - is_perf_true: bool, ) -> &'prompt dyn Prompt { let mut stack = stack.clone(); - let left_prompt_string = get_prompt_string( - PROMPT_COMMAND, - config, - engine_state, - &mut stack, - is_perf_true, - ); + let left_prompt_string = get_prompt_string(PROMPT_COMMAND, config, engine_state, &mut stack); // Now that we have the prompt string lets ansify it. // <133 A><133 B><133 C> @@ -116,45 +106,20 @@ pub(crate) fn update_prompt<'prompt>( left_prompt_string }; - let right_prompt_string = get_prompt_string( - PROMPT_COMMAND_RIGHT, - config, - engine_state, - &mut stack, - is_perf_true, - ); + let right_prompt_string = + get_prompt_string(PROMPT_COMMAND_RIGHT, config, engine_state, &mut stack); - let prompt_indicator_string = get_prompt_string( - PROMPT_INDICATOR, - config, - engine_state, - &mut stack, - is_perf_true, - ); + let prompt_indicator_string = + get_prompt_string(PROMPT_INDICATOR, config, engine_state, &mut stack); - let prompt_multiline_string = get_prompt_string( - PROMPT_MULTILINE_INDICATOR, - config, - engine_state, - &mut stack, - is_perf_true, - ); + let prompt_multiline_string = + get_prompt_string(PROMPT_MULTILINE_INDICATOR, config, engine_state, &mut stack); - let prompt_vi_insert_string = get_prompt_string( - PROMPT_INDICATOR_VI_INSERT, - config, - engine_state, - &mut stack, - is_perf_true, - ); + let prompt_vi_insert_string = + get_prompt_string(PROMPT_INDICATOR_VI_INSERT, config, engine_state, &mut stack); - let prompt_vi_normal_string = get_prompt_string( - PROMPT_INDICATOR_VI_NORMAL, - config, - engine_state, - &mut stack, - is_perf_true, - ); + let prompt_vi_normal_string = + get_prompt_string(PROMPT_INDICATOR_VI_NORMAL, config, engine_state, &mut stack); // apply the other indicators nu_prompt.update_all_prompt_strings( @@ -166,9 +131,7 @@ pub(crate) fn update_prompt<'prompt>( ); let ret_val = nu_prompt as &dyn Prompt; - if is_perf_true { - info!("update_prompt {}:{}:{}", file!(), line!(), column!()); - } + info!("update_prompt {}:{}:{}", file!(), line!(), column!()); ret_val } diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 47f34954bf..4115a3310d 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -41,7 +41,6 @@ pub fn evaluate_repl( engine_state: &mut EngineState, stack: &mut Stack, nushell_path: &str, - is_perf_true: bool, prerun_command: Option>, ) -> Result<()> { use reedline::{FileBackedHistory, Reedline, Signal}; @@ -60,14 +59,12 @@ pub fn evaluate_repl( let mut nu_prompt = NushellPrompt::new(); - if is_perf_true { - info!( - "translate environment vars {}:{}:{}", - file!(), - line!(), - column!() - ); - } + info!( + "translate environment vars {}:{}:{}", + file!(), + line!(), + column!() + ); // Translate environment variables from Strings to Values if let Some(e) = convert_env_values(engine_state, stack) { @@ -92,18 +89,14 @@ pub fn evaluate_repl( }, ); - if is_perf_true { - info!( - "load config initially {}:{}:{}", - file!(), - line!(), - column!() - ); - } + info!( + "load config initially {}:{}:{}", + file!(), + line!(), + column!() + ); - if is_perf_true { - info!("setup reedline {}:{}:{}", file!(), line!(), column!()); - } + info!("setup reedline {}:{}:{}", file!(), line!(), column!()); let mut line_editor = Reedline::create(); @@ -121,9 +114,7 @@ pub fn evaluate_repl( engine_state.config.history_file_format, ); if let Some(history_path) = history_path.as_deref() { - if is_perf_true { - info!("setup history {}:{}:{}", file!(), line!(), column!()); - } + info!("setup history {}:{}:{}", file!(), line!(), column!()); let history: Box = match engine_state.config.history_file_format { HistoryFileFormat::PlainText => Box::new( @@ -173,14 +164,12 @@ pub fn evaluate_repl( } loop { - if is_perf_true { - info!( - "load config each loop {}:{}:{}", - file!(), - line!(), - column!() - ); - } + info!( + "load config each loop {}:{}:{}", + file!(), + line!(), + column!() + ); let cwd = get_guaranteed_cwd(engine_state, stack); @@ -201,15 +190,11 @@ pub fn evaluate_repl( let config = engine_state.get_config(); - if is_perf_true { - info!("setup colors {}:{}:{}", file!(), line!(), column!()); - } + info!("setup colors {}:{}:{}", file!(), line!(), column!()); let color_hm = get_color_config(config); - if is_perf_true { - info!("update reedline {}:{}:{}", file!(), line!(), column!()); - } + info!("update reedline {}:{}:{}", file!(), line!(), column!()); let engine_reference = std::sync::Arc::new(engine_state.clone()); line_editor = line_editor .with_highlighter(Box::new(NuHighlighter { @@ -266,18 +251,14 @@ pub fn evaluate_repl( }; if config.sync_history_on_enter { - if is_perf_true { - info!("sync history {}:{}:{}", file!(), line!(), column!()); - } + info!("sync history {}:{}:{}", file!(), line!(), column!()); if let Err(e) = line_editor.sync_history() { warn!("Failed to sync history: {}", e); } } - if is_perf_true { - info!("setup keybindings {}:{}:{}", file!(), line!(), column!()); - } + info!("setup keybindings {}:{}:{}", file!(), line!(), column!()); // Changing the line editor based on the found keybindings line_editor = match create_keybindings(config) { @@ -301,9 +282,7 @@ pub fn evaluate_repl( } }; - if is_perf_true { - info!("prompt_update {}:{}:{}", file!(), line!(), column!()); - } + info!("prompt_update {}:{}:{}", file!(), line!(), column!()); // Right before we start our prompt and take input from the user, // fire the "pre_prompt" hook @@ -323,19 +302,16 @@ pub fn evaluate_repl( } let config = engine_state.get_config(); - let prompt = - prompt_update::update_prompt(config, engine_state, stack, &mut nu_prompt, is_perf_true); + let prompt = prompt_update::update_prompt(config, engine_state, stack, &mut nu_prompt); entry_num += 1; - if is_perf_true { - info!( - "finished setup, starting repl {}:{}:{}", - file!(), - line!(), - column!() - ); - } + info!( + "finished setup, starting repl {}:{}:{}", + file!(), + line!(), + column!() + ); let input = line_editor.read_line(prompt); let shell_integration = config.shell_integration; diff --git a/src/config_files.rs b/src/config_files.rs index 789fda6132..3aade0818a 100644 --- a/src/config_files.rs +++ b/src/config_files.rs @@ -17,7 +17,6 @@ pub(crate) fn read_config_file( engine_state: &mut EngineState, stack: &mut Stack, config_file: Option>, - is_perf_true: bool, is_env_config: bool, ) { // Load config startup file @@ -105,16 +104,10 @@ pub(crate) fn read_config_file( eval_config_contents(config_path, engine_state, stack); } - if is_perf_true { - info!("read_config_file {}:{}:{}", file!(), line!(), column!()); - } + info!("read_config_file {}:{}:{}", file!(), line!(), column!()); } -pub(crate) fn read_loginshell_file( - engine_state: &mut EngineState, - stack: &mut Stack, - is_perf_true: bool, -) { +pub(crate) fn read_loginshell_file(engine_state: &mut EngineState, stack: &mut Stack) { // read and execute loginshell file if exists if let Some(mut config_path) = nu_path::config_dir() { config_path.push(NUSHELL_FOLDER); @@ -125,16 +118,10 @@ pub(crate) fn read_loginshell_file( } } - if is_perf_true { - info!("read_loginshell_file {}:{}:{}", file!(), line!(), column!()); - } + info!("read_loginshell_file {}:{}:{}", file!(), line!(), column!()); } -pub(crate) fn read_default_env_file( - engine_state: &mut EngineState, - stack: &mut Stack, - is_perf_true: bool, -) { +pub(crate) fn read_default_env_file(engine_state: &mut EngineState, stack: &mut Stack) { let config_file = get_default_env(); eval_source( engine_state, @@ -144,9 +131,7 @@ pub(crate) fn read_default_env_file( PipelineData::new(Span::new(0, 0)), ); - if is_perf_true { - info!("read_config_file {}:{}:{}", file!(), line!(), column!()); - } + info!("read_config_file {}:{}:{}", file!(), line!(), column!()); // Merge the environment in case env vars changed in the config match nu_engine::env::current_dir(engine_state, stack) { Ok(cwd) => { diff --git a/src/main.rs b/src/main.rs index 3aa21684bb..1499edd8a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ mod tests; #[cfg(feature = "plugin")] use crate::config_files::NUSHELL_FOLDER; use crate::logger::{configure, logger}; -use log::info; +use log::{info, Level}; use miette::Result; #[cfg(feature = "plugin")] use nu_cli::read_plugin_file; @@ -26,7 +26,6 @@ use nu_protocol::{ Spanned, SyntaxShape, Value, }; use nu_utils::stdout_write_all_and_flush; -use std::{cell::RefCell, path::Path}; use std::{ io::BufReader, sync::{ @@ -34,8 +33,7 @@ use std::{ Arc, }, }; - -thread_local! { static IS_PERF: RefCell = RefCell::new(false) } +use std::{path::Path, str::FromStr}; // Inspired by fish's acquire_tty_or_exit #[cfg(unix)] @@ -268,18 +266,17 @@ fn main() -> Result<()> { .expect("error setting number of threads"); } - set_is_perf_value(binary_args.perf); - - if binary_args.perf || binary_args.log_level.is_some() { - // since we're in this section, either perf is true or log_level has been set - // if log_level is set, just use it - // otherwise if perf is true, set the log_level to `info` which is what - // the perf calls are set to. - let level = binary_args + if binary_args.log_level.is_some() { + let mut level = binary_args .log_level .map(|level| level.item) .unwrap_or_else(|| "info".to_string()); + if Level::from_str(level.as_str()).is_err() { + eprintln!("ERROR: log library did not recognize log level '{level}', using default 'info'"); + level = "info".to_string(); + } + let target = binary_args .log_target .map(|target| target.item) @@ -327,9 +324,7 @@ fn main() -> Result<()> { PipelineData::new(Span::new(0, 0)) }; - if is_perf_true() { - info!("redirect_stdin {}:{}:{}", file!(), line!(), column!()); - } + info!("redirect_stdin {}:{}:{}", file!(), line!(), column!()); // First, set up env vars as strings only gather_parent_env_vars(&mut engine_state, &init_cwd); @@ -343,7 +338,6 @@ fn main() -> Result<()> { &mut stack, binary_args.plugin_file, NUSHELL_FOLDER, - is_perf_true(), ); // only want to load config and env if relative argument is provided. @@ -352,15 +346,10 @@ fn main() -> Result<()> { &mut engine_state, &mut stack, binary_args.env_file, - is_perf_true(), true, ); } else { - config_files::read_default_env_file( - &mut engine_state, - &mut stack, - is_perf_true(), - ) + config_files::read_default_env_file(&mut engine_state, &mut stack) } if binary_args.config_file.is_some() { @@ -368,7 +357,6 @@ fn main() -> Result<()> { &mut engine_state, &mut stack, binary_args.config_file, - is_perf_true(), false, ); } @@ -378,12 +366,9 @@ fn main() -> Result<()> { &mut engine_state, &mut stack, input, - is_perf_true(), binary_args.table_mode, ); - if is_perf_true() { - info!("-c command execution {}:{}:{}", file!(), line!(), column!()); - } + info!("-c command execution {}:{}:{}", file!(), line!(), column!()); match ret_val { Ok(Some(exit_code)) => std::process::exit(exit_code as i32), Ok(None) => Ok(()), @@ -396,7 +381,6 @@ fn main() -> Result<()> { &mut stack, binary_args.plugin_file, NUSHELL_FOLDER, - is_perf_true(), ); // only want to load config and env if relative argument is provided. @@ -405,15 +389,10 @@ fn main() -> Result<()> { &mut engine_state, &mut stack, binary_args.env_file, - is_perf_true(), true, ); } else { - config_files::read_default_env_file( - &mut engine_state, - &mut stack, - is_perf_true(), - ) + config_files::read_default_env_file(&mut engine_state, &mut stack) } if binary_args.config_file.is_some() { @@ -421,7 +400,6 @@ fn main() -> Result<()> { &mut engine_state, &mut stack, binary_args.config_file, - is_perf_true(), false, ); } @@ -432,7 +410,6 @@ fn main() -> Result<()> { &mut engine_state, &mut stack, input, - is_perf_true(), ); let last_exit_code = stack.get_env_var(&engine_state, "LAST_EXIT_CODE"); @@ -444,9 +421,7 @@ fn main() -> Result<()> { } } } - if is_perf_true() { - info!("eval_file execution {}:{}:{}", file!(), line!(), column!()); - } + info!("eval_file execution {}:{}:{}", file!(), line!(), column!()); ret_val } else { @@ -464,12 +439,9 @@ fn main() -> Result<()> { &mut engine_state, &mut stack, config_files::NUSHELL_FOLDER, - is_perf_true(), binary_args.execute, ); - if is_perf_true() { - info!("repl eval {}:{}:{}", file!(), line!(), column!()); - } + info!("repl eval {}:{}:{}", file!(), line!(), column!()); ret_val } @@ -487,23 +459,15 @@ fn setup_config( is_login_shell: bool, ) { #[cfg(feature = "plugin")] - read_plugin_file( - engine_state, - stack, - plugin_file, - NUSHELL_FOLDER, - is_perf_true(), - ); + read_plugin_file(engine_state, stack, plugin_file, NUSHELL_FOLDER); - if is_perf_true() { - info!("read_config_file {}:{}:{}", file!(), line!(), column!()); - } + info!("read_config_file {}:{}:{}", file!(), line!(), column!()); - config_files::read_config_file(engine_state, stack, env_file, is_perf_true(), true); - config_files::read_config_file(engine_state, stack, config_file, is_perf_true(), false); + config_files::read_config_file(engine_state, stack, env_file, true); + config_files::read_config_file(engine_state, stack, config_file, false); if is_login_shell { - config_files::read_loginshell_file(engine_state, stack, is_perf_true()); + config_files::read_loginshell_file(engine_state, stack); } // Give a warning if we see `$config` for a few releases @@ -556,7 +520,6 @@ fn parse_commandline_args( let interactive_shell = call.get_named_arg("interactive"); let commands: Option = call.get_flag_expr("commands"); let testbin: Option = call.get_flag_expr("testbin"); - let perf = call.has_flag("perf"); #[cfg(feature = "plugin")] let plugin_file: Option = call.get_flag_expr("plugin-config"); let config_file: Option = call.get_flag_expr("config"); @@ -629,7 +592,6 @@ fn parse_commandline_args( log_level, log_target, execute, - perf, threads, table_mode, }); @@ -656,7 +618,6 @@ struct NushellCliArgs { log_level: Option>, log_target: Option>, execute: Option>, - perf: bool, threads: Option, table_mode: Option, } @@ -676,11 +637,6 @@ impl Command for Nu { .switch("login", "start as a login shell", Some('l')) .switch("interactive", "start as an interactive shell", Some('i')) .switch("version", "print the version", Some('v')) - .switch( - "perf", - "start and print performance metrics during startup", - Some('p'), - ) .named( "testbin", SyntaxShape::String, @@ -708,7 +664,7 @@ impl Command for Nu { .named( "log-level", SyntaxShape::String, - "log level for performance logs", + "log level for diagnostic logs (error, warn, info, debug, trace). Off by default", None, ) .named( @@ -797,16 +753,6 @@ impl Command for Nu { } } -pub fn is_perf_true() -> bool { - IS_PERF.with(|value| *value.borrow()) -} - -fn set_is_perf_value(value: bool) { - IS_PERF.with(|new_value| { - *new_value.borrow_mut() = value; - }); -} - fn set_config_path( engine_state: &mut EngineState, cwd: &Path,