added verbose logs
This commit is contained in:
@@ -6,7 +6,7 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.6.0", features = ["derive"] }
|
clap = { version = "4.6.0", features = ["derive"] }
|
||||||
colored = "3.1.1"
|
colored = "3.1.1"
|
||||||
cpal = "0.17.3"
|
cpal = {version = "0.17.3", default-features = false}
|
||||||
display-info = "0.5.9"
|
display-info = "0.5.9"
|
||||||
num_cpus = "1.17.0"
|
num_cpus = "1.17.0"
|
||||||
sysinfo = "0.38.4"
|
sysinfo = "0.38.4"
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use colored::Colorize;
|
||||||
use std::{
|
use std::{
|
||||||
sync::{
|
sync::{
|
||||||
Arc, Mutex,
|
Arc, Mutex,
|
||||||
@@ -7,6 +8,8 @@ use std::{
|
|||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::vprintln;
|
||||||
|
|
||||||
// Factor determining how many times the calculation runs in the multi-threaded test.
|
// Factor determining how many times the calculation runs in the multi-threaded test.
|
||||||
pub const MULTI_THREAD_LOAD_FACTOR: usize = 32;
|
pub const MULTI_THREAD_LOAD_FACTOR: usize = 32;
|
||||||
|
|
||||||
@@ -17,7 +20,9 @@ pub struct BenchmarkResults {
|
|||||||
pub batch_count: u64,
|
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 start_time = Instant::now();
|
||||||
let primes_found = calculate_primes(1, prime_limit);
|
let primes_found = calculate_primes(1, prime_limit);
|
||||||
let duration = start_time.elapsed();
|
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();
|
let start_time = Instant::now();
|
||||||
|
|
||||||
// The total number of calculation batches to perform across all threads
|
// The total number of calculation batches to perform across all threads
|
||||||
|
|||||||
@@ -3,6 +3,15 @@
|
|||||||
pub mod benchmark;
|
pub mod benchmark;
|
||||||
pub mod slimes;
|
pub mod slimes;
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! vprintln {
|
||||||
|
($verbose:expr, $($arg:tt)*) => {
|
||||||
|
if $verbose {
|
||||||
|
println!("{}", format!($($arg)*).dimmed());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn application_header() -> &'static str {
|
pub fn application_header() -> &'static str {
|
||||||
r#"
|
r#"
|
||||||
.---.
|
.---.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ fn main() {
|
|||||||
sys.refresh_all();
|
sys.refresh_all();
|
||||||
|
|
||||||
for slime in slimes {
|
for slime in slimes {
|
||||||
slime.print(&sys);
|
slime.print(&sys, cli.verbose);
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
@@ -57,10 +57,11 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
print_section_header("Single Threaded CPU Benchmark");
|
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_detailed_result(&singlethread_benchmark);
|
||||||
print_section_header("Multi Threaded CPU 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);
|
print_detailed_result(&multithread_benchmark);
|
||||||
|
|
||||||
let multi_thread_speedup_ratio = if singlethread_benchmark.score > 0 {
|
let multi_thread_speedup_ratio = if singlethread_benchmark.score > 0 {
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ use colored::Color;
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use sysinfo::System;
|
use sysinfo::System;
|
||||||
|
|
||||||
|
use crate::vprintln;
|
||||||
|
|
||||||
pub trait Slime {
|
pub trait Slime {
|
||||||
fn label(&self) -> &str;
|
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 icon(&self) -> &str;
|
||||||
fn color(&self) -> Color;
|
fn color(&self) -> Color;
|
||||||
|
|
||||||
fn print(&self, sys: &System) {
|
fn print(&self, sys: &System, verbose: bool) {
|
||||||
for (i, val) in self.values(sys).iter().enumerate() {
|
for (i, val) in self.values(sys, verbose).iter().enumerate() {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
print!(
|
print!(
|
||||||
"{} {:<10} ",
|
"{} {:<10} ",
|
||||||
@@ -45,7 +47,7 @@ impl Slime for OsSlime {
|
|||||||
fn label(&self) -> &str {
|
fn label(&self) -> &str {
|
||||||
"OS"
|
"OS"
|
||||||
}
|
}
|
||||||
fn values(&self, _sys: &System) -> Vec<String> {
|
fn values(&self, _sys: &System, _verbose: bool) -> Vec<String> {
|
||||||
vec![format!(
|
vec![format!(
|
||||||
"{}",
|
"{}",
|
||||||
System::long_os_version().unwrap_or_else(|| "Unknown".into()),
|
System::long_os_version().unwrap_or_else(|| "Unknown".into()),
|
||||||
@@ -65,7 +67,7 @@ impl Slime for KernelSlime {
|
|||||||
fn label(&self) -> &str {
|
fn label(&self) -> &str {
|
||||||
"Kernel"
|
"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())]
|
vec![System::kernel_version().unwrap_or_else(|| "Unknown".into())]
|
||||||
}
|
}
|
||||||
fn icon(&self) -> &str {
|
fn icon(&self) -> &str {
|
||||||
@@ -82,7 +84,7 @@ impl Slime for HostnameSlime {
|
|||||||
fn label(&self) -> &str {
|
fn label(&self) -> &str {
|
||||||
"Hostname"
|
"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())]
|
vec![System::host_name().unwrap_or_else(|| "Unknown".into())]
|
||||||
}
|
}
|
||||||
fn icon(&self) -> &str {
|
fn icon(&self) -> &str {
|
||||||
@@ -99,12 +101,14 @@ impl Slime for CpuSlime {
|
|||||||
fn label(&self) -> &str {
|
fn label(&self) -> &str {
|
||||||
"CPU"
|
"CPU"
|
||||||
}
|
}
|
||||||
fn values(&self, sys: &System) -> Vec<String> {
|
fn values(&self, sys: &System, verbose: bool) -> Vec<String> {
|
||||||
// sys.cpus()
|
// sys.cpus()
|
||||||
// .iter()
|
// .iter()
|
||||||
// .map(|cpu| format!("{} @ {:.2}GHz", cpu.name(), cpu.frequency() as f32 / 1000.0))
|
// .map(|cpu| format!("{} @ {:.2}GHz", cpu.name(), cpu.frequency() as f32 / 1000.0))
|
||||||
// .collect()
|
// .collect()
|
||||||
|
|
||||||
|
vprintln!(verbose, "Querying and mapping CPU info");
|
||||||
|
|
||||||
let cpus = sys.cpus();
|
let cpus = sys.cpus();
|
||||||
|
|
||||||
let max_freq_mhz = cpus.iter().map(|c| c.frequency()).max().unwrap_or(0) as f32 / 1000.0;
|
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 {
|
fn label(&self) -> &str {
|
||||||
"RAM"
|
"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 total_ram = sys.total_memory() / 1024 / 1024;
|
||||||
let used_ram = sys.used_memory() / 1024 / 1024;
|
let used_ram = sys.used_memory() / 1024 / 1024;
|
||||||
vec![format!(
|
vec![format!(
|
||||||
@@ -163,7 +167,7 @@ impl Slime for BoardSlime {
|
|||||||
fn color(&self) -> Color {
|
fn color(&self) -> Color {
|
||||||
Color::Green
|
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 {
|
let Some(mobo) = sysinfo::Motherboard::new() else {
|
||||||
return vec!["Unknown Model".into()];
|
return vec!["Unknown Model".into()];
|
||||||
};
|
};
|
||||||
@@ -201,11 +205,18 @@ impl Slime for GpuSlime {
|
|||||||
fn color(&self) -> Color {
|
fn color(&self) -> Color {
|
||||||
Color::Cyan
|
Color::Cyan
|
||||||
}
|
}
|
||||||
fn values(&self, _sys: &System) -> Vec<String> {
|
fn values(&self, _sys: &System, verbose: bool) -> Vec<String> {
|
||||||
let mut gpus = Vec::new();
|
let mut gpus = Vec::new();
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[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")
|
if let Ok(output) = Command::new("wmic")
|
||||||
.args(["path", "win32_VideoController", "get", "name"])
|
.args(["path", "win32_VideoController", "get", "name"])
|
||||||
.output()
|
.output()
|
||||||
@@ -224,6 +235,11 @@ impl Slime for GpuSlime {
|
|||||||
{
|
{
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
vprintln!(
|
||||||
|
verbose,
|
||||||
|
r#"Executing `sh -c "lspci | grep -E 'VGA|3D'"` and formatting"#
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(output) = Command::new("sh")
|
if let Ok(output) = Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg("lspci | grep -E 'VGA|3D'")
|
.arg("lspci | grep -E 'VGA|3D'")
|
||||||
@@ -262,7 +278,9 @@ impl Slime for MonitorSlime {
|
|||||||
fn color(&self) -> Color {
|
fn color(&self) -> Color {
|
||||||
Color::Blue
|
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() {
|
match display_info::DisplayInfo::all() {
|
||||||
Ok(displays) => displays
|
Ok(displays) => displays
|
||||||
.iter()
|
.iter()
|
||||||
@@ -298,13 +316,18 @@ impl Slime for NetworkSlime {
|
|||||||
fn color(&self) -> Color {
|
fn color(&self) -> Color {
|
||||||
Color::Cyan
|
Color::Cyan
|
||||||
}
|
}
|
||||||
fn values(&self, _sys: &System) -> Vec<String> {
|
fn values(&self, _sys: &System, verbose: bool) -> Vec<String> {
|
||||||
let mut nets = Vec::new();
|
let mut nets = Vec::new();
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
vprintln!(
|
||||||
|
verbose,
|
||||||
|
r#"Executing `wmic path win32_networkadapter where PhysicalAdapter=True get name`"#
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(output) = Command::new("wmic")
|
if let Ok(output) = Command::new("wmic")
|
||||||
.args([
|
.args([
|
||||||
"path",
|
"path",
|
||||||
@@ -330,6 +353,11 @@ impl Slime for NetworkSlime {
|
|||||||
{
|
{
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
vprintln!(
|
||||||
|
verbose,
|
||||||
|
r#"Executing `sh -c "lspci | grep -E 'Network|Ethernet'"` and formatting"#
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(output) = Command::new("sh")
|
if let Ok(output) = Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg("lspci | grep -E 'Network|Ethernet'")
|
.arg("lspci | grep -E 'Network|Ethernet'")
|
||||||
@@ -364,13 +392,18 @@ impl Slime for AudioSlime {
|
|||||||
fn color(&self) -> Color {
|
fn color(&self) -> Color {
|
||||||
Color::Red
|
Color::Red
|
||||||
}
|
}
|
||||||
fn values(&self, _sys: &System) -> Vec<String> {
|
fn values(&self, _sys: &System, verbose: bool) -> Vec<String> {
|
||||||
let mut audio_cards = Vec::new();
|
let mut audio_cards = Vec::new();
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
vprintln!(
|
||||||
|
verbose,
|
||||||
|
r#"Executing `wmic path win32_sounddevice get name`"#
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(output) = Command::new("wmic")
|
if let Ok(output) = Command::new("wmic")
|
||||||
.args(["path", "win32_sounddevice", "get", "name"])
|
.args(["path", "win32_sounddevice", "get", "name"])
|
||||||
.output()
|
.output()
|
||||||
@@ -389,6 +422,11 @@ impl Slime for AudioSlime {
|
|||||||
{
|
{
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
vprintln!(
|
||||||
|
verbose,
|
||||||
|
r#"Executing `sh -c "lspci | grep -E 'Audio'"` and formatting"#
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(output) = Command::new("sh")
|
if let Ok(output) = Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg("lspci | grep -i 'Audio'")
|
.arg("lspci | grep -i 'Audio'")
|
||||||
|
|||||||
Reference in New Issue
Block a user