Skip to content

Instantly share code, notes, and snippets.

@tateisu
Last active March 18, 2021 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tateisu/68b9cd634f0c98a9e449c8ecfffea310 to your computer and use it in GitHub Desktop.
Save tateisu/68b9cd634f0c98a9e449c8ecfffea310 to your computer and use it in GitHub Desktop.
fio をCrystalDiskMark風に使うスクリプト
#!/usr/bin/perl --
use strict;
use warnings;
use IPC::Open2;
my $target = shift or die "usage: $0 {folder}\n";
my $runtime = 3;
my $size= "32g";
my $config = <<"END";
[global]
ioengine=libaio
size=$size
direct=1
runtime=$runtime
directory=$target
filename=.fio-diskmark
thread
END
;
my @rules = (
[ "Seq-1M-Q1T1" ,"" ,bs=>"1M" ,iodepth =>1 ,numjobs=>1 ],
[ "Rand-512k-Q8T8" ,"rand" ,bs=>"512k" ,iodepth =>8 ,numjobs=>8 ],
[ "Rand-4k-Q32T1" ,"rand" ,bs=>"4k" ,iodepth =>32 ,numjobs=>1 ],
[ "Rand-4k-Q1T1" ,"rand" ,bs=>"4k" ,iodepth =>1 ,numjobs=>1 ],
);
for(@rules){
my($name,$rand,@params)=@$_;
for my $rw( "read","write" ){
$config .= "\n[$name-$rw]\n";
for(my $i=0;$i<@params;$i+=2){
$config .= "$params[$i]=$params[$i+1]\n";
}
$config .= "rw=$rand$rw\n";
$config .= "stonewall\n";
}
}
my $prog = "fio -";
open2(my $reader,my $writer, $prog) or die "$! $prog";
print $writer $config;
close($writer) or die "$! $prog";
my $text ="";
while(<$reader>){
$text .= $_;
chomp;
print $_,"\n";
}
close($reader) or die "$!";
unlink "$target/.fio-diskmark";
my %names;
while( $text=~ /^(\S+?): \(g=(\d+)/gm ){
$names{0+$2}=$1;
}
my %values;
while( $text =~ /^Run status group (\d+)\s*\Q(all jobs):\E[\x0d\x0a]+\s*(?:READ|WRITE):\s*([^\x0d\x0a]+)$/gm ){
my $name = $names{0+$1};
my $line = $2;
$line =~ /\(([\d.]+)([kM]?)B\/s\)/ or die "can't parse bandwidth. $line";
my($num,$unit)=(0+$1,$2);
if ($unit =~ /k/i){
$num /= 1000;
}elsif( $unit eq "" ){
$num /= 1000000;
}
$values{$name} = $num;
}
sub n{
my($name)=@_;
my $v = $values{$name} or die "missing value for $name";
return $v;
}
my $nameLen =0;
for(@rules){
my($name)=@$_;
$nameLen = length $name if $nameLen < length $name;
}
printf("|%s| Read(MB/s)|Write(MB/s)|\n"," " x $nameLen);
printf("|%s|-----------|-----------|\n","-" x $nameLen);
for(@rules){
my($name)=@$_;
printf("|%${nameLen}s|%11.3f|%11.3f|\n", $name, n("${name}-read"), n("${name}-write"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment