diff --git a/Cargo.lock b/Cargo.lock index cd794dfc..7f38974e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1197,9 +1197,9 @@ checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] @@ -1397,9 +1397,9 @@ checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] name = "syn" -version = "1.0.60" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ "proc-macro2", "quote", diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs index 73830842..31c247ca 100644 --- a/src/app/data_farmer.rs +++ b/src/app/data_farmer.rs @@ -105,7 +105,6 @@ impl DataCollection { } pub fn clean_data(&mut self, max_time_millis: u64) { - // trace!("Cleaning data."); let current_time = Instant::now(); let remove_index = match self @@ -125,7 +124,6 @@ impl DataCollection { } pub fn eat_data(&mut self, harvested_data: Box) { - // trace!("Eating data now..."); let harvested_time = harvested_data.last_collection_time; // trace!("Harvested time: {:?}", harvested_time); // trace!("New current instant: {:?}", self.current_instant); @@ -181,7 +179,6 @@ impl DataCollection { fn eat_memory_and_swap( &mut self, memory: memory::MemHarvest, swap: memory::MemHarvest, new_entry: &mut TimedData, ) { - // trace!("Eating mem and swap."); // Memory let mem_percent = if memory.mem_total_in_kib > 0 { Some((memory.mem_used_in_kib as f64) / (memory.mem_total_in_kib as f64) * 100.0) @@ -219,7 +216,6 @@ impl DataCollection { } fn eat_cpu(&mut self, cpu: Vec, new_entry: &mut TimedData) { - // trace!("Eating CPU."); // Note this only pre-calculates the data points - the names will be // within the local copy of cpu_harvest. Since it's all sequential // it probably doesn't matter anyways. @@ -236,7 +232,6 @@ impl DataCollection { } fn eat_temp(&mut self, temperature_sensors: Vec) { - // trace!("Eating temps."); // TODO: [PO] To implement self.temp_harvest = temperature_sensors.to_vec(); } @@ -244,7 +239,6 @@ impl DataCollection { fn eat_disks( &mut self, disks: Vec, io: disks::IoHarvest, harvested_time: Instant, ) { - // trace!("Eating disks."); // TODO: [PO] To implement let time_since_last_harvest = harvested_time @@ -325,12 +319,10 @@ impl DataCollection { } fn eat_proc(&mut self, list_of_processes: Vec) { - // trace!("Eating proc."); self.process_harvest = list_of_processes; } fn eat_battery(&mut self, list_of_batteries: Vec) { - // trace!("Eating batteries."); self.battery_harvest = list_of_batteries; } } diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs index feab6005..5d2bebfe 100644 --- a/src/app/data_harvester.rs +++ b/src/app/data_harvester.rs @@ -151,7 +151,6 @@ impl DataCollector { } if self.widgets_to_harvest.use_battery { - // trace!("First run battery vec creation."); if let Ok(battery_manager) = Manager::new() { if let Ok(batteries) = battery_manager.batteries() { let battery_list: Vec = batteries.filter_map(Result::ok).collect(); @@ -163,12 +162,10 @@ impl DataCollector { } } - // trace!("Running first run."); futures::executor::block_on(self.update_data()); - // trace!("First run done. Sleeping for 250ms..."); + std::thread::sleep(std::time::Duration::from_millis(250)); - // trace!("First run done. Running first run cleanup now."); self.data.cleanup(); // trace!("Enabled widgets to harvest: {:#?}", self.widgets_to_harvest); diff --git a/src/bin/main.rs b/src/bin/main.rs index e9854987..02828ed7 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -26,30 +26,17 @@ use crossterm::{ }; use tui::{backend::CrosstermBackend, Terminal}; -// TODO: Add a debugger tool: -// Debugger binary. This isn't implemented yet; the idea for this is to make it easier to troubleshoot bug reports -// by providing a built-in debugger to help gather relevant information to narrow down the problem. - fn main() -> Result<()> { let matches = clap::get_matches(); - // let is_debug = matches.is_present("debug"); - // if is_debug { - // let mut tmp_dir = std::env::temp_dir(); - // tmp_dir.push("bottom_debug.log"); - // utils::logging::init_logger(log::LevelFilter::Trace, tmp_dir.as_os_str())?; - // } else { #[cfg(all(feature = "fern", debug_assertions))] { utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log"))?; } - // } let config_path = read_config(matches.value_of("config_location")) .context("Unable to access the given config file location.")?; - // trace!("Config path: {:?}", config_path); let mut config: Config = create_or_get_config(&config_path) .context("Unable to properly parse or create the config file.")?; - // trace!("Current config: {:#?}", config); // Get widget layout separately let (widget_layout, default_widget_id, default_widget_type_option) = @@ -90,30 +77,22 @@ fn main() -> Result<()> { let cvar = thread_termination_cvar.clone(); let cleaning_sender = sender.clone(); const OFFSET_WAIT_TIME: u64 = constants::STALE_MAX_MILLISECONDS + 60000; - // trace!("Initializing cleaning thread..."); thread::spawn(move || { loop { - // debug!("Starting cleaning loop..."); let result = cvar.wait_timeout( lock.lock().unwrap(), Duration::from_millis(OFFSET_WAIT_TIME), ); - // debug!("Result mutex guard over..."); if let Ok(result) = result { if *(result.0) { - // debug!("Received termination lock in cleaning thread from cvar!"); break; } } - // debug!("Sending cleaning signal..."); if cleaning_sender.send(BottomEvent::Clean).is_err() { // debug!("Failed to send cleaning sender..."); break; } - // trace!("Cleaning signal sent without errors."); } - - // trace!("Cleaning thread loop has closed."); }) }; @@ -256,14 +235,12 @@ fn main() -> Result<()> { } // I think doing it in this order is safe... - // trace!("Send termination thread locks."); + *thread_termination_lock.lock().unwrap() = true; - // trace!("Notifying all cvars."); + thread_termination_cvar.notify_all(); - // trace!("Main/drawing thread is cleaning up."); cleanup_terminal(&mut terminal)?; - // trace!("Fini."); Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 9a7c489d..438d0bd6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -594,9 +594,7 @@ pub fn create_input_thread( >, termination_ctrl_lock: Arc>, ) -> std::thread::JoinHandle<()> { - // trace!("Creating input thread."); thread::spawn(move || { - // trace!("Spawned input thread."); let mut mouse_timer = Instant::now(); let mut keyboard_timer = Instant::now(); @@ -604,7 +602,6 @@ pub fn create_input_thread( if let Ok(is_terminated) = termination_ctrl_lock.try_lock() { // We don't block. if *is_terminated { - // trace!("Received termination lock in input thread!"); drop(is_terminated); break; } @@ -612,13 +609,11 @@ pub fn create_input_thread( if let Ok(poll) = poll(Duration::from_millis(20)) { if poll { if let Ok(event) = read() { - // trace!("Input thread received an event: {:?}", event); if let Event::Key(key) = event { if Instant::now().duration_since(keyboard_timer).as_millis() >= 20 { if sender.send(BottomEvent::KeyInput(key)).is_err() { break; } - // trace!("Input thread sent keyboard data."); keyboard_timer = Instant::now(); } } else if let Event::Mouse(mouse) = event { @@ -626,7 +621,6 @@ pub fn create_input_thread( if sender.send(BottomEvent::MouseInput(mouse)).is_err() { break; } - // trace!("Input thread sent mouse data."); mouse_timer = Instant::now(); } } @@ -634,7 +628,6 @@ pub fn create_input_thread( } } } - // trace!("Input thread loop has closed."); }) } @@ -647,36 +640,31 @@ pub fn create_collection_thread( app_config_fields: &app::AppConfigFields, filters: app::DataFilters, used_widget_set: UsedWidgets, ) -> std::thread::JoinHandle<()> { - // trace!("Creating collection thread."); let temp_type = app_config_fields.temperature_type.clone(); let use_current_cpu_total = app_config_fields.use_current_cpu_total; let show_average_cpu = app_config_fields.show_average_cpu; let update_rate_in_milliseconds = app_config_fields.update_rate_in_milliseconds; thread::spawn(move || { - // trace!("Spawned collection thread."); let mut data_state = data_harvester::DataCollector::new(filters); - // trace!("Created default data state."); + data_state.set_collected_data(used_widget_set); data_state.set_temperature_type(temp_type); data_state.set_use_current_cpu_total(use_current_cpu_total); data_state.set_show_average_cpu(show_average_cpu); - // trace!("Set default data state settings."); data_state.init(); - // trace!("Data state is now fully initialized."); + loop { // Check once at the very top... if let Ok(is_terminated) = termination_ctrl_lock.try_lock() { // We don't block here. if *is_terminated { - // trace!("Received termination lock in collection thread!"); drop(is_terminated); break; } } - // trace!("Checking for collection control receiver event..."); let mut update_time = update_rate_in_milliseconds; if let Ok(message) = control_receiver.try_recv() { // trace!("Received message in collection thread: {:?}", message); @@ -704,32 +692,26 @@ pub fn create_collection_thread( if let Ok(is_terminated) = termination_ctrl_lock.try_lock() { // We don't block here. if *is_terminated { - // trace!("Received termination lock in collection thread!"); drop(is_terminated); break; } } - // trace!("Collection thread is updating and sending..."); let event = BottomEvent::Update(Box::from(data_state.data)); data_state.data = data_harvester::Data::default(); if sender.send(event).is_err() { - // trace!("Error sending from collection thread..."); break; } - // trace!("No problem sending from collection thread!"); if let Ok((is_terminated, _wait_timeout_result)) = termination_ctrl_cvar.wait_timeout( termination_ctrl_lock.lock().unwrap(), Duration::from_millis(update_time), ) { if *is_terminated { - // trace!("Received termination lock in collection thread from cvar!"); drop(is_terminated); break; } } } - // trace!("Collection thread loop has closed."); }) }