Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate disk collection code off of heim, remove heim #1064

Merged
merged 39 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
acd79e5
refactor: fix some refresh code
ClementTsang Mar 9, 2023
e58746d
remove async from the freebsd code
ClementTsang Mar 11, 2023
7754d02
some file/implementation organization
ClementTsang Mar 14, 2023
577bf72
more restructuring
ClementTsang Mar 16, 2023
5e1592c
Some other fixes
ClementTsang Mar 19, 2023
b2594ce
remove futures
ClementTsang Mar 19, 2023
48158e7
ready for some big changes?
ClementTsang Mar 23, 2023
4d5f250
big changes
ClementTsang Mar 26, 2023
69675dc
linux io + reads
ClementTsang Apr 1, 2023
ecf0ac2
use lossy conversion for mount point
ClementTsang Apr 1, 2023
8724780
add windows refresh
ClementTsang Apr 1, 2023
794eda3
so long heim, and thanks for all the fish
ClementTsang Apr 1, 2023
c53a32e
fix filter behaviour, remove string allocation when reading lines
ClementTsang Apr 3, 2023
042c530
rename unix -> system for more accurate file struct representation
ClementTsang Apr 4, 2023
7e0a2be
fix freebsd
ClementTsang Apr 4, 2023
37f4fd7
port generic unix partition code
ClementTsang Apr 5, 2023
b10d124
add bindings and fix errors
ClementTsang Apr 5, 2023
ad1d8f9
finish macOS bindings for I/O
ClementTsang Apr 5, 2023
9c8df52
disable conform check, this seems to... make disk I/O work on macOS?????
ClementTsang Apr 5, 2023
c027da9
fix linux
ClementTsang Apr 5, 2023
32e38ae
add safety comments
ClementTsang Apr 5, 2023
2628254
more comments
ClementTsang Apr 5, 2023
72485bc
update changelog
ClementTsang Apr 5, 2023
6d6bec0
changelog
ClementTsang Apr 5, 2023
096190d
We're going full 0.9.0 for this
ClementTsang Apr 5, 2023
e92cba7
update lock
ClementTsang Apr 5, 2023
c396659
fix some typing
ClementTsang Apr 6, 2023
eff2f16
bleh
ClementTsang Apr 6, 2023
461cde4
some file management
ClementTsang Apr 6, 2023
7f0c669
hoist out get_disk_usage
ClementTsang Apr 6, 2023
12559df
fix some stuff for Windows
ClementTsang Apr 6, 2023
30ea987
typing and remove dead code allow lint
ClementTsang Apr 6, 2023
0f4287b
unify typing
ClementTsang Apr 6, 2023
661c578
fix
ClementTsang Apr 6, 2023
111133c
fix 2
ClementTsang Apr 6, 2023
a30aac1
macOS fix
ClementTsang Apr 7, 2023
4d22589
Add bindings file for windows
ClementTsang Apr 9, 2023
0765343
add windows implementation
ClementTsang Apr 10, 2023
e5d241a
fix macos
ClementTsang Apr 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
big changes
  • Loading branch information
ClementTsang committed Apr 9, 2023
commit 4d5f25027984c6f7548ad12cf23567a1800270ab
6 changes: 3 additions & 3 deletions src/app/data_harvester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ impl DataCollector {
if self.widgets_to_harvest.use_disk {
#[cfg(any(target_os = "freebsd", target_os = "linux", target_os = "macos"))]
{
self.data.disks =
disks::get_disk_usage(&self.filters.disk_filter, &self.filters.mount_filter)
.ok();
let disk_filter = &self.filters.disk_filter;
let mount_filter = &self.filters.mount_filter;
self.data.disks = disks::get_disk_usage(disk_filter, mount_filter).ok();
}

#[cfg(target_os = "windows")]
Expand Down
15 changes: 6 additions & 9 deletions src/app/data_harvester/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

use std::collections::HashMap;

cfg_if::cfg_if! {
if #[cfg(target_family = "unix")]
{
pub mod unix;
pub use self::unix::*;
}
}

cfg_if::cfg_if! {
if #[cfg(target_os = "freebsd")] {
pub mod freebsd;
Expand All @@ -18,8 +10,13 @@ cfg_if::cfg_if! {
pub mod windows;
pub use self::windows::*;
} else if #[cfg(target_os = "linux")] {
pub(crate) mod linux;
pub mod unix;
pub use self::unix::*;
} else if #[cfg(target_os = "macos")] {
pub mod unix;
pub use self::unix::*;
}
// TODO: Add dummy impls here for other OSes?
}

#[derive(Debug, Clone, Default)]
Expand Down
139 changes: 0 additions & 139 deletions src/app/data_harvester/disks/heim.rs

This file was deleted.

130 changes: 105 additions & 25 deletions src/app/data_harvester/disks/unix.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,121 @@
//! Implementation based on [heim's](https://github.com/heim-rs/heim)
//! Unix disk usage.
//! Disk stats for Unix-like systems that aren't supported through other means.

use std::path::Path;
use crate::app::Filter;
use crate::data_harvester::disks::{DiskHarvest, IoData, IoHarvest};

