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
add windows implementation
  • Loading branch information
ClementTsang committed Apr 10, 2023
commit 0765343879de4ee1903abcef30f27d4686b66ea1
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ mach2 = "0.4.1"
[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.48.0", features = [
"Win32_Foundation",
"Win32_Security",
"Win32_Storage_FileSystem",
"Win32_System_IO",
"Win32_System_Ioctl",
"Win32_System_ProcessStatus",
"Win32_System_Threading",
] }
Expand Down
42 changes: 30 additions & 12 deletions src/app/data_farmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
use std::{collections::BTreeMap, time::Instant, vec::Vec};

use fxhash::FxHashMap;
use once_cell::sync::Lazy;
use regex::Regex;

#[cfg(feature = "battery")]
use crate::data_harvester::batteries;
Expand Down Expand Up @@ -317,23 +315,43 @@ impl DataCollection {
&mut self, disks: Vec<disks::DiskHarvest>, io: disks::IoHarvest, harvested_time: Instant,
) {
// TODO: [PO] To implement

let time_since_last_harvest = harvested_time
.duration_since(self.current_instant)
.as_secs_f64();

for (itx, device) in disks.iter().enumerate() {
if let Some(trim) = device.name.split('/').last() {
let io_device = if cfg!(target_os = "macos") {
// Must trim one level further for macOS!
static DISK_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"disk\d+").unwrap());
if let Some(disk_trim) = DISK_REGEX.find(trim) {
io.get(disk_trim.as_str())
let checked_name = {
cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
match &device.volume_name {
Some(volume_name) => Some(volume_name.as_str()),
None => device.name.split('/').last(),
}
} else {
None
device.name.split('/').last()
}
}
};

if let Some(checked_name) = checked_name {
let io_device = {
cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
use once_cell::sync::Lazy;
use regex::Regex;

// Must trim one level further for macOS!
static DISK_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"disk\d+").unwrap());
if let Some(disk_trim) = DISK_REGEX.find(trim) {
io.get(disk_trim.as_str())
} else {
None
}
} else {
io.get(checked_name)
}
}
} else {
io.get(trim)
};

if let Some(io_device) = io_device {
Expand Down
16 changes: 14 additions & 2 deletions src/app/data_harvester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,24 @@ impl DataCollector {
}
}

// Sysinfo-related list refreshing.
if self.widgets_to_harvest.use_net {
self.sys.refresh_networks_list();
}

if self.widgets_to_harvest.use_temp {
self.sys.refresh_components_list();
}

#[cfg(target_os = "windows")]
if self.widgets_to_harvest.use_proc {
self.sys.refresh_users_list();
{
if self.widgets_to_harvest.use_proc {
self.sys.refresh_users_list();
}

if self.widgets_to_harvest.use_disk {
self.sys.refresh_disks_list();
}
}

self.update_data();
Expand Down Expand Up @@ -261,6 +270,9 @@ impl DataCollector {

#[cfg(target_os = "windows")]
if self.widgets_to_harvest.use_disk {
if refresh_start.duration_since(self.last_collection_time) > LIST_REFRESH_TIME {
self.sys.refresh_disks_list();
}
self.sys.refresh_disks();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/app/data_harvester/disks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ pub struct DiskHarvest {
pub name: String,
pub mount_point: String,

/// Windows also contains an additional volume name field.
#[cfg(target_os = "windows")]
pub volume_name: Option<String>,

// TODO: Maybe unify all these?
pub free_space: Option<u64>,
pub used_space: Option<u64>,
Expand Down
6 changes: 3 additions & 3 deletions src/app/data_harvester/disks/unix/linux/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Partition {
if path.is_absolute() {
path.into_os_string()
.into_string()
.unwrap_or_else(|_| "Name unavailable".to_string())
.unwrap_or_else(|_| "Name Unavailable".to_string())
} else {
let mut combined_path = std::path::PathBuf::new();
combined_path.push(device);
Expand All @@ -61,7 +61,7 @@ impl Partition {
canon_path
.into_os_string()
.into_string()
.unwrap_or_else(|_| "Name unavailable".to_string())
.unwrap_or_else(|_| "Name Unavailable".to_string())
} else {
device.to_owned()
}
Expand All @@ -70,7 +70,7 @@ impl Partition {
device.to_owned()
}
} else {
"Name unavailable".to_string()
"Name Unavailable".to_string()
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/app/data_harvester/disks/windows.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Disk stats via sysinfo.

use itertools::Itertools;
use sysinfo::{DiskExt, System, SystemExt};

use super::{keep_disk_entry, DiskHarvest};
Expand All @@ -11,7 +12,18 @@ use bindings::*;

/// Returns I/O stats.
pub(crate) fn io_stats() -> anyhow::Result<Vec<anyhow::Result<IoCounters>>> {
Ok(vec![])
let volume_io = all_volume_io()?;

Ok(volume_io
.into_iter()
.map_ok(|(performance, volume_name)| {
let name = volume_name;
let read_bytes = performance.BytesRead as u64;
let write_bytes = performance.BytesWritten as u64;

IoCounters::new(name, read_bytes, write_bytes)
})
.collect::<Vec<_>>())
}

pub(crate) fn get_disk_usage(
Expand All @@ -25,11 +37,11 @@ pub(crate) fn get_disk_usage(
let name = disk.name();

if name.is_empty() {
"Name unavailable".to_string()
"No Name".to_string()
} else {
name.to_os_string()
.into_string()
.unwrap_or_else(|_| "Name unavailable".to_string())
.unwrap_or_else(|_| "Name Unavailable".to_string())
}
};

Expand All @@ -38,7 +50,9 @@ pub(crate) fn get_disk_usage(
.as_os_str()
.to_os_string()
.into_string()
.unwrap_or_else(|_| "Mount unavailable".to_string());
.unwrap_or_else(|_| "Mount Unavailable".to_string());

let volume_name = volume_name_from_mount(&mount_point).ok();

if keep_disk_entry(&name, &mount_point, disk_filter, mount_filter) {
let free_space = disk.available_space();
Expand All @@ -48,6 +62,7 @@ pub(crate) fn get_disk_usage(
Some(DiskHarvest {
name,
mount_point,
volume_name,
free_space: Some(free_space),
used_space: Some(used_space),
total_space: Some(total_space),
Expand Down
Loading