Whamcloud - gitweb
b=21829 fix broken llobdstat and add a counter parameter
authorBrian J. Murrell <brian@sun.com>
Tue, 30 Mar 2010 18:40:39 +0000 (11:40 -0700)
committerRobert Read <rread@sun.com>
Tue, 30 Mar 2010 18:40:39 +0000 (11:40 -0700)
Need to make sure we limit the search for OBD stats files to the obdfilter
subdirectory of "/proc/fs/lustre".
Add a counter argument to limit the number of items returned when using the
interval parameter.
Fix lots of whitespace atrocities as well as better format some of the code.

i=cliff
i=wangyb

lustre/ChangeLog
lustre/utils/llobdstat

index 9856522..a8c165f 100644 (file)
@@ -12,6 +12,11 @@ tbd  Sun Microsystems, Inc.
        * Recommended e2fsprogs version: 1.41.6.sun1
        * Note that reiserfs quotas are disabled on SLES 10 in this kernel.
 
        * Recommended e2fsprogs version: 1.41.6.sun1
        * Note that reiserfs quotas are disabled on SLES 10 in this kernel.
 
+Severity   : normal
+Bugzilla   : 21829
+Description: llobdstat fix and enhancement
+Details    : add a counter to set a limit to how many samples will be returned
+            fix a wildcard in the path to limit to obdfilter stats only
 
 Severity   : normal
 Bugzilla   : 21259
 
 Severity   : normal
 Bugzilla   : 21259
index 300c9d8..9c9cf5a 100644 (file)
@@ -1,5 +1,5 @@
 #!/usr/bin/perl
 #!/usr/bin/perl
-# llobdstat is a utility that parses obdfilter statistics files 
+# llobdstat is a utility that parses obdfilter statistics files
 # found at proc/fs/lustre/<ostname>/stats.
 # It is mainly useful to watch the statistics change over time.
 
 # found at proc/fs/lustre/<ostname>/stats.
 # It is mainly useful to watch the statistics change over time.
 
