Skip to content

Commit

Permalink
upgrade sysinfo and make thread detection work for all Apple M series…
Browse files Browse the repository at this point in the history
… for now.
  • Loading branch information
Byron committed Dec 13, 2022
1 parent bbd3a1c commit bbd5c67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ wild = "2.0.4"
owo-colors = "3.5.0"

[target.'cfg(all(target_os = "macos", target_arch = "aarch64"))'.dependencies]
sysinfo = { version = "0.23.2", default-features = false }
sysinfo = { version = "0.27.0", default-features = false }

[[bin]]
name="dua"
Expand Down
25 changes: 13 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ fn derive_default_threads(threads: usize) -> usize {
/// On everything else, it's usually a good idea to use as many threads as possible for noticeable speedups.
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
fn derive_default_threads(threads: usize) -> usize {
use sysinfo::{ProcessorExt, RefreshKind, SystemExt};
use sysinfo::{CpuExt, CpuRefreshKind};
use sysinfo::{RefreshKind, SystemExt};
if threads == 0 {
sysinfo::System::new_with_specifics(RefreshKind::new().with_cpu())
.processors()
.get(0)
.map_or(0, |p| match p.brand() {
"Apple M1"|"Apple M1 Pro"|"Apple M1 Max"|"Apple M2" => 4,
other => {
eprintln!(
let system = sysinfo::System::new_with_specifics(
RefreshKind::new().with_cpu(CpuRefreshKind::default()),
);
if system.global_cpu_info().brand().starts_with("Apple M") {
4
} else {
eprintln!(
"Couldn't auto-configure correct amount of threads for {}. Create an issue here: https://github.com/byron/dua-cli/issues",
other
system.global_cpu_info().brand()
);
0
}
})
0
}
} else {
threads
}
Expand All @@ -57,6 +57,7 @@ fn main() -> Result<()> {

let opt: options::Args = options::Args::parse_from(wild::args_os());
let threads = derive_default_threads(opt.threads);
dbg!(threads);
let walk_options = dua::WalkOptions {
threads,
byte_format: opt.format.into(),
Expand Down

0 comments on commit bbd5c67

Please sign in to comment.