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
disable conform check, this seems to... make disk I/O work on macOS?????
  • Loading branch information
ClementTsang committed Apr 9, 2023
commit 9c8df5278c6e2973021ee688a3988ee4464bb567
54 changes: 35 additions & 19 deletions src/app/data_harvester/disks/system/macos/io_counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

use std::ffi::OsStr;

use anyhow::bail;

use super::io_kit::{self, get_dict, get_disks, get_i64, get_string};

#[derive(Debug, Default)]
Expand All @@ -30,27 +28,45 @@ impl IoCounters {
fn get_device_io(device: io_kit::IoObject) -> anyhow::Result<IoCounters> {
let parent = device.service_parent()?;

if parent.conforms_to_block_storage_driver() {
let disk_props = device.properties()?;
let parent_props = parent.properties()?;
// XXX: Re: Conform check being disabled.
//
// Okay, so this is weird.
//
// The problem is that if I have this check - this is what sources like psutil use, for
// example (see https://github.com/giampaolo/psutil/blob/7eadee31db2f038763a3a6f978db1ea76bbc4674/psutil/_psutil_osx.c#LL1422C20-L1422C20)
// then this will only return stuff like disk0.
//
// The problem with this is that there is *never* a disk0 *disk* entry to correspond to this,
// so there will be entries like disk1 or whatnot. Someone's done some digging on the gopsutil
// repo (https://github.com/shirou/gopsutil/issues/855#issuecomment-610016435), and it seems
// like this is a consequence of how Apple does logical volumes.
//
// So with all that said, what I've found is that I *can* still get a mapping - but I have
// to disable the conform check, which... is weird. I'm not sure if this is valid at all. But
// it *does* seem to match Activity Monitor with regards to disk activity, so... I guess we
// can leave this for now...?

let name = get_string(&disk_props, "BSD Name")?;
let stats = get_dict(&parent_props, "Statistics")?;
// if !parent.conforms_to_block_storage_driver() {
// anyhow::bail!("{parent:?}, the parent of {device:?} does not conform to IOBlockStorageDriver")
// }

let read_bytes = get_i64(&stats, "Bytes (Read)")? as u64;
let write_bytes = get_i64(&stats, "Bytes (Write)")? as u64;
let disk_props = device.properties()?;
let parent_props = parent.properties()?;

// let read_count = stats.get_i64("Operations (Read)")? as u64;
// let write_count = stats.get_i64("Operations (Write)")? as u64;
let name = get_string(&disk_props, "BSD Name")?;
let stats = get_dict(&parent_props, "Statistics")?;

Ok(IoCounters {
name,
read_bytes,
write_bytes,
})
} else {
bail!("{parent:?}, the parent of {device:?} does not conform to IOBlockStorageDriver")
}
let read_bytes = get_i64(&stats, "Bytes (Read)")? as u64;
let write_bytes = get_i64(&stats, "Bytes (Write)")? as u64;

// let read_count = stats.get_i64("Operations (Read)")? as u64;
// let write_count = stats.get_i64("Operations (Write)")? as u64;

Ok(IoCounters {
name,
read_bytes,
write_bytes,
})
}

/// Returns an iterator of disk I/O stats. Pulls data through IOKit.
Expand Down
4 changes: 2 additions & 2 deletions src/app/data_harvester/disks/system/macos/io_kit/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use core_foundation::base::{mach_port_t, CFAllocatorRef};
use core_foundation::dictionary::CFMutableDictionaryRef;

use libc::c_char;
use mach2::kern_return::kern_return_t;
use mach2::port::MACH_PORT_NULL;
use mach2::{boolean::boolean_t, kern_return::kern_return_t};

#[allow(non_camel_case_types)]
pub type io_object_t = mach_port_t;
Expand Down Expand Up @@ -49,7 +49,7 @@ extern "C" {
entry: io_registry_entry_t, plane: *const libc::c_char, parent: *mut io_registry_entry_t,
) -> kern_return_t;

pub fn IOObjectConformsTo(object: io_object_t, className: *const libc::c_char) -> boolean_t;
// pub fn IOObjectConformsTo(object: io_object_t, className: *const libc::c_char) -> mach2::boolean::boolean_t;

pub fn IORegistryEntryCreateCFProperties(
entry: io_registry_entry_t, properties: *mut CFMutableDictionaryRef,
Expand Down
10 changes: 5 additions & 5 deletions src/app/data_harvester/disks/system/macos/io_kit/io_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ impl IoObject {
}
}

pub fn conforms_to_block_storage_driver(&self) -> bool {
let result =
unsafe { IOObjectConformsTo(self.0, "IOBlockStorageDriver\0".as_ptr().cast()) };
// pub fn conforms_to_block_storage_driver(&self) -> bool {
// let result =
// unsafe { IOObjectConformsTo(self.0, "IOBlockStorageDriver\0".as_ptr().cast()) };

result != 0
}
// result != 0
// }
}

impl From<io_object_t> for IoObject {
Expand Down