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

Add System Information to sysperf command #308

Merged
merged 3 commits into from
Dec 19, 2024
Merged
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
19 changes: 17 additions & 2 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions crates/rbuilder/src/live_builder/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use reth_db::Database;
use reth_provider::{BlockReader, DatabaseProviderFactory, HeaderProvider, StateProviderFactory};
use serde::de::DeserializeOwned;
use std::fmt::Debug;
use sysperf::{format_results, run_all_benchmarks};
use sysperf::{format_results, gather_system_info, run_all_benchmarks};
use tokio::signal::ctrl_c;
use tokio_util::sync::CancellationToken;

Expand Down Expand Up @@ -102,7 +102,8 @@ where
let result =
run_all_benchmarks(&PathBuf::from("/tmp/benchmark_test.tmp"), 100, 100, 1000)?;

println!("{}", format_results(&result));
let sysinfo = gather_system_info();
println!("{}", format_results(&result, &sysinfo));
return Ok(());
}
};
Expand Down
6 changes: 3 additions & 3 deletions crates/rbuilder/src/live_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ where
continue;
}
// Allow only increasing blocks
if last_processed_block.map_or(false, |last_processed_block| {
ferranbt marked this conversation as resolved.
Show resolved Hide resolved
payload.block() <= last_processed_block
}) {
if last_processed_block
.is_some_and(|last_processed_block| payload.block() <= last_processed_block)
{
continue;
}
let current_time = OffsetDateTime::now_utc();
Expand Down
2 changes: 1 addition & 1 deletion crates/rbuilder/src/primitives/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl RawShareBundle {
None
};

if self.metadata.as_ref().map_or(false, |r| r.cancelled) {
if self.metadata.as_ref().is_some_and(|r| r.cancelled) {
return Ok(RawShareBundleDecodeResult::CancelShareBundle(
CancelShareBundle {
block,
Expand Down
1 change: 1 addition & 0 deletions crates/rbuilder/src/telemetry/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//!
//! When metric server is spawned is serves prometheus metrics at: /debug/metrics/prometheus

#![allow(unexpected_cfgs)]
use crate::{
building::ExecutionResult, primitives::mev_boost::MevBoostRelayID, utils::build_info::Version,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/rbuilder/src/utils/error_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ pub fn store_error_event<T: serde::Serialize>(category: &str, error: &str, paylo
return;
}
};
if payload_json.as_bytes().len() > MAX_PAYLOAD_SIZE_BYTES {
ferranbt marked this conversation as resolved.
Show resolved Hide resolved
if payload_json.len() > MAX_PAYLOAD_SIZE_BYTES {
error!(
"Error payload is too large, not storing error event. Payload size: {}",
payload_json.as_bytes().len()
payload_json.len()
);
return;
}
Expand Down
1 change: 1 addition & 0 deletions crates/sysperf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ alloy-primitives.workspace = true
rayon = "1.8"
rand = "0.8"
num_cpus = "1.16"
sysinfo = "0.33.0"
106 changes: 98 additions & 8 deletions crates/sysperf/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use alloy_primitives::{keccak256, B256};
use rand::Rng;
use rayon::prelude::*;
use std::fs::OpenOptions;
use std::io::{Seek, SeekFrom, Write};
use std::path::Path;
use std::time::Instant;
use std::{
fs::OpenOptions,
io::{Seek, SeekFrom, Write},
path::Path,
time::Instant,
};
use sysinfo::{Disks, Networks, System};

// Common result structures
#[derive(Debug)]
Expand Down Expand Up @@ -39,6 +42,18 @@ pub struct CpuBenchmarkResult {
pub threads_used: usize,
}

#[derive(Debug)]
pub struct SystemInfoResult {
ferranbt marked this conversation as resolved.
Show resolved Hide resolved
pub long_os_version: Option<String>,
pub kernel_version: Option<String>,
pub cpu_brand: String,
pub cpu_count: usize,
pub total_memory_mb: u64,
pub used_memory_mb: u64,
pub disk_info: String,
pub network_info: String,
}

// Disk Benchmarks
pub fn benchmark_sequential_write(
path: &Path,
Expand Down Expand Up @@ -243,25 +258,100 @@ pub fn run_all_benchmarks(
})
}

pub fn format_results(result: &BenchmarkResult) -> String {
pub fn gather_system_info() -> SystemInfoResult {
let mut sys = System::new_all();
sys.refresh_all();

let long_os_version = System::long_os_version();
let kernel_version = System::kernel_version();
let cpu_brand = if !sys.cpus().is_empty() {
sys.cpus()[0].brand().to_string()
} else {
"Unknown CPU".to_string()
};

let cpu_count = sys.cpus().len();
let total_memory_mb = sys.total_memory() / 1024;
let used_memory_mb = sys.used_memory() / 1024;

let networks = Networks::new_with_refreshed_list();
let disks = Disks::new_with_refreshed_list();

// Build the disk_info string
let mut disk_info = String::from("Disks:\n");
for disk in disks.list() {
disk_info.push_str(&format!(
" {:?}: {}B total, {}B available\n",
disk.name(),
disk.total_space(),
disk.available_space()
));
}

// Build the network_info string
let mut network_info = String::from("Networks:\n");
for (name, data) in networks.list() {
network_info.push_str(&format!(
" {}: received={}B, transmitted={}B\n",
name,
data.total_received(),
data.total_transmitted()
));
}

SystemInfoResult {
long_os_version,
kernel_version,
cpu_brand,
cpu_count,
total_memory_mb,
used_memory_mb,
disk_info,
network_info,
}
}

pub fn format_results(result: &BenchmarkResult, sysinfo: &SystemInfoResult) -> String {
format!(
"Hardware Benchmark Results:\n\
"System Information:\n\
OS Version: {}\n\
Kernel Version: {}\n\
CPU: {} ({} cores)\n\
Total Memory: {} MB\n\
Used Memory: {} MB\n\
\nHardware Benchmark Results:\n\
\nDisk Performance:\
\n Sequential Write: {:.2} MB/s ({:.2} ops/s)\
\n Random Write: {:.2} MB/s ({:.2} ops/s)\
\n\nMemory Performance:\
\n Bandwidth: {:.2} GB/s\
\n\nCPU Performance:\
\n Single-threaded: {:.2} hashes/s\
\n Multi-threaded: {:.2} hashes/s (using {} threads)",
\n Multi-threaded: {:.2} hashes/s (using {} threads)\
\n\n{}\
\n{}",
sysinfo
.long_os_version
.clone()
.unwrap_or_else(|| "Unknown".to_string()),
sysinfo
.kernel_version
.clone()
.unwrap_or_else(|| "Unknown".to_string()),
sysinfo.cpu_brand,
sysinfo.cpu_count,
sysinfo.total_memory_mb,
sysinfo.used_memory_mb,
result.disk_sequential.throughput_mb_s,
result.disk_sequential.operations_per_second,
result.disk_random.throughput_mb_s,
result.disk_random.operations_per_second,
result.memory.bandwidth_gb_s,
result.cpu_single.hashes_per_second,
result.cpu_parallel.hashes_per_second,
result.cpu_parallel.threads_used
result.cpu_parallel.threads_used,
sysinfo.disk_info,
sysinfo.network_info,
)
}

Expand Down
Loading