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

feat: add option for using shorter CPU model name #331

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ pub struct Opt {
#[clap(short = 'K', long = "long-kernel", help = "Lengthens kernel output")]
pub long_kernel: bool,

#[clap(
short = 'G',
long = "shorter-cpu",
help = "Shorten the CPU's model name"
)]
pub shorter_cpu: bool,

#[clap(
short = 'm',
long = "memory-percentage",
Expand Down Expand Up @@ -160,6 +167,10 @@ impl Opt {
self.ascii_artists = true;
}

if args.shorter_cpu {
self.shorter_cpu = args.shorter_cpu;
}

if args.config.is_some() {
self.config = args.config;
}
Expand Down
50 changes: 44 additions & 6 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,41 @@ fn handle_readout_processor(
use crate::format::cpu as format_cpu;
use crate::format::cpu_only as format_cpu_only;

let cpu_model = match general_readout.cpu_model_name() {
Ok(m) => {
if opt.shorter_cpu {
// Observed forms:
// - AMD A6-9220 RADEON R4
// - AMD Radeon R7 200
// - AMD Ryzen 5 PRO 4650U with Radeon Graphics
// - AMD Ryzen 7 5800X 8-Core Processor
// - Apple M1 Pro
// - Common KVM Processor
// - Intel(R) Core(TM) i5-6200 CPU @ 2.30GHz
// - Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
// - Intel(R) Xeon(R) CPU E5-2660 0 @ 2.20GHz
// - Qualcomm Technologies, Inc SM8150
let mut split = m.split_whitespace();
let mut segments: Vec<&str> =
split.by_ref().take(4).filter(|s| s != &"CPU").collect();

if matches!(segments.iter().last(), Some(&"PRO")) {
if let Some(s) = split.next() {
segments.push(s);
}
}

segments.join(" ")
} else {
m
}
}
Err(e) => {
readout_values.push(Readout::new_err(ReadoutKey::Processor, e));
return;
}
};

let cores = {
if opt.physical_cores {
general_readout.cpu_physical_cores()
Expand All @@ -367,12 +402,15 @@ fn handle_readout_processor(
}
};

match (general_readout.cpu_model_name(), cores) {
(Ok(m), Ok(c)) => {
readout_values.push(Readout::new(ReadoutKey::Processor, format_cpu(&m, c)))
}
(Ok(m), _) => readout_values.push(Readout::new(ReadoutKey::Processor, format_cpu_only(&m))),
(Err(e), _) => readout_values.push(Readout::new_err(ReadoutKey::Processor, e)),
match cores {
Ok(c) => readout_values.push(Readout::new(
ReadoutKey::Processor,
format_cpu(&cpu_model, c),
)),
_ => readout_values.push(Readout::new(
ReadoutKey::Processor,
format_cpu_only(&cpu_model),
)),
}
}

Expand Down