summaryrefslogtreecommitdiffstats
path: root/bin/iostats
blob: d55d550b63292fe0528defa1c54f963453ded7e0 (plain)
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
#!/usr/bin/perl

# Usage: pipe the output of Linux's `strace' program into the stdin of
# this command, and the output of this command into gnuplot.

my $filename = shift || "tstab2.h5";
my $total = 0;
my %What;			# What{pos}{nbytes}{r|w} = naccesses

while (<>) {
   if (!defined $fd) {
      if (/^open\("(.*?)".*=\s+(\d+)/ && $1 eq $filename) {
	 $fd = $2;
	 $pos = 0;
      }
   } elsif (/^close\((\d+)/ && $1==$fd) {
      $fd = undef;
   } elsif (/^lseek\((\d+), -?\d+,.*= (\d+)/ &&
	    $1==$fd && $2>=0) {
      $pos = $2;
   } elsif (/^lseek\((\d+),/ && $1==$fd) {
      die $_;
   } elsif (/^write\((\d+), ".*?"(\.\.\.)?, \d+\)\s*= (\d+)/ &&
	    $1==$fd && $3>=0) {
      my $nbytes = $3;
      $What{$pos}{$nbytes}{w}++;
      printf "%d %d\n", $total, $pos;
      $pos += $nbytes;
      $total += $nbytes;
   } elsif (/^write\((\d+),/ && $1==$fd) {
      die $_;
   } elsif (/^read\((\d+), ".*?"(\.\.\.)?, \d+\)\s*= (\d+)/ &&
	    $1==$fd && $3>=0) {
      my $nbytes = $3;
      $What{$pos}{$nbytes}{r}++;
      printf "%d %d\n", $total, $pos;
      $pos += $nbytes;
      $total += $nbytes;
   } elsif (/^read\((\d+),/ && $1==$fd) {
      die $_;
   }
}
     

print "="x36, "\n"; 
  printf "%8s %8s %8s %8s\n","Position","NBytes","NReads","NWrites";
for $pos (sort {$a<=>$b} keys %What) {
  for $nbytes (sort {$a<=>$b} keys %{$What{$pos}}) {
    printf "%8d %8d %8d %8d\n", $pos, $nbytes,
           $What{$pos}{$nbytes}{r},
           $What{$pos}{$nbytes}{w};
  }
}