added verbose logs

This commit is contained in:
2026-03-24 17:24:25 +01:00
parent 88806c8822
commit 60d9822b3f
5 changed files with 74 additions and 19 deletions

View File

@@ -6,7 +6,7 @@ edition = "2024"
[dependencies]
clap = { version = "4.6.0", features = ["derive"] }
colored = "3.1.1"
cpal = "0.17.3"
cpal = {version = "0.17.3", default-features = false}
display-info = "0.5.9"
num_cpus = "1.17.0"
sysinfo = "0.38.4"

View File

@@ -1,3 +1,4 @@
use colored::Colorize;
use std::{
sync::{
Arc, Mutex,
@@ -7,6 +8,8 @@ use std::{
time::{Duration, Instant},
};
use crate::vprintln;
// Factor determining how many times the calculation runs in the multi-threaded test.
pub const MULTI_THREAD_LOAD_FACTOR: usize = 32;
@@ -17,7 +20,9 @@ pub struct BenchmarkResults {
pub batch_count: u64,
}
pub fn run_benchmark_singlethread(prime_limit: u64) -> BenchmarkResults {
pub fn run_benchmark_singlethread(prime_limit: u64, verbose: bool) -> BenchmarkResults {
vprintln!(verbose, "Running single-threaded CPU benchmark");
let start_time = Instant::now();
let primes_found = calculate_primes(1, prime_limit);
let duration = start_time.elapsed();
@@ -32,7 +37,9 @@ pub fn run_benchmark_singlethread(prime_limit: u64) -> BenchmarkResults {
}
}
pub fn run_benchmark_multithread(prime_limit: u64, jobs: usize) -> BenchmarkResults {
pub fn run_benchmark_multithread(prime_limit: u64, jobs: usize, verbose: bool) -> BenchmarkResults {
vprintln!(verbose, "Running multi-threaded CPU benchmark");
let start_time = Instant::now();
// The total number of calculation batches to perform across all threads

View File

@@ -3,6 +3,15 @@
pub mod benchmark;
pub mod slimes;
#[macro_export]
macro_rules! vprintln {
($verbose:expr, $($arg:tt)*) => {
if $verbose {
println!("{}", format!($($arg)*).dimmed());
}
};
}
pub fn application_header() -> &'static str {
r#"
.---.

View File

@@ -45,7 +45,7 @@ fn main() {
sys.refresh_all();
for slime in slimes {
slime.print(&sys);
slime.print(&sys, cli.verbose);
}
println!();
}
@@ -57,10 +57,11 @@ fn main() {
};
print_section_header("Single Threaded CPU Benchmark");
let singlethread_benchmark = run_benchmark_singlethread(cli.prime_limit);
let singlethread_benchmark = run_benchmark_singlethread(cli.prime_limit, cli.verbose);
print_detailed_result(&singlethread_benchmark);
print_section_header("Multi Threaded CPU Benchmark");
let multithread_benchmark = run_benchmark_multithread(cli.prime_limit, logical_core_count);
let multithread_benchmark =
run_benchmark_multithread(cli.prime_limit, logical_core_count, cli.verbose);
print_detailed_result(&multithread_benchmark);
let multi_thread_speedup_ratio = if singlethread_benchmark.score > 0 {

View File

@@ -2,14 +2,16 @@ use colored::Color;
use colored::Colorize;
use sysinfo::System;
use crate::vprintln;
pub trait Slime {
fn label(&self) -> &str;
fn values(&self, sys: &System) -> Vec<String>;
fn values(&self, sys: &System, verbose: bool) -> Vec<String>;
fn icon(&self) -> &str;
fn color(&self) -> Color;
fn print(&self, sys: &System) {
for (i, val) in self.values(sys).iter().enumerate() {
fn print(&self, sys: &System, verbose: bool) {
for (i, val) in self.values(sys, verbose).iter().enumerate() {
if i == 0 {
print!(
"{} {:<10} ",
@@ -45,7 +47,7 @@ impl Slime for OsSlime {
fn label(&self) -> &str {
"OS"
}
fn values(&self, _sys: &System) -> Vec<String> {
fn values(&self, _sys: &System, _verbose: bool) -> Vec<String> {
vec![format!(
"{}",
System::long_os_version().unwrap_or_else(|| "Unknown".into()),
@@ -65,7 +67,7 @@ impl Slime for KernelSlime {
fn label(&self) -> &str {
"Kernel"
}
fn values(&self, _sys: &System) -> Vec<String> {
fn values(&self, _sys: &System, _verbose: bool) -> Vec<String> {
vec![System::kernel_version().unwrap_or_else(|| "Unknown".into())]
}
fn icon(&self) -> &str {
@@ -82,7 +84,7 @@ impl Slime for HostnameSlime {
fn label(&self) -> &str {
"Hostname"
}
fn values(&self, _sys: &System) -> Vec<String> {
fn values(&self, _sys: &System, _verbose: bool) -> Vec<String> {
vec![System::host_name().unwrap_or_else(|| "Unknown".into())]
}
fn icon(&self) -> &str {
@@ -99,12 +101,14 @@ impl Slime for CpuSlime {
fn label(&self) -> &str {
"CPU"
}
fn values(&self, sys: &System) -> Vec<String> {
fn values(&self, sys: &System, verbose: bool) -> Vec<String> {
// sys.cpus()
// .iter()
// .map(|cpu| format!("{} @ {:.2}GHz", cpu.name(), cpu.frequency() as f32 / 1000.0))
// .collect()
vprintln!(verbose, "Querying and mapping CPU info");
let cpus = sys.cpus();
let max_freq_mhz = cpus.iter().map(|c| c.frequency()).max().unwrap_or(0) as f32 / 1000.0;
@@ -134,7 +138,7 @@ impl Slime for RamSlime {
fn label(&self) -> &str {
"RAM"
}
fn values(&self, sys: &System) -> Vec<String> {
fn values(&self, sys: &System, _verbose: bool) -> Vec<String> {
let total_ram = sys.total_memory() / 1024 / 1024;
let used_ram = sys.used_memory() / 1024 / 1024;
vec![format!(
@@ -163,7 +167,7 @@ impl Slime for BoardSlime {
fn color(&self) -> Color {
Color::Green
}
fn values(&self, _sys: &System) -> Vec<String> {
fn values(&self, _sys: &System, _verbose: bool) -> Vec<String> {
let Some(mobo) = sysinfo::Motherboard::new() else {
return vec!["Unknown Model".into()];
};
@@ -201,11 +205,18 @@ impl Slime for GpuSlime {
fn color(&self) -> Color {
Color::Cyan
}
fn values(&self, _sys: &System) -> Vec<String> {
fn values(&self, _sys: &System, verbose: bool) -> Vec<String> {
let mut gpus = Vec::new();
#[cfg(target_os = "windows")]
{
use std::process::Command;
vprintln!(
verbose,
r#"Executing `wmic path win32_VideoController get name`"#
);
if let Ok(output) = Command::new("wmic")
.args(["path", "win32_VideoController", "get", "name"])
.output()
@@ -224,6 +235,11 @@ impl Slime for GpuSlime {
{
use std::process::Command;
vprintln!(
verbose,
r#"Executing `sh -c "lspci | grep -E 'VGA|3D'"` and formatting"#
);
if let Ok(output) = Command::new("sh")
.arg("-c")
.arg("lspci | grep -E 'VGA|3D'")
@@ -262,7 +278,9 @@ impl Slime for MonitorSlime {
fn color(&self) -> Color {
Color::Blue
}
fn values(&self, _sys: &System) -> Vec<String> {
fn values(&self, _sys: &System, _verbose: bool) -> Vec<String> {
// vprintln!(verbose, "Querying and mapping monitors");
match display_info::DisplayInfo::all() {
Ok(displays) => displays
.iter()
@@ -298,13 +316,18 @@ impl Slime for NetworkSlime {
fn color(&self) -> Color {
Color::Cyan
}
fn values(&self, _sys: &System) -> Vec<String> {
fn values(&self, _sys: &System, verbose: bool) -> Vec<String> {
let mut nets = Vec::new();
#[cfg(target_os = "windows")]
{
use std::process::Command;
vprintln!(
verbose,
r#"Executing `wmic path win32_networkadapter where PhysicalAdapter=True get name`"#
);
if let Ok(output) = Command::new("wmic")
.args([
"path",
@@ -330,6 +353,11 @@ impl Slime for NetworkSlime {
{
use std::process::Command;
vprintln!(
verbose,
r#"Executing `sh -c "lspci | grep -E 'Network|Ethernet'"` and formatting"#
);
if let Ok(output) = Command::new("sh")
.arg("-c")
.arg("lspci | grep -E 'Network|Ethernet'")
@@ -364,13 +392,18 @@ impl Slime for AudioSlime {
fn color(&self) -> Color {
Color::Red
}
fn values(&self, _sys: &System) -> Vec<String> {
fn values(&self, _sys: &System, verbose: bool) -> Vec<String> {
let mut audio_cards = Vec::new();
#[cfg(target_os = "windows")]
{
use std::process::Command;
vprintln!(
verbose,
r#"Executing `wmic path win32_sounddevice get name`"#
);
if let Ok(output) = Command::new("wmic")
.args(["path", "win32_sounddevice", "get", "name"])
.output()
@@ -389,6 +422,11 @@ impl Slime for AudioSlime {
{
use std::process::Command;
vprintln!(
verbose,
r#"Executing `sh -c "lspci | grep -E 'Audio'"` and formatting"#
);
if let Ok(output) = Command::new("sh")
.arg("-c")
.arg("lspci | grep -i 'Audio'")