Skip to content

Commit

Permalink
refactor: rename data_collection to collection
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed Jan 20, 2025
1 parent 408e81c commit a41142a
Show file tree
Hide file tree
Showing 68 changed files with 59 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use unicode_segmentation::{GraphemeCursor, UnicodeSegmentation};

use crate::{
canvas::components::time_chart::LegendPosition,
collection::{processes::Pid, temperature},
constants,
data_collection::{processes::Pid, temperature},
utils::data_units::DataUnit,
widgets::{ProcWidgetColumn, ProcWidgetMode},
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/data/process.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::BTreeMap, vec::Vec};

use crate::data_collection::processes::{Pid, ProcessHarvest};
use crate::collection::processes::{Pid, ProcessHarvest};
use hashbrown::HashMap;

#[derive(Clone, Debug, Default)]
Expand Down
4 changes: 2 additions & 2 deletions src/app/data/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::{
};

#[cfg(feature = "battery")]
use crate::data_collection::batteries;
use crate::collection::batteries;
use crate::{
data_collection::{cpu, disks, memory::MemHarvest, network, Data},
collection::{cpu, disks, memory::MemHarvest, network, Data},
dec_bytes_per_second_string,
widgets::TempWidgetData,
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/data/time_series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
use hashbrown::{HashMap, HashSet}; // TODO: Try fxhash again.
use timeless::data::ChunkedData;

use crate::data_collection::Data;
use crate::collection::Data;

/// Values corresponding to a time slice.
pub type Values = ChunkedData<f64>;
Expand Down
2 changes: 1 addition & 1 deletion src/app/process_killer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use windows::Win32::{
},
};

use crate::data_collection::processes::Pid;
use crate::collection::processes::Pid;

/// Based from [this SO answer](https://stackoverflow.com/a/55231715).
#[cfg(target_os = "windows")]
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/widgets/battery_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use unicode_width::UnicodeWidthStr;
use crate::{
app::App,
canvas::{drawing_utils::widget_block, Painter},
collection::batteries::BatteryState,
constants::*,
data_collection::batteries::BatteryState,
};

/// Calculate how many bars are to be drawn within basic mode's components.
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/widgets/cpu_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
drawing_utils::widget_block,
Painter,
},
data_collection::cpu::{CpuData, CpuDataType},
collection::cpu::{CpuData, CpuDataType},
};

impl Painter {
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/widgets/cpu_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
drawing_utils::should_hide_x_label,
Painter,
},
data_collection::cpu::CpuData,
collection::cpu::CpuData,
to_points,
widgets::CpuWidgetState,
};
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/widgets/mem_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tui::{
use crate::{
app::App,
canvas::{components::pipe_gauge::PipeGauge, drawing_utils::widget_block, Painter},
data_collection::memory::MemHarvest,
collection::memory::MemHarvest,
get_binary_unit_and_denominator,
};

Expand Down
2 changes: 1 addition & 1 deletion src/canvas/widgets/mem_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
drawing_utils::should_hide_x_label,
Painter,
},
data_collection::memory::MemHarvest,
collection::memory::MemHarvest,
get_binary_unit_and_denominator, to_points,
};

Expand Down
4 changes: 2 additions & 2 deletions src/data_collection.rs → src/collection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This is the main file to house data collection functions.
//!
//! TODO: Rename this to intake?
//! TODO: Rename this to intake? Collection?
#[cfg(feature = "nvidia")]
pub mod nvidia;
Expand Down Expand Up @@ -238,7 +238,7 @@ impl DataCollector {
self.data.cleanup();
}

