Added a disk benchmark test for sequential reads
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
1c56e43de8
commit
be549808b5
11
src/main.rs
11
src/main.rs
@ -28,7 +28,15 @@ struct Disk {
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum DiskCommands {
|
||||
#[clap(name = "write-test", about = "Write a large file to determine sequential disk speeds.")]
|
||||
// disk read subcommand
|
||||
#[clap(name = "read-test", about = "Read from /dev/zero to determine sequential disk read speeds.")]
|
||||
ReadTest {
|
||||
#[clap(short = 's', default_value_t = 15)]
|
||||
size: u8,
|
||||
},
|
||||
|
||||
// disk write subcommand
|
||||
#[clap(name = "write-test", about = "Write a large file to determine sequential disk write speeds.")]
|
||||
WriteTest {
|
||||
#[clap(short = 't', default_value_t = String::from("/tmp/disk-test.tmp"))]
|
||||
tempfile: String,
|
||||
@ -70,6 +78,7 @@ fn main() {
|
||||
// map subcommands back to the main command
|
||||
match &cli.command {
|
||||
Commands::Disk(args) => match &args.disk_commands {
|
||||
DiskCommands::ReadTest { size } => tests::disk::disk_read_test(size),
|
||||
DiskCommands::WriteTest { tempfile, size } => tests::disk::disk_write_test(tempfile, size),
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,33 @@
|
||||
use std::fs;
|
||||
use std::process::Command;
|
||||
|
||||
// test disk read speeds by reading for /dev/zero and writing it to /dev/null
|
||||
pub fn disk_read_test(size: &u8) {
|
||||
// convert size in Gigabytes down to Megabytes
|
||||
let size_gigs: u32 = (*size as u32 * 1024 * 8).into();
|
||||
|
||||
// run sync to clear out any disk caches prior to running
|
||||
Command::new("sync");
|
||||
|
||||
// run the dd command
|
||||
let output = Command::new("dd")
|
||||
.arg("bs=128k")
|
||||
.arg(format!("count={}", size_gigs))
|
||||
.arg("if=/dev/zero")
|
||||
.arg("of=/dev/null")
|
||||
.output()
|
||||
.expect("Failed to execute command");
|
||||
|
||||
// check that the command succeeded
|
||||
assert!(output.status.success());
|
||||
|
||||
// dd's output ends up in stderr
|
||||
println!("{}", String::from_utf8_lossy(&output.stderr));
|
||||
|
||||
// run another sync to clear out the disk's cache
|
||||
Command::new("sync");
|
||||
}
|
||||
|
||||
// test disk write speeds by continually writing zeroes to it
|
||||
pub fn disk_write_test(tempfile: &str, size: &u8) {
|
||||
// convert size in Gigabytes down to Megabytes
|
||||
|
Loading…
Reference in New Issue
Block a user