summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-09-30 22:06:57 -0400
committerGitHub <noreply@github.com>2020-09-30 22:06:57 -0400
commit9afb6d7c88ca515ecd8d37134b567b6d17e0f0fb (patch)
tree0f5918a7ba31de81d388bc9c1b738423386fe9d8 /src/app
parent57e87d88d09e6282770a2315977fe43ef52958b4 (diff)
feature: add --debug flag for logging (#259)
Adds a `--debug` flag to aid in debugging issues. This saves to `/tmp/bottom_debug.log`.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/data_farmer.rs11
-rw-r--r--src/app/data_harvester.rs70
-rw-r--r--src/app/layout_manager.rs2
3 files changed, 80 insertions, 3 deletions
diff --git a/src/app/data_farmer.rs b/src/app/data_farmer.rs
index 48417ae5..5238c9cc 100644
--- a/src/app/data_farmer.rs
+++ b/src/app/data_farmer.rs
@@ -101,6 +101,7 @@ impl DataCollection {
}
pub fn clean_data(&mut self, max_time_millis: u64) {
+ trace!("Cleaning data.");
let current_time = Instant::now();
let mut remove_index = 0;
@@ -116,7 +117,10 @@ impl DataCollection {
}
pub fn eat_data(&mut self, harvested_data: &Data) {
+ trace!("Eating data now...");
let harvested_time = harvested_data.last_collection_time;
+ trace!("Harvested time: {:?}", harvested_time);
+ trace!("New current instant: {:?}", self.current_instant);
let mut new_entry = TimedData::default();
// Network
@@ -166,6 +170,7 @@ impl DataCollection {
fn eat_memory_and_swap(
&mut self, memory: &mem::MemHarvest, swap: &mem::MemHarvest, new_entry: &mut TimedData,
) {
+ trace!("Eating mem and swap.");
// Memory
let mem_percent = match memory.mem_total_in_mb {
0 => 0f64,
@@ -188,6 +193,7 @@ impl DataCollection {
}
fn eat_network(&mut self, network: &network::NetworkHarvest, new_entry: &mut TimedData) {
+ trace!("Eating network.");
// FIXME [NETWORKING; CONFIG]: The ability to config this?
// FIXME [NETWORKING]: Support bits, support switching between decimal and binary units (move the log part to conversion and switch on the fly)
// RX
@@ -209,6 +215,7 @@ impl DataCollection {
}
fn eat_cpu(&mut self, cpu: &[cpu::CpuData], 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.
@@ -219,6 +226,7 @@ impl DataCollection {
}
fn eat_temp(&mut self, temperature_sensors: &[temperature::TempHarvest]) {
+ trace!("Eating temps.");
// TODO: [PO] To implement
self.temp_harvest = temperature_sensors.to_vec();
}
@@ -226,6 +234,7 @@ impl DataCollection {
fn eat_disks(
&mut self, disks: &[disks::DiskHarvest], io: &disks::IOHarvest, harvested_time: Instant,
) {
+ trace!("Eating disks.");
// TODO: [PO] To implement
let time_since_last_harvest = harvested_time
@@ -300,10 +309,12 @@ impl DataCollection {
}
fn eat_proc(&mut self, list_of_processes: &[processes::ProcessHarvest]) {
+ trace!("Eating proc.");
self.process_harvest = list_of_processes.to_vec();
}
fn eat_battery(&mut self, list_of_batteries: &[battery_harvester::BatteryHarvest]) {
+ trace!("Eating batteries.");
self.battery_harvest = list_of_batteries.to_vec();
}
}
diff --git a/src/app/data_harvester.rs b/src/app/data_harvester.rs
index 0bc99bfd..bd0c98e0 100644
--- a/src/app/data_harvester.rs
+++ b/src/app/data_harvester.rs
@@ -53,7 +53,7 @@ impl Default for Data {
}
impl Data {
- pub fn first_run_cleanup(&mut self) {
+ pub fn cleanup(&mut self) {
self.io = None;
self.temperature_sensors = None;
self.list_of_processes = None;
@@ -68,6 +68,7 @@ impl Data {
}
}
+#[derive(Debug)]
pub struct DataCollector {
pub data: Data,
sys: System,
@@ -134,9 +135,14 @@ impl DataCollector {
}
}
+ trace!("Running first run.");
futures::executor::block_on(self.update_data());
std::thread::sleep(std::time::Duration::from_millis(250));
- self.data.first_run_cleanup();
+
+ trace!("Running first run cleanup now.");
+ self.data.cleanup();
+
+ trace!("Enabled widgets to harvest: {:#?}", self.widgets_to_harvest);
}
pub fn set_collected_data(&mut self, used_widgets: UsedWidgets) {
@@ -193,6 +199,13 @@ impl DataCollector {
// CPU
if self.widgets_to_harvest.use_cpu {
self.data.cpu = Some(cpu::get_cpu_data_list(&self.sys, self.show_average_cpu));
+ if log_enabled!(log::Level::Trace) {
+ if let Some(cpus) = &self.data.cpu {
+ trace!("cpus: {:#?} results", cpus.len());
+ } else {
+ trace!("Found no cpus.");
+ }
+ }
}
// Batteries
@@ -203,6 +216,14 @@ impl DataCollector {
battery_list,
));
}
+
+ if log_enabled!(log::Level::Trace) {
+ if let Some(batteries) = &self.data.list_of_batteries {
+ trace!("batteries: {:#?} results", batteries.len());
+ } else {
+ trace!("Found no batteries.");
+ }
+ }
}
if self.widgets_to_harvest.use_proc {
@@ -244,6 +265,14 @@ impl DataCollector {
} {
self.data.list_of_processes = Some(process_list);
}
+
+ if log_enabled!(log::Level::Trace) {
+ if let Some(processes) = &self.data.list_of_processes {
+ trace!("processes: {:#?} results", processes.len());
+ } else {
+ trace!("Found no processes.");
+ }
+ }
}
// Async if Heim
@@ -350,26 +379,63 @@ impl DataCollector {
self.total_rx = net_data.total_rx;
self.total_tx = net_data.total_tx;
self.data.network = Some(net_data);
+ if log_enabled!(log::Level::Trace) {
+ trace!("Total rx: {:#?}", self.total_rx);
+ trace!("Total tx: {:#?}", self.total_tx);
+ if let Some(network) = &self.data.network {
+ trace!("network rx: {:#?}", network.rx);
+ trace!("network tx: {:#?}", network.tx);
+ } else {
+ trace!("Could not find any networks.");
+ }
+ }
}
if let Ok(memory) = mem_res {
self.data.memory = memory;
+ if log_enabled!(log::Level::Trace) {
+ trace!("mem: {:?} results", self.data.memory);
+ }
}
if let Ok(swap) = swap_res {
self.data.swap = swap;
+ if log_enabled!(log::Level::Trace) {
+ trace!("swap: {:?} results", self.data.swap);
+ }
}
if let Ok(disks) = disk_res {
self.data.disks = disks;
+ if log_enabled!(log::Level::Trace) {
+ if let Some(disks) = &self.data.disks {
+ trace!("disks: {:#?} results", disks.len());
+ } else {
+ trace!("Could not find any disks.");
+ }
+ }
}
if let Ok(io) = io_res {
self.data.io = io;
+ if log_enabled!(log::Level::Trace) {
+ if let Some(io) = &self.data.io {
+ trace!("io: {:#?} results", io.len());
+ } else {
+ trace!("Could not find any io results.");
+ }
+ }
}
if let Ok(temp) = temp_res {
self.data.temperature_sensors = temp;
+ if log_enabled!(log::Level::Trace) {
+ if let Some(sensors) = &self.data.temperature_sensors {
+ trace!("temp: {:#?} results", sensors.len());
+ } else {
+ trace!("Could not find any temp sensors.");
+ }
+ }
}
// Update time
diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs
index 6036c2a5..c856c42d 100644
--- a/src/app/layout_manager.rs
+++ b/src/app/layout_manager.rs
@@ -968,7 +968,7 @@ Supported widget names:
}
}
-#[derive(Clone, Default)]
+#[derive(Clone, Default, Debug)]
pub struct UsedWidgets {
pub use_cpu: bool,
pub use_mem: bool,