pub fn set_data_collection(&mut self, used_widgets: UsedWidgets) {
pub fn set_collection(&mut self, used_widgets: UsedWidgets) {
self.widgets_to_harvest = used_widgets;
}

Expand Down
2 changes: 1 addition & 1 deletion src/data_collection/amd.rs → src/collection/amd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod amdgpu_marketing;

use crate::{
app::{filter::Filter, layout_manager::UsedWidgets},
data_collection::{
collection::{
memory::MemHarvest,
temperature::{TempHarvest, TemperatureType},
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::collections::VecDeque;
use sysinfo::System;

use super::{CpuData, CpuDataType, CpuHarvest};
use crate::data_collection::error::CollectionResult;
use crate::collection::error::CollectionResult;

pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CollectionResult<CpuHarvest> {
let mut cpu_deque: VecDeque<_> = sys
Expand All @@ -32,7 +32,7 @@ pub fn get_cpu_data_list(sys: &System, show_average_cpu: bool) -> CollectionResu
}

#[cfg(target_family = "unix")]
pub(crate) fn get_load_avg() -> crate::data_collection::cpu::LoadAvgHarvest {
pub(crate) fn get_load_avg() -> crate::collection::cpu::LoadAvgHarvest {
// The API for sysinfo apparently wants you to call it like this, rather than
// using a &System.
let sysinfo::LoadAvg { one, five, fifteen } = sysinfo::System::load_average();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use hashbrown::HashMap;
use serde::Deserialize;

use super::{keep_disk_entry, DiskHarvest, IoHarvest};
use crate::data_collection::{
deserialize_xo, disks::IoData, error::CollectionResult, DataCollector,
};
use crate::collection::{deserialize_xo, disks::IoData, error::CollectionResult, DataCollector};

#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -40,7 +38,7 @@ pub fn get_io_usage() -> CollectionResult<IoHarvest> {

#[cfg(feature = "zfs")]
{
use crate::data_collection::disks::zfs_io_counters;
use crate::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();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Fallback disk info using sysinfo.
use super::{keep_disk_entry, DiskHarvest};
use crate::data_collection::DataCollector;
use crate::collection::DataCollector;

pub(crate) fn get_disk_usage(collector: &DataCollector) -> anyhow::Result<Vec<DiskHarvest>> {
let disks = &collector.sys.disks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use file_systems::*;
use usage::*;

use super::{keep_disk_entry, DiskHarvest};
use crate::data_collection::DataCollector;
use crate::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>> {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
str::FromStr,
};

use crate::data_collection::disks::IoCounters;
use crate::collection::disks::IoCounters;

/// Copied from the `psutil` sources:
///
Expand Down Expand Up @@ -87,7 +87,7 @@ pub fn io_stats() -> anyhow::Result<Vec<IoCounters>> {

#[cfg(feature = "zfs")]
{
use crate::data_collection::disks::zfs_io_counters;
use crate::collection::disks::zfs_io_counters;
if let Ok(mut zfs_io) = zfs_io_counters::zfs_io_stats() {
results.append(&mut zfs_io);
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{

use anyhow::bail;

use crate::data_collection::disks::unix::{FileSystem, Usage};
use crate::collection::disks::unix::{FileSystem, Usage};

/// Representation of partition details. Based on [`heim`](https://github.com/heim-rs/heim/tree/master).
pub(crate) struct Partition {
Expand Down
Original file line number Diff line number Diff line change
@@ -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::data_collection::disks::IoCounters;
use crate::collection::disks::IoCounters;

fn get_device_io(device: io_kit::IoObject) -> anyhow::Result<IoCounters> {
let parent = device.service_parent()?;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use anyhow::bail;

use super::bindings;
use crate::data_collection::disks::unix::{FileSystem, Usage};
use crate::collection::disks::unix::{FileSystem, Usage};

pub(crate) struct Partition {
device: String,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bindings::*;
use itertools::Itertools;

use super::{keep_disk_entry, DiskHarvest};
use crate::data_collection::{disks::IoCounters, DataCollector};
use crate::collection::{disks::IoCounters, DataCollector};

/// Returns I/O stats.
pub(crate) fn io_stats() -> anyhow::Result<Vec<IoCounters>> {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::data_collection::disks::IoCounters;
use crate::collection::disks::IoCounters;

/// Returns zpool I/O stats. Pulls data from `sysctl
/// kstat.zfs.{POOL}.dataset.{objset-*}`
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use sysinfo::System;

use crate::data_collection::memory::MemHarvest;
use crate::collection::memory::MemHarvest;

/// Returns RAM usage.
pub(crate) fn get_ram_usage(sys: &System) -> Option<MemHarvest> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::mem::{size_of, zeroed};

use windows::Win32::System::ProcessStatus::{GetPerformanceInfo, PERFORMANCE_INFORMATION};

use crate::data_collection::memory::MemHarvest;
use crate::collection::memory::MemHarvest;

const PERFORMANCE_INFORMATION_SIZE: u32 = size_of::<PERFORMANCE_INFORMATION>() as _;

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/data_collection/nvidia.rs → src/collection/nvidia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use nvml_wrapper::{

use crate::{
app::{filter::Filter, layout_manager::UsedWidgets},
data_collection::{
collection::{
memory::MemHarvest,
temperature::{TempHarvest, TemperatureType},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl DataCollector {
} else if #[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "windows", target_os = "android", target_os = "ios"))] {
sysinfo_process_data(self)
} else {
Err(crate::data_collection::error::CollectionError::Unsupported)
Err(crate::collection::error::CollectionError::Unsupported)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{io, process::Command};
use hashbrown::HashMap;
use serde::{Deserialize, Deserializer};

use crate::data_collection::{deserialize_xo, processes::UnixProcessExt, Pid};
use crate::collection::{deserialize_xo, processes::UnixProcessExt, Pid};

#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "kebab-case")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use process::*;
use sysinfo::ProcessStatus;

use super::{Pid, ProcessHarvest, UserTable};
use crate::data_collection::{error::CollectionResult, DataCollector};
use crate::collection::{error::CollectionResult, DataCollector};

/// Maximum character length of a `/proc/<PID>/stat`` process name.
/// If it's equal or greater, then we instead refer to the command for the name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustix::{
path::Arg,
};

use crate::data_collection::processes::Pid;
use crate::collection::processes::Pid;

static PAGESIZE: OnceLock<u64> = OnceLock::new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use hashbrown::HashMap;
use itertools::Itertools;

use super::UnixProcessExt;
use crate::data_collection::Pid;
use crate::collection::Pid;

pub(crate) struct MacOSProcessExt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use libc::{
};
use mach2::vm_types::user_addr_t;

use crate::data_collection::Pid;
use crate::collection::Pid;

#[repr(C)]
pub(crate) struct kinfo_proc {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ cfg_if! {

use super::ProcessHarvest;

use crate::data_collection::{DataCollector, processes::*};
use crate::data_collection::error::CollectionResult;
use crate::collection::{DataCollector, processes::*};
use crate::collection::error::CollectionResult;

pub fn sysinfo_process_data(collector: &mut DataCollector) -> CollectionResult<Vec<ProcessHarvest>> {
let sys = &collector.sys.system;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hashbrown::HashMap;
use sysinfo::{ProcessStatus, System};

use super::ProcessHarvest;
use crate::data_collection::{error::CollectionResult, processes::UserTable, Pid};
use crate::collection::{error::CollectionResult, processes::UserTable, Pid};

pub(crate) trait UnixProcessExt {
fn sysinfo_process_data(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hashbrown::HashMap;

use crate::data_collection::error::{CollectionError, CollectionResult};
use crate::collection::error::{CollectionError, CollectionResult};

#[derive(Debug, Default)]
pub struct UserTable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::time::Duration;

use super::ProcessHarvest;
use crate::data_collection::{error::CollectionResult, DataCollector};
use crate::collection::{error::CollectionResult, DataCollector};

// TODO: There's a lot of shared code with this and the unix impl.
pub fn sysinfo_process_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Display for TypedTemperature {

#[cfg(test)]
mod test {
use crate::data_collection::temperature::{TemperatureType, TypedTemperature};
use crate::collection::temperature::{TemperatureType, TypedTemperature};

#[test]
fn temp_conversions() {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKi

use crate::{
app::{layout_manager::WidgetDirection, App},
data_collection::Data,
collection::Data,
};

/// Events sent to the main thread.
Expand Down
Loading

0 comments on commit a41142a

Please sign in to comment.