diff --git a/Cargo.lock b/Cargo.lock index a48d81257f..7f98a77512 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3108,6 +3108,7 @@ dependencies = [ name = "nu-std" version = "0.91.1" dependencies = [ + "log", "miette", "nu-engine", "nu-parser", diff --git a/crates/nu-cli/src/reedline_config.rs b/crates/nu-cli/src/reedline_config.rs index 5f0f9d2270..b49dad878c 100644 --- a/crates/nu-cli/src/reedline_config.rs +++ b/crates/nu-cli/src/reedline_config.rs @@ -1,5 +1,6 @@ use crate::{menus::NuMenuCompleter, NuHelpCompleter}; use crossterm::event::{KeyCode, KeyModifiers}; +use log::trace; use nu_color_config::{color_record_to_nustyle, lookup_ansi_color_style}; use nu_engine::eval_block; use nu_parser::parse; @@ -78,6 +79,7 @@ pub(crate) fn add_menus( stack: &Stack, config: &Config, ) -> Result { + trace!("add_menus: config: {:#?}", &config); line_editor = line_editor.clear_menus(); for menu in &config.menus { diff --git a/crates/nu-cli/src/repl.rs b/crates/nu-cli/src/repl.rs index 3792e06af7..c39f6c6410 100644 --- a/crates/nu-cli/src/repl.rs +++ b/crates/nu-cli/src/repl.rs @@ -360,6 +360,7 @@ fn loop_iteration(ctx: LoopContext) -> (bool, Stack, Reedline) { ); start_time = std::time::Instant::now(); + trace!("adding menus"); line_editor = add_menus(line_editor, engine_reference, &stack_arc, config).unwrap_or_else(|e| { report_error_new(engine_state, &e); diff --git a/crates/nu-std/Cargo.toml b/crates/nu-std/Cargo.toml index 70df4df9d2..443aed0fd1 100644 --- a/crates/nu-std/Cargo.toml +++ b/crates/nu-std/Cargo.toml @@ -13,3 +13,4 @@ nu-protocol = { version = "0.91.1", path = "../nu-protocol" } nu-engine = { version = "0.91.1", path = "../nu-engine" } miette = { workspace = true, features = ["fancy-no-backtrace"] } +log = "0.4" diff --git a/crates/nu-std/src/lib.rs b/crates/nu-std/src/lib.rs index 93c0523ce6..9389d6a0d0 100644 --- a/crates/nu-std/src/lib.rs +++ b/crates/nu-std/src/lib.rs @@ -1,3 +1,4 @@ +use log::trace; use nu_engine::{env::current_dir, eval_block}; use nu_parser::parse; use nu_protocol::{ @@ -13,6 +14,7 @@ const NU_STDLIB_VIRTUAL_DIR: &str = "NU_STDLIB_VIRTUAL_DIR"; pub fn load_standard_library( engine_state: &mut nu_protocol::engine::EngineState, ) -> Result<(), miette::ErrReport> { + trace!("load_standard_library"); let (block, delta) = { // Using full virtual path to avoid potential conflicts with user having 'std' directory // in their working directory. diff --git a/src/config_files.rs b/src/config_files.rs index 3091bda199..af58d1f233 100644 --- a/src/config_files.rs +++ b/src/config_files.rs @@ -1,4 +1,4 @@ -use log::info; +use log::{info, trace}; #[cfg(feature = "plugin")] use nu_cli::read_plugin_file; use nu_cli::{eval_config_contents, eval_source}; @@ -27,6 +27,7 @@ pub(crate) fn read_config_file( config_file: Option>, is_env_config: bool, ) { + trace!("read_config_file {:?}", &config_file); // Load config startup file if let Some(file) = config_file { let working_set = StateWorkingSet::new(engine_state); @@ -129,6 +130,7 @@ pub(crate) fn read_loginshell_file(engine_state: &mut EngineState, stack: &mut S } pub(crate) fn read_default_env_file(engine_state: &mut EngineState, stack: &mut Stack) { + trace!("read_default_env_file"); let config_file = get_default_env(); eval_source( engine_state, @@ -161,6 +163,11 @@ fn eval_default_config( config_file: &str, is_env_config: bool, ) { + trace!( + "eval_default_config: config_file: {:?}, is_env_config: {}", + &config_file, + is_env_config + ); println!("Continuing without config file"); // Just use the contents of "default_config.nu" or "default_env.nu" eval_source( @@ -199,6 +206,12 @@ pub(crate) fn setup_config( env_file: Option>, is_login_shell: bool, ) { + trace!( + "setup_config: config: {:?}, env: {:?}, login: {}", + &config_file, + &env_file, + is_login_shell + ); let result = catch_unwind(AssertUnwindSafe(|| { #[cfg(feature = "plugin")] read_plugin_file(engine_state, stack, plugin_file, NUSHELL_FOLDER); @@ -225,6 +238,13 @@ pub(crate) fn set_config_path( key: &str, config_file: Option<&Spanned>, ) { + trace!( + "set_config_path: cwd: {:?}, default_config: {}, key: {}, config_file: {:?}", + &cwd, + &default_config_name, + &key, + &config_file + ); let config_path = match config_file { Some(s) => canonicalize_with(&s.item, cwd).ok(), None => nu_path::config_dir().map(|mut p| { diff --git a/src/main.rs b/src/main.rs index e292cbeba3..9b293bc7fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use crate::{ logger::{configure, logger}, }; use command::gather_commandline_args; -use log::Level; +use log::{trace, Level}; use miette::Result; use nu_cli::gather_parent_env_vars; use nu_cmd_base::util::get_init_cwd; @@ -233,6 +233,7 @@ fn main() -> Result<()> { ); } + start_time = std::time::Instant::now(); if let Some(include_path) = &parsed_nu_cli_args.include_path { let span = include_path.span; let vals: Vec<_> = include_path @@ -243,6 +244,14 @@ fn main() -> Result<()> { engine_state.add_env_var("NU_LIB_DIRS".into(), Value::list(vals, span)); } + perf( + "NU_LIB_DIRS setup", + start_time, + file!(), + line!(), + column!(), + use_color, + ); start_time = std::time::Instant::now(); // First, set up env vars as strings only @@ -265,7 +274,16 @@ fn main() -> Result<()> { load_standard_library(&mut engine_state)?; } + start_time = std::time::Instant::now(); if parsed_nu_cli_args.lsp { + perf( + "lsp starting", + start_time, + file!(), + line!(), + column!(), + use_color, + ); return LanguageServer::initialize_stdio_connection()?.serve_requests(engine_state, ctrlc); } @@ -330,6 +348,7 @@ fn main() -> Result<()> { start_time = std::time::Instant::now(); let input = if let Some(redirect_stdin) = &parsed_nu_cli_args.redirect_stdin { + trace!("redirecting stdin"); let stdin = std::io::stdin(); let buf_reader = BufReader::new(stdin); @@ -347,6 +366,7 @@ fn main() -> Result<()> { trim_end_newline: false, } } else { + trace!("not redirecting stdin"); PipelineData::empty() }; perf( @@ -358,9 +378,18 @@ fn main() -> Result<()> { use_color, ); + start_time = std::time::Instant::now(); // Set up the $nu constant before evaluating config files (need to have $nu available in them) let nu_const = create_nu_constant(&engine_state, input.span().unwrap_or_else(Span::unknown))?; engine_state.set_variable_const_val(NU_VARIABLE_ID, nu_const); + perf( + "create_nu_constant", + start_time, + file!(), + line!(), + column!(), + use_color, + ); if let Some(commands) = parsed_nu_cli_args.commands.clone() { run_commands( diff --git a/src/run.rs b/src/run.rs index 4f0edcde05..576b6c9abd 100644 --- a/src/run.rs +++ b/src/run.rs @@ -4,6 +4,7 @@ use crate::{ command, config_files::{self, setup_config}, }; +use log::trace; #[cfg(feature = "plugin")] use nu_cli::read_plugin_file; use nu_cli::{evaluate_commands, evaluate_file, evaluate_repl}; @@ -18,6 +19,7 @@ pub(crate) fn run_commands( input: PipelineData, entire_start_time: std::time::Instant, ) -> Result<(), miette::ErrReport> { + trace!("run_commands"); let mut stack = nu_protocol::engine::Stack::new(); let start_time = std::time::Instant::now(); @@ -141,6 +143,7 @@ pub(crate) fn run_file( args_to_script: Vec, input: PipelineData, ) -> Result<(), miette::ErrReport> { + trace!("run_file"); let mut stack = nu_protocol::engine::Stack::new(); let start_time = std::time::Instant::now(); @@ -242,6 +245,7 @@ pub(crate) fn run_repl( parsed_nu_cli_args: command::NushellCliArgs, entire_start_time: std::time::Instant, ) -> Result<(), miette::ErrReport> { + trace!("run_repl"); let mut stack = nu_protocol::engine::Stack::new(); let start_time = std::time::Instant::now();