mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 06:34:16 +00:00
refactor: pull data collection out of nested folder structure (#1364)
* refactor: pull data collection out of nested folder structure * fix sysinfo * comment
This commit is contained in:
parent
28d2950d92
commit
22b40780ad
60 changed files with 59 additions and 60 deletions
|
@ -5,7 +5,6 @@ use std::{
|
|||
|
||||
use concat_string::concat_string;
|
||||
use data_farmer::*;
|
||||
use data_harvester::temperature;
|
||||
use filter::*;
|
||||
use hashbrown::HashMap;
|
||||
use layout_manager::*;
|
||||
|
@ -14,6 +13,7 @@ use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation};
|
|||
|
||||
use crate::{
|
||||
constants,
|
||||
data_collection::temperature,
|
||||
data_conversion::ConvertedData,
|
||||
utils::error::{BottomError, Result},
|
||||
Pid,
|
||||
|
@ -24,7 +24,6 @@ use crate::{
|
|||
};
|
||||
|
||||
pub mod data_farmer;
|
||||
pub mod data_harvester;
|
||||
pub mod filter;
|
||||
pub mod frozen_state;
|
||||
pub mod layout_manager;
|
||||
|
@ -117,7 +116,7 @@ pub struct App {
|
|||
pub is_determining_widget_boundary: bool,
|
||||
pub basic_mode_use_percent: bool,
|
||||
#[cfg(target_family = "unix")]
|
||||
pub user_table: data_harvester::processes::UserTable,
|
||||
pub user_table: crate::data_collection::processes::UserTable,
|
||||
pub states: AppWidgetStates,
|
||||
pub app_config_fields: AppConfigFields,
|
||||
pub widget_map: HashMap<u64, BottomWidget>,
|
||||
|
@ -148,7 +147,7 @@ impl App {
|
|||
is_determining_widget_boundary: false,
|
||||
basic_mode_use_percent: false,
|
||||
#[cfg(target_family = "unix")]
|
||||
user_table: data_harvester::processes::UserTable::default(),
|
||||
user_table: crate::data_collection::processes::UserTable::default(),
|
||||
states,
|
||||
app_config_fields,
|
||||
widget_map,
|
||||
|
|
|
@ -13,14 +13,15 @@
|
|||
//! memory usage and higher CPU usage - you will be trying to process more and
|
||||
//! more points as this is used!
|
||||
|
||||
use crate::data_collection::processes::ProcessHarvest;
|
||||
use std::{collections::BTreeMap, time::Instant, vec::Vec};
|
||||
|
||||
use hashbrown::HashMap;
|
||||
|
||||
#[cfg(feature = "battery")]
|
||||
use crate::data_harvester::batteries;
|
||||
use crate::data_collection::batteries;
|
||||
use crate::{
|
||||
data_harvester::{cpu, disks, memory, network, processes::ProcessHarvest, temperature, Data},
|
||||
data_collection::{cpu, disks, memory, network, temperature, Data},
|
||||
utils::data_prefixes::*,
|
||||
utils::gen_util::get_decimal_bytes,
|
||||
Pid,
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{borrow::Cow, collections::VecDeque};
|
|||
use humantime::parse_duration;
|
||||
use regex::Regex;
|
||||
|
||||
use super::data_harvester::processes::ProcessHarvest;
|
||||
use crate::data_collection::processes::ProcessHarvest;
|
||||
use crate::multi_eq_ignore_ascii_case;
|
||||
use crate::utils::data_prefixes::*;
|
||||
use crate::utils::error::{
|
||||
|
|
|
@ -231,6 +231,7 @@ impl Painter {
|
|||
|
||||
terminal.draw(|f| {
|
||||
let (terminal_size, frozen_draw_loc) = if app_state.frozen_state.is_frozen() {
|
||||
// TODO: Remove built-in cache?
|
||||
let split_loc = Layout::default()
|
||||
.constraints([Constraint::Min(0), Constraint::Length(1)])
|
||||
.split(f.size());
|
||||
|
|
|
@ -7,10 +7,11 @@ use tui::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
app::{data_harvester::cpu::CpuDataType, App},
|
||||
app::App,
|
||||
canvas::Painter,
|
||||
components::tui_widget::pipe_gauge::{LabelLimit, PipeGauge},
|
||||
constants::*,
|
||||
data_collection::cpu::CpuDataType,
|
||||
data_conversion::CpuWidgetData,
|
||||
};
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::collections::VecDeque;
|
|||
use sysinfo::{CpuExt, LoadAvg, System, SystemExt};
|
||||
|
||||
use super::{CpuData, CpuDataType, CpuHarvest};
|
||||
use crate::app::data_harvester::cpu::LoadAvgHarvest;
|
||||
use crate::data_collection::cpu::LoadAvgHarvest;
|
||||
|
||||
pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> crate::error::Result<CpuHarvest> {
|
||||
let mut cpu_deque: VecDeque<_> = sys
|
|
@ -7,8 +7,8 @@ use serde::Deserialize;
|
|||
use super::{keep_disk_entry, DiskHarvest, IoHarvest};
|
||||
|
||||
use crate::{
|
||||
app::data_harvester::DataCollector, data_harvester::deserialize_xo,
|
||||
data_harvester::disks::IoData, utils::error,
|
||||
data_collection::deserialize_xo, data_collection::disks::IoData,
|
||||
data_collection::DataCollector, utils::error,
|
||||
};
|
||||
use hashbrown::HashMap;
|
||||
|
||||
|
@ -42,7 +42,7 @@ pub fn get_io_usage() -> error::Result<IoHarvest> {
|
|||
|
||||
#[cfg(feature = "zfs")]
|
||||
{
|
||||
use crate::app::data_harvester::disks::zfs_io_counters;
|
||||
use crate::data_collection::disks::zfs_io_counters;
|
||||
if let Ok(zfs_io) = zfs_io_counters::zfs_io_stats() {
|
||||
for io in zfs_io.into_iter() {
|
||||
let mount_point = io.device_name().to_string_lossy();
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use sysinfo::{DiskExt, SystemExt};
|
||||
|
||||
use crate::app::data_harvester::DataCollector;
|
||||
use crate::data_collection::DataCollector;
|
||||
|
||||
use super::{keep_disk_entry, DiskHarvest};
|
||||
|
|
@ -25,7 +25,7 @@ cfg_if::cfg_if! {
|
|||
}
|
||||
|
||||
use super::{keep_disk_entry, DiskHarvest};
|
||||
use crate::app::data_harvester::DataCollector;
|
||||
use crate::data_collection::DataCollector;
|
||||
|
||||
/// Returns the disk usage of the mounted (and for now, physical) disks.
|
||||
pub fn get_disk_usage(collector: &DataCollector) -> anyhow::Result<Vec<DiskHarvest>> {
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
str::FromStr,
|
||||
};
|
||||
|
||||
use crate::app::data_harvester::disks::IoCounters;
|
||||
use crate::data_collection::disks::IoCounters;
|
||||
|
||||
/// Copied from the `psutil` sources:
|
||||
///
|
||||
|
@ -85,7 +85,7 @@ pub fn io_stats() -> anyhow::Result<Vec<IoCounters>> {
|
|||
|
||||
#[cfg(feature = "zfs")]
|
||||
{
|
||||
use crate::app::data_harvester::disks::zfs_io_counters;
|
||||
use crate::data_collection::disks::zfs_io_counters;
|
||||
if let Ok(mut zfs_io) = zfs_io_counters::zfs_io_stats() {
|
||||
results.append(&mut zfs_io);
|
||||
}
|
|
@ -12,7 +12,7 @@ use std::{
|
|||
|
||||
use anyhow::bail;
|
||||
|
||||
use crate::app::data_harvester::disks::unix::{FileSystem, Usage};
|
||||
use crate::data_collection::disks::unix::{FileSystem, Usage};
|
||||
|
||||
/// Representation of partition details. Based on [`heim`](https://github.com/heim-rs/heim/tree/master).
|
||||
pub(crate) struct Partition {
|
|
@ -1,7 +1,7 @@
|
|||
//! Based on [heim's implementation](https://github.com/heim-rs/heim/blob/master/heim-disk/src/sys/macos/counters.rs).
|
||||
|
||||
use super::io_kit::{self, get_dict, get_disks, get_i64, get_string};
|
||||
use crate::app::data_harvester::disks::IoCounters;
|
||||
use crate::data_collection::disks::IoCounters;
|
||||
|
||||
fn get_device_io(device: io_kit::IoObject) -> anyhow::Result<IoCounters> {
|
||||
let parent = device.service_parent()?;
|
|
@ -8,7 +8,7 @@ use std::{
|
|||
use anyhow::bail;
|
||||
|
||||
use super::bindings;
|
||||
use crate::app::data_harvester::disks::unix::{FileSystem, Usage};
|
||||
use crate::data_collection::disks::unix::{FileSystem, Usage};
|
||||
|
||||
pub(crate) struct Partition {
|
||||
device: String,
|
|
@ -5,7 +5,7 @@ use sysinfo::{DiskExt, SystemExt};
|
|||
|
||||
use super::{keep_disk_entry, DiskHarvest};
|
||||
|
||||
use crate::app::data_harvester::{disks::IoCounters, DataCollector};
|
||||
use crate::data_collection::{disks::IoCounters, DataCollector};
|
||||
|
||||
mod bindings;
|
||||
use bindings::*;
|
|
@ -1,4 +1,4 @@
|
|||
use crate::app::data_harvester::disks::IoCounters;
|
||||
use crate::data_collection::disks::IoCounters;
|
||||
|
||||
/// Returns zpool I/O stats. Pulls data from `sysctl kstat.zfs.{POOL}.dataset.{objset-*}`
|
||||
#[cfg(target_os = "freebsd")]
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use sysinfo::{System, SystemExt};
|
||||
|
||||
use crate::data_harvester::memory::MemHarvest;
|
||||
use crate::data_collection::memory::MemHarvest;
|
||||
|
||||
/// Returns RAM usage.
|
||||
pub(crate) fn get_ram_usage(sys: &System) -> Option<MemHarvest> {
|
|
@ -2,7 +2,7 @@ use std::mem::{size_of, zeroed};
|
|||
|
||||
use windows::Win32::System::ProcessStatus::{GetPerformanceInfo, PERFORMANCE_INFORMATION};
|
||||
|
||||
use crate::data_harvester::memory::MemHarvest;
|
||||
use crate::data_collection::memory::MemHarvest;
|
||||
|
||||
// TODO: Note this actually calculates the total *committed* usage. Rename and change label for accuracy!
|
||||
/// Get the committed memory usage.
|
|
@ -3,7 +3,7 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use super::NetworkHarvest;
|
||||
use crate::app::Filter;
|
||||
use crate::app::filter::Filter;
|
||||
|
||||
// TODO: Eventually make it so that this thing also takes individual usage into account, so we can show per-interface!
|
||||
pub fn get_network_data(
|
|
@ -5,11 +5,11 @@ use nvml_wrapper::enum_wrappers::device::TemperatureSensor;
|
|||
use nvml_wrapper::enums::device::UsedGpuMemory;
|
||||
use nvml_wrapper::{error::NvmlError, Nvml};
|
||||
|
||||
use crate::app::Filter;
|
||||
use crate::app::filter::Filter;
|
||||
|
||||
use crate::app::layout_manager::UsedWidgets;
|
||||
use crate::data_harvester::memory::MemHarvest;
|
||||
use crate::data_harvester::temperature::{is_temp_filtered, TempHarvest, TemperatureType};
|
||||
use crate::data_collection::memory::MemHarvest;
|
||||
use crate::data_collection::temperature::{is_temp_filtered, TempHarvest, TemperatureType};
|
||||
|
||||
pub static NVML_DATA: OnceLock<Result<Nvml, NvmlError>> = OnceLock::new();
|
||||
|
|
@ -6,7 +6,7 @@ use std::process::Command;
|
|||
use hashbrown::HashMap;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::data_harvester::{deserialize_xo, processes::UnixProcessExt};
|
||||
use crate::data_collection::{deserialize_xo, processes::UnixProcessExt};
|
||||
use crate::Pid;
|
||||
|
||||
#[derive(Deserialize, Debug, Default)]
|
|
@ -11,7 +11,7 @@ use hashbrown::HashSet;
|
|||
use sysinfo::ProcessStatus;
|
||||
|
||||
use super::{ProcessHarvest, UserTable};
|
||||
use crate::app::data_harvester::DataCollector;
|
||||
use crate::data_collection::DataCollector;
|
||||
use crate::utils::error::{self, BottomError};
|
||||
use crate::Pid;
|
||||
|
|
@ -11,7 +11,7 @@ cfg_if! {
|
|||
|
||||
use super::ProcessHarvest;
|
||||
|
||||
use crate::app::data_harvester::{DataCollector, processes::*};
|
||||
use crate::data_collection::{DataCollector, processes::*};
|
||||
use crate::utils::error;
|
||||
|
||||
pub fn sysinfo_process_data(collector: &mut DataCollector) -> error::Result<Vec<ProcessHarvest>> {
|
|
@ -7,7 +7,7 @@ use hashbrown::HashMap;
|
|||
use sysinfo::{CpuExt, PidExt, ProcessExt, ProcessStatus, System, SystemExt};
|
||||
|
||||
use super::ProcessHarvest;
|
||||
use crate::{data_harvester::processes::UserTable, utils::error, Pid};
|
||||
use crate::{data_collection::processes::UserTable, utils::error, Pid};
|
||||
|
||||
pub(crate) trait UnixProcessExt {
|
||||
fn sysinfo_process_data(
|
|
@ -6,7 +6,7 @@ use sysinfo::{CpuExt, PidExt, ProcessExt, SystemExt, UserExt};
|
|||
|
||||
use super::ProcessHarvest;
|
||||
|
||||
use crate::data_harvester::DataCollector;
|
||||
use crate::data_collection::DataCollector;
|
||||
|
||||
pub fn sysinfo_process_data(
|
||||
collector: &mut DataCollector,
|
|
@ -13,7 +13,7 @@ cfg_if::cfg_if! {
|
|||
}
|
||||
}
|
||||
|
||||
use crate::app::Filter;
|
||||
use crate::app::filter::Filter;
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct TempHarvest {
|
||||
|
@ -65,7 +65,7 @@ pub fn is_temp_filtered(filter: &Option<Filter>, text: &str) -> bool {
|
|||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::app::data_harvester::temperature::TemperatureType;
|
||||
use crate::data_collection::temperature::TemperatureType;
|
||||
|
||||
#[test]
|
||||
fn temp_conversions() {
|
|
@ -9,7 +9,7 @@ use anyhow::Result;
|
|||
use hashbrown::{HashMap, HashSet};
|
||||
|
||||
use super::{is_temp_filtered, TempHarvest, TemperatureType};
|
||||
use crate::{app::Filter, utils::error::BottomError};
|
||||
use crate::{app::filter::Filter, utils::error::BottomError};
|
||||
|
||||
const EMPTY_NAME: &str = "Unknown";
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
use anyhow::Result;
|
||||
|
||||
use super::{is_temp_filtered, TempHarvest, TemperatureType};
|
||||
use crate::app::Filter;
|
||||
use crate::app::filter::Filter;
|
||||
|
||||
pub fn get_temperature_data(
|
||||
sys: &sysinfo::System, temp_type: &TemperatureType, filter: &Option<Filter>,
|
|
@ -3,13 +3,9 @@
|
|||
|
||||
use kstring::KString;
|
||||
|
||||
use crate::app::data_harvester::memory::MemHarvest;
|
||||
use crate::app::{
|
||||
data_farmer::DataCollection,
|
||||
data_harvester::{cpu::CpuDataType, temperature::TemperatureType},
|
||||
AxisScaling,
|
||||
};
|
||||
use crate::app::{data_farmer::DataCollection, AxisScaling};
|
||||
use crate::components::tui_widget::time_chart::Point;
|
||||
use crate::data_collection::{cpu::CpuDataType, memory::MemHarvest, temperature::TemperatureType};
|
||||
use crate::utils::data_prefixes::*;
|
||||
use crate::utils::data_units::DataUnit;
|
||||
use crate::utils::gen_util::*;
|
||||
|
|
|
@ -26,7 +26,6 @@ use std::{
|
|||
};
|
||||
|
||||
use app::{
|
||||
data_harvester,
|
||||
frozen_state::FrozenState,
|
||||
layout_manager::{UsedWidgets, WidgetDirection},
|
||||
App, AppConfigFields, DataFilters,
|
||||
|
@ -57,6 +56,7 @@ pub mod args;
|
|||
pub mod canvas;
|
||||
pub mod components;
|
||||
pub mod constants;
|
||||
pub mod data_collection;
|
||||
pub mod data_conversion;
|
||||
pub mod options;
|
||||
pub mod widgets;
|
||||
|
@ -76,7 +76,7 @@ pub enum BottomEvent {
|
|||
KeyInput(KeyEvent),
|
||||
MouseInput(MouseEvent),
|
||||
PasteEvent(String),
|
||||
Update(Box<data_harvester::Data>),
|
||||
Update(Box<data_collection::Data>),
|
||||
Clean,
|
||||
Terminate,
|
||||
}
|
||||
|
@ -485,7 +485,7 @@ pub fn create_collection_thread(
|
|||
let update_time = app_config_fields.update_rate;
|
||||
|
||||
thread::spawn(move || {
|
||||
let mut data_state = data_harvester::DataCollector::new(filters);
|
||||
let mut data_state = data_collection::DataCollector::new(filters);
|
||||
|
||||
data_state.set_data_collection(used_widget_set);
|
||||
data_state.set_temperature_type(temp_type);
|
||||
|
@ -524,7 +524,7 @@ pub fn create_collection_thread(
|
|||
}
|
||||
|
||||
let event = BottomEvent::Update(Box::from(data_state.data));
|
||||
data_state.data = data_harvester::Data::default();
|
||||
data_state.data = data_collection::Data::default();
|
||||
if sender.send(event).is_err() {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ use crate::{
|
|||
app::{filter::Filter, layout_manager::*, *},
|
||||
canvas::{canvas_styling::CanvasStyling, ColourScheme},
|
||||
constants::*,
|
||||
data_collection::temperature::TemperatureType,
|
||||
utils::{
|
||||
data_units::DataUnit,
|
||||
error::{self, BottomError},
|
||||
|
@ -581,29 +582,27 @@ fn get_update_rate(matches: &ArgMatches, config: &Config) -> error::Result<u64>
|
|||
Ok(update_rate)
|
||||
}
|
||||
|
||||
fn get_temperature(
|
||||
matches: &ArgMatches, config: &Config,
|
||||
) -> error::Result<data_harvester::temperature::TemperatureType> {
|
||||
fn get_temperature(matches: &ArgMatches, config: &Config) -> error::Result<TemperatureType> {
|
||||
if matches.get_flag("fahrenheit") {
|
||||
return Ok(data_harvester::temperature::TemperatureType::Fahrenheit);
|
||||
return Ok(TemperatureType::Fahrenheit);
|
||||
} else if matches.get_flag("kelvin") {
|
||||
return Ok(data_harvester::temperature::TemperatureType::Kelvin);
|
||||
return Ok(TemperatureType::Kelvin);
|
||||
} else if matches.get_flag("celsius") {
|
||||
return Ok(data_harvester::temperature::TemperatureType::Celsius);
|
||||
return Ok(TemperatureType::Celsius);
|
||||
} else if let Some(flags) = &config.flags {
|
||||
if let Some(temp_type) = &flags.temperature_type {
|
||||
// Give lowest priority to config.
|
||||
return match temp_type.as_str() {
|
||||
"fahrenheit" | "f" => Ok(data_harvester::temperature::TemperatureType::Fahrenheit),
|
||||
"kelvin" | "k" => Ok(data_harvester::temperature::TemperatureType::Kelvin),
|
||||
"celsius" | "c" => Ok(data_harvester::temperature::TemperatureType::Celsius),
|
||||
"fahrenheit" | "f" => Ok(TemperatureType::Fahrenheit),
|
||||
"kelvin" | "k" => Ok(TemperatureType::Kelvin),
|
||||
"celsius" | "c" => Ok(TemperatureType::Celsius),
|
||||
_ => Err(BottomError::ConfigError(format!(
|
||||
"\"{temp_type}\" is an invalid temperature type, use \"<kelvin|k|celsius|c|fahrenheit|f>\"."
|
||||
))),
|
||||
};
|
||||
}
|
||||
}
|
||||
Ok(data_harvester::temperature::TemperatureType::Celsius)
|
||||
Ok(TemperatureType::Celsius)
|
||||
}
|
||||
|
||||
/// Yes, this function gets whether to show average CPU (true) or not (false)
|
||||
|
|
|
@ -4,12 +4,13 @@ use concat_string::concat_string;
|
|||
use tui::{style::Style, text::Text, widgets::Row};
|
||||
|
||||
use crate::{
|
||||
app::{data_harvester::cpu::CpuDataType, AppConfigFields},
|
||||
app::AppConfigFields,
|
||||
canvas::{canvas_styling::CanvasStyling, Painter},
|
||||
components::data_table::{
|
||||
Column, ColumnHeader, DataTable, DataTableColumn, DataTableProps, DataTableStyling,
|
||||
DataToCell,
|
||||
},
|
||||
data_collection::cpu::CpuDataType,
|
||||
data_conversion::CpuWidgetData,
|
||||
options::CpuDefault,
|
||||
utils::gen_util::truncate_to_text,
|
||||
|
|
|
@ -8,7 +8,6 @@ use serde::{de::Error, Deserialize};
|
|||
use crate::{
|
||||
app::{
|
||||
data_farmer::{DataCollection, ProcessData},
|
||||
data_harvester::processes::ProcessHarvest,
|
||||
query::*,
|
||||
AppConfigFields, AppSearchState,
|
||||
},
|
||||
|
@ -17,6 +16,7 @@ use crate::{
|
|||
Column, ColumnHeader, ColumnWidthBounds, DataTable, DataTableColumn, DataTableProps,
|
||||
DataTableStyling, SortColumn, SortDataTable, SortDataTableProps, SortOrder, SortsRow,
|
||||
},
|
||||
data_collection::processes::ProcessHarvest,
|
||||
Pid,
|
||||
};
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ use tui::{text::Text, widgets::Row};
|
|||
|
||||
use super::proc_widget_column::ProcColumn;
|
||||
use crate::{
|
||||
app::data_harvester::processes::ProcessHarvest,
|
||||
canvas::Painter,
|
||||
components::data_table::{DataTableColumn, DataToCell},
|
||||
data_collection::processes::ProcessHarvest,
|
||||
data_conversion::{binary_byte_string, dec_bytes_per_second_string, dec_bytes_string},
|
||||
utils::gen_util::truncate_to_text,
|
||||
Pid,
|
||||
|
|
|
@ -5,12 +5,13 @@ use kstring::KString;
|
|||
use tui::text::Text;
|
||||
|
||||
use crate::{
|
||||
app::{data_harvester::temperature::TemperatureType, AppConfigFields},
|
||||
app::AppConfigFields,
|
||||
canvas::canvas_styling::CanvasStyling,
|
||||
components::data_table::{
|
||||
ColumnHeader, DataTableColumn, DataTableProps, DataTableStyling, DataToCell, SortColumn,
|
||||
SortDataTable, SortDataTableProps, SortOrder, SortsRow,
|
||||
},
|
||||
data_collection::temperature::TemperatureType,
|
||||
utils::gen_util::{sort_partial_fn, truncate_to_text},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue