2 # llobdstat is a utility that parses obdfilter statistics files
3 # found at proc/fs/lustre/<ostname>/stats.
4 # It is mainly useful to watch the statistics change over time.
8 my $defaultpath = "/proc/fs/lustre";
9 my $obdstats = "stats";
13 print STDERR "Usage: $pname <ost_name> [<interval> [<count>}]\n";
14 print STDERR "where ost_name : ost name under $defaultpath/obdfilter\n";
15 print STDERR " interval : sample interaval in seconds\n";
16 print STDERR "example: $pname lustre-OST0000 2\n";
17 print STDERR "Use CTRL + C to stop statistics printing\n";
21 my $statspath = "None";
25 if (($#ARGV < 0) || ($#ARGV > 2)) {
28 if ( $ARGV[0] =~ /help$/ ) {
32 $statspath = $ARGV[0];
33 } elsif ( -f "$ARGV[0]/$obdstats" ) {
34 $statspath = "$ARGV[0]/$obdstats";
36 my $st = "$defaultpath/obdfilter/$ARGV[0]/$obdstats";
41 if ( $statspath =~ /^None$/ ) {
42 die "Cannot locate stat file for: $ARGV[0]\n";
52 print "$pname on $statspath\n";
58 # Removed some statstics like open, close that obdfilter doesn't contain.
59 # To add statistics parameters one needs to specify parameter names in the
60 # below declarations in the same sequence.
61 my ($read_bytes, $write_bytes, $create, $destroy, $statfs, $punch,
62 $snapshot_time) = ("read_bytes", "write_bytes", "create", "destroy",
63 "statfs", "punch", "snapshot_time");
65 my @extinfo = ($create, $destroy, $statfs, $punch);
66 my %shortname = ($create => "cx", $destroy => "dx", $statfs => "st", $punch => "pu");
71 my $itc_freq; # On Itanium systems use this
72 if (open(CPUINFO, "/proc/cpuinfo")==0) {
76 if (/^cpu MHz\s+:\s*([\d\.]+)/) { $cpu_freq=$1; }
77 elsif (/^itc MHz\s+:\s*([\d\.]+)/) { $itc_freq=$1; }
79 if (defined($itc_freq)) {
81 } elsif (defined($cpu_freq)) {
90 print "Processor counters run at $mhz MHz\n";
92 # read statistics from obdfilter stats file.
93 # This subroutine gets called after every interval specified by user.
102 # ($name, $cumulcount, $samples, $unit, $min, $max, $sum, $sumsquare)
103 @iodata = split(/\s+/, $_);
104 my $name = $iodata[0];
106 $prevcount = $cur{$name};
107 if (defined($prevcount)) {
108 $last{$name} = $prevcount;
110 if ($name =~ /^read_bytes$/ || $name =~ /^write_bytes$/) {
111 $cur{$name} = $iodata[6];
113 elsif ($name =~ /^snapshot_time$/) {
114 # $cumulcount =~ /(\d+)/;
115 $cur{$name} = $iodata[1];
117 $cur{$name} = $iodata[1];
122 # process stats information read from obdfilter stats file.
123 # This subroutine gets called after every interval specified by user.
128 my $last_time = $last{$snapshot_time};
129 if (!defined($last_time)) {
130 printf "Read: %-g, Write: %-g, create/destroy: %-g/%-g, stat: %-g, punch: %-g\n",
131 $cur{$read_bytes}, $cur{$write_bytes},
132 $cur{$create}, $cur{$destroy},
133 $cur{$statfs}, $cur{$punch};
135 print "[NOTE: cx: create, dx: destroy, st: statfs, pu: punch ]\n\n";
136 print "Timestamp Read-delta ReadRate Write-delta WriteRate\n";
137 print "--------------------------------------------------------\n";
140 my $timespan = $cur{$snapshot_time} - $last{$snapshot_time};
141 my $rdelta = $cur{$read_bytes} - $last{$read_bytes};
142 my $rrate = ($rdelta) / ($timespan * ( 1 << 20 ));
143 my $wdelta = $cur{$write_bytes} - $last{$write_bytes};
144 my $wrate = ($wdelta) / ($timespan * ( 1 << 20 ));
145 $rdelta = ($rdelta) / (1024 * 1024);
146 $wdelta = ($wdelta) / (1024 * 1024);
147 # This print repeats after every interval.
148 printf "%10lu %6.2fMB %6.2fMB/s %6.2fMB %6.2fMB/s",
149 $cur{$snapshot_time}, $rdelta, $rrate, $wdelta, $wrate;
151 $delta = $cur{$getattr} - $last{$getattr};
153 $rdelta = int ($delta/$timespan);
154 print " ga:$delta,$rdelta/s";
157 for $data ( @extinfo ) {
158 $delta = $cur{$data} - $last{$data};
160 print " $shortname{$data}:$delta";
168 #Open the obdfilter stat file with STATS
169 open(STATS, $statspath) || die "Cannot open $statspath: $!\n";
171 # read the statistics from stat file.
178 # Repeat the statistics printing after every "interval" specified in
179 # command line, up to counter times, if specified
180 } while ($interval && (defined($counter) ? $counter-- > 0 : 1));
182 # llobdfilter.pl ends here.