@@ -10,7 +10,7 @@ my $obdstats = "stats";
 
 sub usage()
 {
 
 sub usage()
 {
-    print STDERR "Usage: $pname <ost_name> [<interval>]\n";
+    print STDERR "Usage: $pname <ost_name> [<interval> [<count>}]\n";
     print STDERR "where  ost_name  : ost name under $defaultpath/obdfilter\n";
     print STDERR "       interval  : sample interaval in seconds\n";
     print STDERR "example: $pname lustre-OST0000 2\n";
     print STDERR "where  ost_name  : ost name under $defaultpath/obdfilter\n";
     print STDERR "       interval  : sample interaval in seconds\n";
     print STDERR "example: $pname lustre-OST0000 2\n";
@@ -20,30 +20,34 @@ sub usage()
 
 my $statspath = "None";
 my $interval = 0;
 
 my $statspath = "None";
 my $interval = 0;
+my $counter = undef;
 
 
-if (($#ARGV < 0) || ($#ARGV > 1)) {
+if (($#ARGV < 0) || ($#ARGV > 2)) {
     usage();
 } else {
     if ( $ARGV[0] =~ /help$/ ) {
     usage();
 } else {
     if ( $ARGV[0] =~ /help$/ ) {
-       usage();
+        usage();
     }
     if ( -f $ARGV[0] ) {
     }
     if ( -f $ARGV[0] ) {
-       $statspath = $ARGV[0];
+        $statspath = $ARGV[0];
     } elsif ( -f "$ARGV[0]/$obdstats" ) {
     } elsif ( -f "$ARGV[0]/$obdstats" ) {
-       $statspath = "$ARGV[0]/$obdstats";
+        $statspath = "$ARGV[0]/$obdstats";
     } else {
     } else {
-       my $st = `ls $defaultpath/*/$ARGV[0]/$obdstats 2> /dev/null`;
-       chop $st;
-       if ( -f "$st" ) {
-           $statspath = $st;
-       }
+        my $st = `ls $defaultpath/obdfilter/$ARGV[0]/$obdstats 2> /dev/null`;
+        chop $st;
+        if ( -f "$st" ) {
+            $statspath = $st;
+        }
     }
     if ( $statspath =~ /^None$/ ) {
         die "Cannot locate stat file for: $ARGV[0]\n";
     }
     }
     if ( $statspath =~ /^None$/ ) {
         die "Cannot locate stat file for: $ARGV[0]\n";
     }
-    if ($#ARGV == 1) {
-       $interval = $ARGV[1];
-    } 
+    if ($#ARGV > 0) {
+        $interval = $ARGV[1];
+    }
+    if ($#ARGV > 1) {
+        $counter = $ARGV[2];
+    }
 }
 
 print "$pname on $statspath\n";
 }
 
 print "$pname on $statspath\n";
@@ -52,10 +56,12 @@ my %cur;
 my %last;
 my $mhz = 0;
 
 my %last;
 my $mhz = 0;
 
-#Removed some statstics like open, close that obdfilter don't contains.
-#To add statistics parameters one need to specify parameter names in below declarations in same sequence. 
-my ($read_bytes, $write_bytes, $create, $destroy, $statfs, $punch, $snapshot_time) = 
-    ("read_bytes", "write_bytes", "create", "destroy", "statfs", "punch", "snapshot_time"); 
+# Removed some statstics like open, close that obdfilter doesn't contain.
+# To add statistics parameters one needs to specify parameter names in the
+# below declarations in the same sequence.
+my ($read_bytes, $write_bytes, $create, $destroy, $statfs, $punch,
+    $snapshot_time) = ("read_bytes", "write_bytes", "create", "destroy",
+                       "statfs", "punch", "snapshot_time");
 
 my @extinfo = ($create, $destroy, $statfs, $punch);
 my %shortname = ($create => "cx", $destroy => "dx", $statfs => "st", $punch => "pu");
 
 my @extinfo = ($create, $destroy, $statfs, $punch);
 my %shortname = ($create => "cx", $destroy => "dx", $statfs => "st", $punch => "pu");
@@ -65,106 +71,113 @@ sub get_cpumhz()
     my $cpu_freq;
     my $itc_freq; # On Itanium systems use this
     if (open(CPUINFO, "/proc/cpuinfo")==0) {
     my $cpu_freq;
     my $itc_freq; # On Itanium systems use this
     if (open(CPUINFO, "/proc/cpuinfo")==0) {
-       return;
+        return;
     }
     while (<CPUINFO>) {
     }
     while (<CPUINFO>) {
-       if (/^cpu MHz\s+:\s*([\d\.]+)/) { $cpu_freq=$1; }
-       elsif (/^itc MHz\s+:\s*([\d\.]+)/) { $itc_freq=$1; }
+        if (/^cpu MHz\s+:\s*([\d\.]+)/) { $cpu_freq=$1; }
+        elsif (/^itc MHz\s+:\s*([\d\.]+)/) { $itc_freq=$1; }
+    }
+    if (defined($itc_freq)) {
+        $mhz = $itc_freq;
+    } elsif (defined($cpu_freq)) {
+        $mhz = $cpu_freq;
+    } else {
+        $mhz = 1;
     }
     }
-    if (defined($itc_freq)) { $mhz = $itc_freq; }
-    elsif (defined($cpu_freq)) { $mhz = $cpu_freq; }
-    else { $mhz = 1; }
     close CPUINFO;
 }
 
 get_cpumhz();
 print "Processor counters run at $mhz MHz\n";
 
     close CPUINFO;
 }
 
 get_cpumhz();
 print "Processor counters run at $mhz MHz\n";
 
-# readstats subroutine reads statistics from obdfilter stats file.
-# This subroutine gets called after every interval specified by user.     
+# read statistics from obdfilter stats file.
+# This subroutine gets called after every interval specified by user.
 sub readstat()
 {
 sub readstat()
 {
-       my $prevcount;
-       my @iodata;
-
-       seek STATS, 0, 0;
-       while (<STATS>) {
-               chop;
-#              ($name, $cumulcount, $samples, $unit, $min, $max, $sum, $sumsquare) 
-               @iodata = split(/\s+/, $_);
-               my $name = $iodata[0];
-
-               $prevcount = $cur{$name};
-               if (defined($prevcount)) {
-                       $last{$name} = $prevcount; 
-               } 
-               if ($name =~ /^read_bytes$/ || $name =~ /^write_bytes$/) {
-                       $cur{$name} = $iodata[6];
-               }
-               elsif ($name =~ /^snapshot_time$/) {
-#                      $cumulcount =~ /(\d+)/;
-                       $cur{$name} = $iodata[1];
-               }
-               else {
-                       $cur{$name} = $iodata[1];
-               }
-       }
+    my $prevcount;
+    my @iodata;
+
+    seek STATS, 0, 0;
+    while (<STATS>) {
+        chop;
+#        ($name, $cumulcount, $samples, $unit, $min, $max, $sum, $sumsquare)
+        @iodata = split(/\s+/, $_);
+        my $name = $iodata[0];
+
+        $prevcount = $cur{$name};
+        if (defined($prevcount)) {
+            $last{$name} = $prevcount;
+        }
+        if ($name =~ /^read_bytes$/ || $name =~ /^write_bytes$/) {
+            $cur{$name} = $iodata[6];
+        }
+        elsif ($name =~ /^snapshot_time$/) {
+#            $cumulcount =~ /(\d+)/;
+            $cur{$name} = $iodata[1];
+        } else {
+            $cur{$name} = $iodata[1];
+        }
+    }
 }
 }
-# process_stats subroutine processes stats information read from obdfilter stats file.
-# This subroutine gets called after every interval specified by user.     
+
+# process stats information read from obdfilter stats file.
+# This subroutine gets called after every interval specified by user.
 sub process_stats()
 {
 sub process_stats()
 {
-       my $delta;
-       my $data;
-       my $last_time = $last{$snapshot_time};
-       if (!defined($last_time)) {
-               printf "Read: %-g, Write: %-g, create/destroy: %-g/%-g, stat: %-g, punch: %-g\n",
-               $cur{$read_bytes}, $cur{$write_bytes},  
-               $cur{$create}, $cur{$destroy}, 
-               $cur{$statfs}, $cur{$punch}; 
-                if ($interval) {
-                        print "[NOTE: cx: create, dx: destroy, st: statfs, pu: punch ]\n\n";
-                        print "Timestamp   Read-delta  ReadRate  Write-delta  WriteRate\n";
-                        print "--------------------------------------------------------\n";
-                }
-       }
-       else {
-               my $timespan = $cur{$snapshot_time} - $last{$snapshot_time};
-               my $rdelta = $cur{$read_bytes} - $last{$read_bytes};
-               my $rrate = ($rdelta) / ($timespan * ( 1 << 20 ));
-               my $wdelta = $cur{$write_bytes} - $last{$write_bytes};
-               my $wrate = ($wdelta) / ($timespan * ( 1 << 20 ));
-               $rdelta = ($rdelta) / (1024 * 1024);
-               $wdelta = ($wdelta) / (1024 * 1024);
-               # This print repeats after every interval.
-               printf "%10lu  %6.2fMB  %6.2fMB/s   %6.2fMB  %6.2fMB/s",
-                       $cur{$snapshot_time}, $rdelta, $rrate, $wdelta, $wrate;
-
-               $delta = $cur{$getattr} - $last{$getattr};
-               if ( $delta != 0 ) {
-                       $rdelta = int ($delta/$timespan);
-                       print " ga:$delta,$rdelta/s";
-               }
-               
-               for $data ( @extinfo ) {
-                       $delta = $cur{$data} - $last{$data};
-                       if ($delta != 0) {
-                               print " $shortname{$data}:$delta";
-                       }
-               }
-               print "\n";
-               $| = 1;
-       }
+    my $delta;
+    my $data;
+    my $last_time = $last{$snapshot_time};
+    if (!defined($last_time)) {
+        printf "Read: %-g, Write: %-g, create/destroy: %-g/%-g, stat: %-g, punch: %-g\n",
+        $cur{$read_bytes}, $cur{$write_bytes},
+        $cur{$create}, $cur{$destroy},
+        $cur{$statfs}, $cur{$punch};
+        if ($interval) {
+            print "[NOTE: cx: create, dx: destroy, st: statfs, pu: punch ]\n\n";
+            print "Timestamp   Read-delta  ReadRate  Write-delta  WriteRate\n";
+            print "--------------------------------------------------------\n";
+        }
+    } else {
+        my $timespan = $cur{$snapshot_time} - $last{$snapshot_time};
+        my $rdelta = $cur{$read_bytes} - $last{$read_bytes};
+        my $rrate = ($rdelta) / ($timespan * ( 1 << 20 ));
+        my $wdelta = $cur{$write_bytes} - $last{$write_bytes};
+        my $wrate = ($wdelta) / ($timespan * ( 1 << 20 ));
+        $rdelta = ($rdelta) / (1024 * 1024);
+        $wdelta = ($wdelta) / (1024 * 1024);
+        # This print repeats after every interval.
+        printf "%10lu  %6.2fMB  %6.2fMB/s   %6.2fMB  %6.2fMB/s",
+               $cur{$snapshot_time}, $rdelta, $rrate, $wdelta, $wrate;
+
+        $delta = $cur{$getattr} - $last{$getattr};
+        if ( $delta != 0 ) {
+            $rdelta = int ($delta/$timespan);
+            print " ga:$delta,$rdelta/s";
+        }
+
+        for $data ( @extinfo ) {
+            $delta = $cur{$data} - $last{$data};
+            if ($delta != 0) {
+                print " $shortname{$data}:$delta";
+            }
+        }
+        print "\n";
+        $| = 1;
+    }
 }
 }
+
 #Open the obdfilter stat file with STATS
 open(STATS, $statspath) || die "Cannot open $statspath: $!\n";
 do {
 #Open the obdfilter stat file with STATS
 open(STATS, $statspath) || die "Cannot open $statspath: $!\n";
 do {
-       readstat();             # read the statistics from stat file.
-       process_stats();        
-       if ($interval) {        
-               sleep($interval); 
-               %last = %cur;
-       }
-} while ($interval);   # Repeat the statistics printing after every "interval" specified in command line.
+    # read the statistics from stat file.
+    readstat();
+    process_stats();
+    if ($interval) {
+        sleep($interval);
+        %last = %cur;
+    }
+    # Repeat the statistics printing after every "interval" specified in
+    # command line, up to counter times, if specified
+} while ($interval && (defined($counter) ? $counter-- > 0 : 1));
 close STATS;
 # llobdfilter.pl ends here.
 close STATS;
 # llobdfilter.pl ends here.