-
Notifications
You must be signed in to change notification settings - Fork 12
/
tiobench.pl
executable file
·364 lines (324 loc) · 15.1 KB
/
tiobench.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/usr/bin/env perl
# Author: James Manning <jmm at users.sf.net>
# Author: Randy Hron <rwhron at earthlink dot net>
# This software may be used and distributed according to the terms of
# the GNU General Public License, http://www.gnu.org/copyleft/gpl.html
#
# Description:
# Perl wrapper for calling the tiotest executable multiple times
# with varying sets of parameters as instructed
use warnings;
use strict;
use Getopt::Long;
$|=1; # give output ASAP
# look around for tiotest in different places
my @tiotest_places=(
'.', # current directory
'/usr/local/bin', # install target location
'/usr/sbin', # install target location
split(':',$ENV{'PATH'}), # directories in current $PATH
($0 =~m#(.*)/#) # directory this script resides in
);
my $tiotest='';
foreach my $place (@tiotest_places) {
$tiotest=$place . '/tiotest';
last if -x $tiotest;
}
if (! -x $tiotest) {
print "tiotest program not found in any of the following places:\n\n",
join(' ',@tiotest_places),"\n\n",
"copy it to one of them or modify this perl script's ",
"\@tiotest_places array\n";
exit(1);
}
### CONSTANTS
# sizes
my $KB = 1024;
my $MB = 1024 * 1024;
my $GB = 1024 * 1024 * 1024;
# debug levels, ala log4j and jakarta commons logging
my $LEVEL_NONE = 0;
my $LEVEL_FATAL = 10;
my $LEVEL_ERROR = 20;
my $LEVEL_WARN = 30;
my $LEVEL_INFO = 40;
my $LEVEL_DEBUG = 50;
my $LEVEL_TRACE = 60;
### VARIABLES
my @sizes; my $size; my @targets; my $dir;
my @blocks; my $block; my @threads; my $thread;
my $random_ops; my %stat_data; my $area; my $mem_size;
my $write_mbytes; my $write_time; my $write_utime; my $write_stime;
my $rwrite_mbytes; my $rwrite_time; my $rwrite_utime; my $rwrite_stime;
my $read_mbytes; my $read_time; my $read_utime; my $read_stime;
my $rread_mbytes; my $rread_time; my $rread_utime; my $rread_stime;
my $num_runs; my $run_number; my $help; my $nofrag;
my $identifier; my $debug; my $dump; my $progress;
my $timeout; my $rawdev; my $flushCaches; my $directIO;
# option parsing
GetOptions("target=s@",\@targets,
"identifier=s",\$identifier,
"size=i@",\@sizes,
"block=i@",\@blocks,
"random=i",\$random_ops,
"numruns=i",\$num_runs,
"help",\$help,
"nofrag",\$nofrag,
"debug=i",\$debug,
"timeout=i",\$timeout,
"dump",\$dump,
"progress",\$progress,
"threads=i@",\@threads,
"flushCaches", \$flushCaches,
"directio", \$directIO,);
&usage if $help || $Getopt::Long::error;
my $start_time = time if $timeout;
### DEFAULT VALUES
$num_runs=1 unless $num_runs && $num_runs > 0;
@targets=qw(.) unless @targets;
@blocks=qw(4096) unless @blocks;
@threads=qw(1 2 4 8) unless @threads;
$random_ops=4000 unless $random_ops;
chomp($identifier=`uname -r`) unless $identifier;
$debug=$LEVEL_NONE unless defined($debug);
unless(@sizes) { # try to be a little smart about file size when possible
my $mem_size = &get_memory_size();
$mem_size = int($mem_size/$MB); # convert to MB
my $use_size=2*($mem_size); # try to use at least twice memory
# used to cap the value between 200 MB and about 2 GB
#$use_size=200 if $use_size < 200; # min
#$use_size=2000 if $use_size > 2000; # max
@sizes=($use_size);
print "No size specified, using $use_size MB\n"
if $debug >= $LEVEL_INFO;
}
# setup the reporting stuff for fancy output
format SEQ_READS_TOP =
File Blk Num Avg Maximum Lat% Lat% CPU
Identifier Size Size Thr Rate (CPU%) Latency Latency >2s >10s Eff
---------------------------- ------ ------ --- ------------ ------ --------- ----------- -------- -------- -------
.
format SEQ_READS =
@<<<<<<<<<<<<<<<<<<<<<<<<<<< @||||| @||||| @>> @########.## @>>>>% @####.### @#######.## @#.##### @#.##### @######
$identifier,$size,$block,$thread,$stat_data{$identifier}{$thread}{$size}{$block}{'read'}{'rate'},$stat_data{$identifier}{$thread}{$size}{$block}{'read'}{'cpu'},$stat_data{$identifier}{$thread}{$size}{$block}{'read'}{'avglat'},$stat_data{$identifier}{$thread}{$size}{$block}{'read'}{'maxlat'},$stat_data{$identifier}{$thread}{$size}{$block}{'read'}{'pct_gt_2_sec'},$stat_data{$identifier}{$thread}{$size}{$block}{'read'}{'pct_gt_10_sec'},$stat_data{$identifier}{$thread}{$size}{$block}{'read'}{'cpueff'}
.
format RAND_READS =
@<<<<<<<<<<<<<<<<<<<<<<<<<<< @||||| @||||| @>> @########.## @>>>>% @####.### @#######.## @#.##### @#.##### @######
$identifier,$size,$block,$thread,$stat_data{$identifier}{$thread}{$size}{$block}{'rread'}{'rate'},$stat_data{$identifier}{$thread}{$size}{$block}{'rread'}{'cpu'},$stat_data{$identifier}{$thread}{$size}{$block}{'rread'}{'avglat'},$stat_data{$identifier}{$thread}{$size}{$block}{'rread'}{'maxlat'},$stat_data{$identifier}{$thread}{$size}{$block}{'rread'}{'pct_gt_2_sec'},$stat_data{$identifier}{$thread}{$size}{$block}{'rread'}{'pct_gt_10_sec'},$stat_data{$identifier}{$thread}{$size}{$block}{'rread'}{'cpueff'}
.
format SEQ_WRITES =
@<<<<<<<<<<<<<<<<<<<<<<<<<<< @||||| @||||| @>> @########.## @>>>>% @####.### @#######.## @#.##### @#.##### @######
$identifier,$size,$block,$thread,$stat_data{$identifier}{$thread}{$size}{$block}{'write'}{'rate'},$stat_data{$identifier}{$thread}{$size}{$block}{'write'}{'cpu'},$stat_data{$identifier}{$thread}{$size}{$block}{'write'}{'avglat'},$stat_data{$identifier}{$thread}{$size}{$block}{'write'}{'maxlat'},$stat_data{$identifier}{$thread}{$size}{$block}{'write'}{'pct_gt_2_sec'},$stat_data{$identifier}{$thread}{$size}{$block}{'write'}{'pct_gt_10_sec'},$stat_data{$identifier}{$thread}{$size}{$block}{'write'}{'cpueff'}
.
format RAND_WRITES =
@<<<<<<<<<<<<<<<<<<<<<<<<<<< @||||| @||||| @>> @########.## @>>>>% @####.### @#######.## @#.##### @#.##### @######
$identifier,$size,$block,$thread,$stat_data{$identifier}{$thread}{$size}{$block}{'rwrite'}{'rate'},$stat_data{$identifier}{$thread}{$size}{$block}{'rwrite'}{'cpu'},$stat_data{$identifier}{$thread}{$size}{$block}{'rwrite'}{'avglat'},$stat_data{$identifier}{$thread}{$size}{$block}{'rwrite'}{'maxlat'},$stat_data{$identifier}{$thread}{$size}{$block}{'rwrite'}{'pct_gt_2_sec'},$stat_data{$identifier}{$thread}{$size}{$block}{'rwrite'}{'pct_gt_10_sec'},$stat_data{$identifier}{$thread}{$size}{$block}{'rwrite'}{'cpueff'}
.
my $total_runs;
my $total_runs_completed;
my $progressbar;
if ($progress) {
$total_runs = $num_runs *
scalar(@targets) *
scalar(@sizes) *
scalar(@blocks) *
scalar(@threads);
$total_runs_completed = 0;
require Term::ProgressBar;
$progressbar = Term::ProgressBar->new({name => 'tiotest runs',
count => $total_runs,
ETA => 'linear',
});
}
my $targets_str = join '', map { " -d " . $_ } @targets;
if(&all_devices(@targets)) {
print "All targets are devices\n"
if $debug >= $LEVEL_INFO;
$targets_str .= ' -R'; # add "raw devices" param
} elsif(&all_directories(@targets)) {
print "All targets are directories\n"
if $debug >= $LEVEL_INFO;
# nothing to do here
} else {
print STDERR "--target params must be either all devices or all directories\n";
exit(1);
}
# run all the possible combinations/permutations/whatever
OUTER:
foreach $size (@sizes) {
foreach $block (@blocks) {
foreach $thread (@threads) {
my $thread_rand=int($random_ops/$thread);
my $thread_size=int($size/$thread); $thread_size=1 if $thread_size==0;
my $run_string = "$tiotest -t $thread -f $thread_size ".
"-r $thread_rand -b $block $targets_str -T";
$run_string .= " -W" if $nofrag;
$run_string .= " -R" if $rawdev;
$run_string .= " -D $debug" if $debug > 0;
$run_string .= " -F" if $flushCaches;
$run_string .= " -X" if $directIO;
foreach $run_number (1..$num_runs) {
print "Running: $run_string\n"
if $debug >= $LEVEL_INFO;
open(TIOTEST,"$run_string |") or die "Could not run $tiotest";
while(my $line = <TIOTEST>) {
next if $line =~ /^total/o; # this may be useful, but it's been ignored up to this point.
print "Processing output line of $line"
if $debug >= $LEVEL_INFO;
my ($field,$amount,$time,$utime,$stime,$avglat,$maxlat,$pct_gt_2_sec,$pct_gt_10_sec)=split(/[:,]/, $line);
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'amount'} += $amount;
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'time'} += $time;
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'utime'} += $utime;
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'stime'} += $stime;
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'avglat'} += $avglat;
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'maxlat'} += $maxlat;
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'pct_gt_2_sec'} += $pct_gt_2_sec;
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'pct_gt_10_sec'} += $pct_gt_10_sec;
}
close(TIOTEST);
$progressbar->update(++$total_runs_completed) if $progress;
}
for my $field ('read','rread','write','rwrite') {
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'rate'} =
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'amount'} /
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'time'};
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'cpu'} =
100 * ( $stat_data{$identifier}{$thread}{$size}{$block}{$field}{'utime'} +
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'stime'} ) /
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'time'};
$stat_data{$identifier}{$thread}{$size}{$block}{$field}{'cpueff'} =
($stat_data{$identifier}{$thread}{$size}{$block}{$field}{'rate'} /
($stat_data{$identifier}{$thread}{$size}{$block}{$field}{'cpu'}/100+0.00001));
}
if($timeout && (time > ($start_time + $timeout))) {
print STDERR "\nTimeout of $timeout seconds has been reached, aborting ($total_runs_completed of $total_runs runs completed)\n";
last OUTER;
}
}
}
}
if ($dump) {
require Data::Dumper;
print Data::Dumper->Dump([\%stat_data], [qw(stat_data)]);
exit(0);
}
# report summary
print "
Unit information
================
File size = megabytes (2^20 bytes, 1,048,576 bytes)
Blk Size = bytes
Rate = megabytes per second
CPU% = percentage of CPU used during the test
Latency = milliseconds
Lat% = percent of requests that took longer than X seconds
CPU Eff = Rate divided by CPU% - throughput per cpu load
";
my %report = (
'SEQ_READS' => 'Sequential Reads',
'RAND_READS' => 'Random Reads',
'SEQ_WRITES' => 'Sequential Writes',
'RAND_WRITES' => 'Random Writes',
);
# The top is the same for all 4 reports
$^ = 'SEQ_READS_TOP';
foreach my $title ('SEQ_READS', 'RAND_READS', 'SEQ_WRITES', 'RAND_WRITES') {
$-=0; $~="$title"; $^L=''; # reporting variables
print "\n$report{$title}\n";
print '=' x length("$report{$title}") . "\n";
foreach $size (@sizes) {
foreach $block (@blocks) {
foreach $thread (@threads) {
write if defined($stat_data{$identifier}{$thread}{$size}{$block});
}
}
}
}
###########################################
######### Utility subroutines #############
###########################################
sub usage {
print "Usage: $0 [<options>]\n","Available options:\n\t",
"[--help] (this help text)\n\t",
"[--identifier IdentString] (use IdentString as identifier in output)\n\t",
"[--nofrag] (don't write fragmented files)\n\t",
"[--raw] (use raw device defined with --dir)\n\t",
"[--size SizeInMB]+\n\t",
"[--numruns NumberOfRuns]\n\t",
"[--target DirOrDisk]+\n\t",
"[--block BlkSizeInBytes]+\n\t",
"[--random NumberRandOpsAllThreads]+\n\t",
"[--threads NumberOfThreads]+\n\t",
"[--dump] (dump in Data::Dumper format, no report)\n\t",
"[--progress] (monitor progress with Term::ProgressBar)\n\t",
"[--timeout TimeoutInSeconds]\n\t",
"[--flushCaches] (requires root)\n\t",
"[--debug DebugLevel]\n\n",
"+ means you can specify this option multiple times to cover multiple\n",
"cases, for instance: $0 --block 4096 --block 8192 will first run\n",
"through with a 4KB block size and then again with a 8KB block size.\n",
"\n",
"--numruns specifies over how many runs each test combination of\n",
"parameters should be averaged\n";
"\n",
"--target parameters are all tested in parallel on each tiotest\n",
"run using tiotest's ability to take multiple -d parameters\n",
exit(1);
}
# sub to try various methods to get the amount of memory of this machine
# returned value is in bytes
sub get_memory_size {
my $mem_size; my @stat_ret;
# first try /proc/meminfo if it's around and readable
if(-r '/proc/meminfo') {
open(MEMINFO,'/proc/meminfo') or die 'Error opening /proc/meminfo';
my $line = (grep {/MemTotal:/} <MEMINFO>)[0];
close(MEMINFO);
print "Fetched line from /proc/meminfo of $line"
if $debug >= $LEVEL_TRACE;
my (undef, $amt, $unit) = split(/\s+/, $line);
if ($unit =~ /^kb$/i) { $amt *= $KB; }
elsif ($unit =~ /^mb$/i) { $amt *= $MB; }
elsif ($unit =~ /^gb$/i) { $amt *= $GB; }
else { die "Do not understand the units in /proc/meminfo of $unit"; }
print "Found memory size of $amt bytes from /proc/meminfo\n"
if $debug >= $LEVEL_DEBUG;
return $amt;
# then try the size of /proc/kcore if that's available
} elsif(-s '/proc/kcore') {
my @stat_ret = stat("/proc/kcore");
my $amt = $stat_ret[7];
print "Found memory size of $amt bytes from size of /proc/kcore\n"
if $debug >= $LEVEL_DEBUG;
return $amt;
# nothing else worked, just pick a default of 256 MB
} else {
print "Cannot figure out memory size, going with 256 MB\n"
if $debug >= $LEVEL_DEBUG;
return 256*$MB;
}
}
sub all_devices {
for my $path (@_) {
print "Checking potential device $path\n"
if $debug >= $LEVEL_TRACE;
if(! -b $path && ! -c $path) {
print "$path is not a device\n"
if $debug >= $LEVEL_DEBUG;
return 0;
}
}
return 1;
}
sub all_directories {
for my $path (@_) {
print "Checking potential directory $path\n"
if $debug >= $LEVEL_TRACE;
if(! -d $path) {
print "$path is not a directory\n"
if $debug >= $LEVEL_DEBUG;
return 0;
}
}
return 1;
}