Added benchmarks for CPU and memory
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
000a33cfe4
commit
baf8630832
19
src/benchmarks/cpu.rs
Normal file
19
src/benchmarks/cpu.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
// test system memory with sysbench
|
||||||
|
pub fn sysbench(threads: &u8, maxprime: &u32) {
|
||||||
|
// run the fio command
|
||||||
|
let output = Command::new("sysbench")
|
||||||
|
.arg("cpu")
|
||||||
|
.arg(format!("--threads={}", threads))
|
||||||
|
.arg(format!("--cpu-max-prime={}", maxprime))
|
||||||
|
.arg("run")
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
// check that the command succeeded
|
||||||
|
assert!(output.status.success());
|
||||||
|
|
||||||
|
// print the test's output
|
||||||
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
}
|
21
src/benchmarks/memory.rs
Normal file
21
src/benchmarks/memory.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
// test system memory with sysbench
|
||||||
|
pub fn sysbench(accessmode: &str, operation: &str, blocksize: &str, totalsize: &str) {
|
||||||
|
// run the fio command
|
||||||
|
let output = Command::new("sysbench")
|
||||||
|
.arg("memory")
|
||||||
|
.arg(format!("--memory-access-mode={}", accessmode))
|
||||||
|
.arg(format!("--memory-oper={}", operation))
|
||||||
|
.arg(format!("--memory-block-size={}", blocksize))
|
||||||
|
.arg(format!("--memory-total-size={}", totalsize))
|
||||||
|
.arg("run")
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
// check that the command succeeded
|
||||||
|
assert!(output.status.success());
|
||||||
|
|
||||||
|
// print the test's output
|
||||||
|
println!("{}", String::from_utf8_lossy(&output.stdout));
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
pub mod cpu;
|
||||||
pub mod disk;
|
pub mod disk;
|
||||||
pub mod games;
|
pub mod games;
|
||||||
|
pub mod memory;
|
||||||
pub mod network;
|
pub mod network;
|
||||||
|
39
src/main.rs
39
src/main.rs
@ -20,6 +20,9 @@ enum Commands {
|
|||||||
// CPU benchmarks subcommand
|
// CPU benchmarks subcommand
|
||||||
#[clap(name = "cpu", about = "CPU benchmarks and stress tests.")]
|
#[clap(name = "cpu", about = "CPU benchmarks and stress tests.")]
|
||||||
Cpu(Cpu),
|
Cpu(Cpu),
|
||||||
|
// memory benchmarks subcommand
|
||||||
|
#[clap(name = "memory", about = "Memory benchmarks and stress tests.")]
|
||||||
|
Mem(Mem),
|
||||||
// disk benchmarks subcommand
|
// disk benchmarks subcommand
|
||||||
#[clap(name = "disk", about = "Hard drive and SSD benchmarks.")]
|
#[clap(name = "disk", about = "Hard drive and SSD benchmarks.")]
|
||||||
Disk(Disk),
|
Disk(Disk),
|
||||||
@ -47,6 +50,37 @@ enum CpuCommands {
|
|||||||
#[clap(short = 't', long, default_value_t = 0, help = "Number of threads to use; defaults to CPU's max thread count. Defaults to 0 (automatic)")]
|
#[clap(short = 't', long, default_value_t = 0, help = "Number of threads to use; defaults to CPU's max thread count. Defaults to 0 (automatic)")]
|
||||||
threads: usize,
|
threads: usize,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// CPU benchmark test subcommand
|
||||||
|
#[clap(name = "benchmark", about = "Benchmark the CPU")]
|
||||||
|
Benchmark {
|
||||||
|
#[clap(short = 'm', long, default_value_t = 4)]
|
||||||
|
threads: u8,
|
||||||
|
#[clap(short = 'o', long, default_value_t = 10000)]
|
||||||
|
maxprime: u32,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
struct Mem {
|
||||||
|
#[clap(subcommand)]
|
||||||
|
mem_commands: MemCommands,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
enum MemCommands {
|
||||||
|
// Memory benchmark test subcommand
|
||||||
|
#[clap(name = "benchmark", about = "Benchmark the system memory")]
|
||||||
|
Benchmark {
|
||||||
|
#[clap(short = 'm', long, default_value_t = String::from("seq"))]
|
||||||
|
accessmode: String,
|
||||||
|
#[clap(short = 'o', long, default_value_t = String::from("write"))]
|
||||||
|
operation: String,
|
||||||
|
#[clap(short = 'b', long, default_value_t = String::from("1K"))]
|
||||||
|
blocksize: String,
|
||||||
|
#[clap(short = 's', long, default_value_t = String::from("100G"))]
|
||||||
|
totalsize: String,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
@ -160,6 +194,11 @@ fn main() {
|
|||||||
match &cli.command {
|
match &cli.command {
|
||||||
Commands::Cpu(args) => match &args.cpu_commands {
|
Commands::Cpu(args) => match &args.cpu_commands {
|
||||||
CpuCommands::StressTest { runtime, threads } => stress::cpu::cpu_stress_math(*runtime, *threads),
|
CpuCommands::StressTest { runtime, threads } => stress::cpu::cpu_stress_math(*runtime, *threads),
|
||||||
|
CpuCommands::Benchmark { threads, maxprime } => benchmarks::cpu::sysbench(threads, maxprime),
|
||||||
|
},
|
||||||
|
|
||||||
|
Commands::Mem(args) => match &args.mem_commands {
|
||||||
|
MemCommands::Benchmark { accessmode, operation, blocksize, totalsize } => benchmarks::memory::sysbench(accessmode, operation, blocksize, totalsize),
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands::Disk(args) => match &args.disk_commands {
|
Commands::Disk(args) => match &args.disk_commands {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user