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
hoist out get_disk_usage
  • Loading branch information
ClementTsang committed Apr 9, 2023
commit 7f0c6697afe4b70b71d3c2bbea53a64111a09239
30 changes: 23 additions & 7 deletions src/app/data_harvester/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ cfg_if::cfg_if! {
} else if #[cfg(target_os = "windows")] {
mod windows;
pub use self::windows::*;

mod system;
pub use self::system::get_io_usage;
} else if #[cfg(target_os = "linux")] {
mod system;
pub use self::system::*;
mod unix;
pub use self::unix::*;
} else if #[cfg(target_os = "macos")] {
mod system;
pub use self::system::*;
mod unix;
pub use self::unix::*;
}
// TODO: Add dummy impls here for other OSes?
}
Expand All @@ -43,6 +40,25 @@ pub struct IoData {

pub type IoHarvest = HashMap<String, Option<IoData>>;

/// Returns the I/O usage of certain mount points.
pub fn get_io_usage() -> anyhow::Result<IoHarvest> {
let mut io_hash: HashMap<String, Option<IoData>> = HashMap::new();

for io in io_stats()?.into_iter().flatten() {
let mount_point = io.device_name().to_string_lossy();

io_hash.insert(
mount_point.to_string(),
Some(IoData {
read_bytes: io.read_bytes(),
write_bytes: io.write_bytes(),
}),
);
}

Ok(io_hash)
}

/// Whether to keep the current disk entry given the filters, disk name, and disk mount.
/// Precedence ordering in the case where name and mount filters disagree, "allow"
/// takes precedence over "deny".
Expand Down
4 changes: 0 additions & 4 deletions src/app/data_harvester/disks/system/macos/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Disk stats for Unix-like systems that aren't supported through other means.

mod file_systems;
use std::collections::HashMap;

use file_systems::*;

Expand All @@ -11,44 +10,22 @@ use usage::*;
cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
mod linux;
use linux::*;
pub use linux::*;
} else if #[cfg(target_os = "macos")] {
mod unix;
use unix::*;
mod other;
use other::*;

mod macos;
use macos::*;
} else if #[cfg(target_os = "windows")] {
mod windows;
use windows::*;
pub use macos::*;
} else {
mod unix;
use unix::*;
mod other;
use other::*;
}
}

use super::{keep_disk_entry, DiskHarvest, IoData, IoHarvest};
use super::{keep_disk_entry, DiskHarvest};
use crate::app::Filter;

/// Returns the I/O usage of certain mount points.
pub fn get_io_usage() -> anyhow::Result<IoHarvest> {
let mut io_hash: HashMap<String, Option<IoData>> = HashMap::new();

for io in io_stats()?.into_iter().flatten() {
let mount_point = io.device_name().to_string_lossy();

io_hash.insert(
mount_point.to_string(),
Some(IoData {
read_bytes: io.read_bytes(),
write_bytes: io.write_bytes(),
}),
);
}

Ok(io_hash)
}

/// Returns the disk usage of the mounted (and for now, physical) disks.
pub fn get_disk_usage(
disk_filter: &Option<Filter>, mount_filter: &Option<Filter>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ mod partition;
pub(crate) use partition::*;

mod io_counters;
pub(crate) use io_counters::*;
pub use io_counters::*;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{

use anyhow::bail;

use crate::app::data_harvester::disks::system::{FileSystem, Usage};
use crate::app::data_harvester::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
4 changes: 4 additions & 0 deletions src/app/data_harvester/disks/unix/macos/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod io_counters;
pub use io_counters::*;

mod io_kit;