/[Frey]/trunk/lib/Frey/Shell/sar.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/Shell/sar.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 867 by dpavlin, Tue Dec 16 22:35:05 2008 UTC revision 877 by dpavlin, Thu Dec 18 13:03:42 2008 UTC
# Line 15  has sar_command => ( Line 15  has sar_command => (
15  sub as_sponge {  sub as_sponge {
16          my ($self,$opts) = @_;          my ($self,$opts) = @_;
17    
18          $opts ||= '-u';          $opts ||= $self->sar_command !~ m{-\w} ? '-u' : '';
19    
20          my @rows;          my @rows;
21          my @name;          my @name;
22    
23            my @pos;
24    
25          my $cmd = $self->sar_command . ' ' . $opts;          my $cmd = $self->sar_command . ' ' . $opts;
26          warn "# cmd: $cmd";          warn "# cmd: $cmd";
27    
# Line 28  sub as_sponge { Line 30  sub as_sponge {
30          open(my $fh, '-|', $cmd) || die "can't open pipe to $cmd $!";          open(my $fh, '-|', $cmd) || die "can't open pipe to $cmd $!";
31          while(<$fh>) {          while(<$fh>) {
32                  chomp;                  chomp;
33    
34                  if ( m{(\d\d)/(\d\d)/(\d\d\d\d)$} ) {                  if ( m{(\d\d)/(\d\d)/(\d\d\d\d)$} ) {
35                          $date = "$3-$1-$2T";                          $date = "$3-$1-$2T";
36                          warn "# date $date";                          warn "# date $date";
37                            next;
38                  }                  }
39    
40                  next unless m{^\d\d:\d\d:\d\d};                  next unless m{^\d\d:\d\d:\d\d};
41                  my @l = split(/\s+/,$_);  
42                  if ( $l[$#l] =~ m{_([^_]+)_} ) {                  my @l;
43                          warn "# header $1 ",join('|', @l);  
44                          $l[0] =~ s{00:00:01}{time} || die "can't locate time column in header";                  if ( s{_([^_]+)_$}{} ) {
45                          delete( $l[$#l] );                          my $line = $_;
46                            warn "# header $1 from $line";
47                            while ( $line =~ s{^(\s*\S+)}{} ) {
48                                    push @pos, length($1);
49                            }
50                            warn "# pos: ", $self->dump( @pos );
51                            my @l = split(/\s+/,$_);
52                            warn "# l: ", $self->dump( @l );
53                            $l[0] =~ s{\d\d:\d\d:\d\d}{time} || die "can't locate time column in header";
54                          @name = @l;                          @name = @l;
55                          next;                          next;
56                    } elsif ( @pos ) {
57                            my @cols = split(/\s+/,$_);
58                            if ( $#cols < $#name ) {
59                                    warn "# skip too short line: '$_'";
60                                    next;
61                            }
62    
63                            # nothing works well with kernel resource format value/sz
64                            s{(\d+)/\d+}{$1}sg if $cmd =~ m{-v};
65    
66                            my $start = 0;
67                            foreach my $col ( 0 .. $#pos ) {
68                                    my $len = $pos[$col];
69                                    my $v = substr($_, $start, $len);
70                                    $v =~ s/^\s+//g;
71                                    push @l, $v;
72                                    $start += $len;
73                            }
74                    } else {
75                            die "got: $_ before header!";
76                  }                  }
77    
78                  $l[0] = $date . $l[0];                  $l[0] = $date . $l[0];

Legend:
Removed from v.867  
changed lines
  Added in v.877

  ViewVC Help
Powered by ViewVC 1.1.26