use crate::app::{
data_harvester::disks::{DiskHarvest, IoHarvest},
filter::Filter,
};
pub fn get_io_usage() -> anyhow::Result<IoHarvest> {
// if !actually_get {
// return Ok(None);
// }

mod file_systems;
pub(crate) use file_systems::FileSystem;
// let mut io_hash: std::collections::HashMap<String, Option<IoData>> =
// std::collections::HashMap::new();

cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
use super::linux::partitions;
} else {
mod partition;
mod mounts;
// let counter_stream = heim::disk::io_counters().await?;

use partition::*;
}
}
// while let Some(io) = counter_stream.next().await {
// if let Ok(io) = io {
// let mount_point = io.device_name().to_str().unwrap_or("Mount Unavailable");

// io_hash.insert(
// mount_point.to_string(),
// Some(IoData {
// read_bytes: io.read_bytes().get::<heim::units::information::byte>(),
// write_bytes: io.write_bytes().get::<heim::units::information::byte>(),
// }),
// );
// }
// }

pub(crate) struct Usage {}
// Ok(Some(io_hash))

fn disk_usage(path: &Path) -> anyhow::Result<Usage> {
todo!()
}

pub fn get_disk_usage(
disk_filter: &Option<Filter>, mount_filter: &Option<Filter>,
) -> anyhow::Result<Vec<DiskHarvest>> {
let partitions = partitions()?;
todo!()
// let mut vec_disks: Vec<DiskHarvest> = Vec::new();
// let partitions_stream = heim::disk::partitions_physical().await?;

Ok(vec![])
}
// while let Some(part) = partitions_stream.next().await {
// if let Ok(partition) = part {
// let name = get_device_name(&partition);

pub fn get_io_usage() -> anyhow::Result<IoHarvest> {
Ok(IoHarvest::default())
// let mount_point = (partition
// .mount_point()
// .to_str()
// .unwrap_or("Name unavailable"))
// .to_string();

// // Precedence ordering in the case where name and mount filters disagree, "allow" takes precedence over "deny".
// //
// // For implementation, we do this as follows:
// // 1. Is the entry allowed through any filter? That is, does it match an entry in a filter where `is_list_ignored` is `false`? If so, we always keep this entry.
// // 2. Is the entry denied through any filter? That is, does it match an entry in a filter where `is_list_ignored` is `true`? If so, we always deny this entry.
// // 3. Anything else is allowed.

// let filter_check_map = [(disk_filter, &name), (mount_filter, &mount_point)];

// // This represents case 1. That is, if there is a match in an allowing list - if there is, then
// // immediately allow it!
// let matches_allow_list = filter_check_map.iter().any(|(filter, text)| {
// if let Some(filter) = filter {
// if !filter.is_list_ignored {
// for r in &filter.list {
// if r.is_match(text) {
// return true;
// }
// }
// }
// }
// false
// });

// let to_keep = if matches_allow_list {
// true
// } else {
// // If it doesn't match an allow list, then check if it is denied.
// // That is, if it matches in a reject filter, then reject. Otherwise, we always keep it.
// !filter_check_map.iter().any(|(filter, text)| {
// if let Some(filter) = filter {
// if filter.is_list_ignored {
// for r in &filter.list {
// if r.is_match(text) {
// return true;
// }
// }
// }
// }
// false
// })
// };

// if to_keep {
// // The usage line can fail in some cases (for example, if you use Void Linux + LUKS,
// // see https://github.com/ClementTsang/bottom/issues/419 for details). As such, check
// // it like this instead.
// if let Ok(usage) = heim::disk::usage(partition.mount_point()).await {
// vec_disks.push(DiskHarvest {
// free_space: Some(usage.free().get::<heim::units::information::byte>()),
// used_space: Some(usage.used().get::<heim::units::information::byte>()),
// total_space: Some(usage.total().get::<heim::units::information::byte>()),
// mount_point,
// name,
// });
// } else {
// vec_disks.push(DiskHarvest {
// free_space: None,
// used_space: None,
// total_space: None,
// mount_point,
// name,
// });
// }
// }
// }
// }

// Ok(Some(vec_disks))
}
41 changes: 41 additions & 0 deletions src/app/data_harvester/disks/unix/other.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Implementation based on [heim's](https://github.com/heim-rs/heim)
//! Unix disk usage.

use std::path::Path;

use crate::app::{
data_harvester::disks::{DiskHarvest, IoHarvest},
filter::Filter,
};

mod file_systems;
pub(crate) use file_systems::FileSystem;

cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
use super::linux::partitions;
} else {
mod partition;
mod mounts;

use partition::*;
}
}

pub(crate) struct Usage {}

fn disk_usage(path: &Path) -> anyhow::Result<Usage> {
todo!()
}

pub fn get_disk_usage(
disk_filter: &Option<Filter>, mount_filter: &Option<Filter>,
) -> anyhow::Result<Vec<DiskHarvest>> {
let partitions = partitions()?;

Ok(vec![])
}

pub fn get_io_usage() -> anyhow::Result<IoHarvest> {
Ok(IoHarvest::default())
}