diff options
Diffstat (limited to 'src/bin/main.rs')
-rw-r--r-- | src/bin/main.rs | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index b0596532..3ffaf234 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -42,7 +42,7 @@ fn main() -> Result<()> { // let _profiler = dhat::Profiler::new_heap(); let matches = clap::get_matches(); - #[cfg(all(feature = "fern", debug_assertions))] + #[cfg(all(feature = "fern"))] { utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log"))?; } @@ -85,15 +85,28 @@ fn main() -> Result<()> { let thread_termination_lock = Arc::new(Mutex::new(false)); let thread_termination_cvar = Arc::new(Condvar::new()); - // Set up input handling let (sender, receiver) = mpsc::channel(); + + // Set up event loop thread; we set this up early to speed up first-time-to-data. + let (collection_thread_ctrl_sender, collection_thread_ctrl_receiver) = mpsc::channel(); + let _collection_thread = create_collection_thread( + sender.clone(), + collection_thread_ctrl_receiver, + thread_termination_lock.clone(), + thread_termination_cvar.clone(), + &app.app_config_fields, + app.filters.clone(), + app.used_widgets, + ); + + // Set up input handling loop thread. let _input_thread = create_input_thread(sender.clone(), thread_termination_lock.clone()); - // Cleaning loop + // Set up cleaning loop thread. let _cleaning_thread = { let lock = thread_termination_lock.clone(); let cvar = thread_termination_cvar.clone(); - let cleaning_sender = sender.clone(); + let cleaning_sender = sender; let offset_wait_time = app.app_config_fields.retention_ms + 60000; thread::spawn(move || { loop { @@ -114,19 +127,7 @@ fn main() -> Result<()> { }) }; - // Event loop - let (collection_thread_ctrl_sender, collection_thread_ctrl_receiver) = mpsc::channel(); - let _collection_thread = create_collection_thread( - sender, - collection_thread_ctrl_receiver, - thread_termination_lock.clone(), - thread_termination_cvar.clone(), - &app.app_config_fields, - app.filters.clone(), - app.used_widgets.clone(), - ); - - // Set up up tui and crossterm + // Set up tui and crossterm let mut stdout_val = stdout(); execute!( stdout_val, @@ -162,6 +163,9 @@ fn main() -> Result<()> { })?; let mut first_run = true; + // Draw once first to initialize the canvas, so it doesn't feel like it's frozen. + try_drawing(&mut terminal, &mut app, &mut painter)?; + while !is_terminated.load(Ordering::SeqCst) { // TODO: Would be good to instead use a mix of is_terminated check + recv. Probably use a termination event instead. if let Ok(recv) = receiver.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) { |