--------------------------------------------------------------------------- @--- Callsites: 2 --------------------------------------------------------- --------------------------------------------------------------------------- ID Lev File/Address Line Parent_Funct MPI_Call 1 0 0x8048ad5 [unknown] Reduce 2 0 0x8048a3b [unknown] Bcast --------------------------------------------------------------------------- @--- Aggregate Time (top twenty, descending, milliseconds) ---------------- --------------------------------------------------------------------------- Call Site Time App% MPI% COV Bcast 2 9.5 24.71 65.75 0.59 Reduce 1 4.95 12.87 34.25 1.35 --------------------------------------------------------------------------- #### #!/usr/bin/perl -w package Parser; use strict; sub new { bless {}; } sub add { my $self = shift; my $hash = shift; push @{$self->{parsers}}, $hash; } sub parse { my $self = shift; my $file = shift; open FILE,'<',$file || die "Can't open $file"; while() { foreach my $p (@{$self->{parsers}}) { if(/$p->{start}/ ... /$p->{end}/) { $p->{process}($_) unless (/$p->{start}/ || /$p->{end}/); } } } close FILE; } 1; sub parse1 { my $text = shift; print "Into parse1\n"; print $text; } sub parse2 { my $text = shift; print "Into parse2\n"; print $text; } my $p = Parser::new(); $p->add({ start => "^ ID Lev File/Address", end => "---", process => \&parse1}); $p->add({ start => "^Call *Site *Time *App", end => "---", process => \&parse2}); $p->parse($file); #### Into parse2 ID Lev File/Address Line Parent_Funct MPI_Call Into parse1 1 0 0x8048ad5 [unknown] Reduce Into parse2 1 0 0x8048ad5 [unknown] Reduce Into parse1 2 0 0x8048a3b [unknown] Bcast Into parse2 2 0 0x8048a3b [unknown] Bcast Into parse1 Bcast 2 20 35.85 64.45 0.76 Into parse2 Bcast 2 20 35.85 64.45 0.76 Into parse1 Reduce 1 11 19.78 35.55 1.31 Into parse2 Reduce 1 11 19.78 35.55 1.31