On Tue, 6 Mar 2007, Uwe Steinmann wrote:
> Thanks for the improved script.
> I made a simple test, but didn't get the expected results.
>
> ibook:/usr/share/doc/linux-wlan-ng# cat /sys/block/hda/hda2/stat
> 285 570 0 0
>
> ibook:/usr/share/doc/linux-wlan-ng# /tmp/linux26diskaccess.pl -r hda2
>
> ibook:/usr/share/doc/linux-wlan-ng# /tmp/linux26diskaccess.pl -rb hda2
> 285
> ibook:/usr/share/doc/linux-wlan-ng# /tmp/linux26diskaccess.pl -w hda2
> 570
> ibook:/usr/share/doc/linux-wlan-ng# /tmp/linux26diskaccess.pl -wb hda2
> 0
>
> Why doesn't '/tmp/linux26diskaccess.pl -r hda2' return '0'?
I see. It's because the partition data start with spaces and thus the
results are shifted (I only check the disk-wide results here). So all we
have to do is strip the leading spaces. I'm attaching the updated
script.
--
Francois Gouget <[EMAIL PROTECTED]> http://fgouget.free.fr/
We are Pentium of Borg. You will be approximated. Division is futile.
#!/usr/bin/perl
use strict;
### config variables
my $blockdev = "/sys/block";
### argument processing
if (@ARGV != 2 or
$ARGV[0] !~ /^-[rw]b?$/ or
$ARGV[1] !~ /^\w+(?:\d+)?$/)
{
print "U\n";
print "\n";
print "$0 [-r|-rb|-w|-wb] <dev(N)>\n";
print "\n";
print "Reports disk I/O statistics counters for use as a NetMRG test script.\n";
print "\n";
print "Options:\n";
print " -r Report the number of read operations\n";
print " -rb Report the number of read blocks\n";
print " -w Report the number of write operations\n";
print " -wb Report the number of written blocks\n";
print " dev(n) Is a relative block device or partition name.\n";
print " For instance hda, hda1 or md0\n";
print "\n";
exit 1;
}
### figure out device/partitions
my ($hd, $partition);
if ($ARGV[1] =~ /^(hd\w)\d+$/)
{
$partition = $ARGV[1];
$hd = $1;
} # end if hd has a partition
else
{
$hd = $ARGV[1];
} # end else hd is just the drive
### read info from system block
# read the data from the correct path
my $path = "$blockdev/$hd";
$path .= "/$partition" if ($partition ne "");
$path .= "/stat";
open(STAT, $path) || die ("U\nERROR: couldn't open $path\n\n");
my $line = <STAT>;
close(STAT);
chomp($line);
my ($read, $readb, $write, $writeb);
if ($partition eq "")
{
($read, $readb, $write, $writeb)=(split /\s+/, $line)[0, 2, 4, 6];
}
else
{
($read, $readb, $write, $writeb)=split /\s+/, $line;
}
### output the data
if ($ARGV[0] eq "-r")
{
print "$read\n";
}
elsif ($ARGV[0] eq "-w")
{
print "$write\n";
}
elsif ($ARGV[0] eq "-rb")
{
print "$readb\n";
}
elsif ($ARGV[0] eq "-wb")
{
print "$writeb\n";
}