common/tools/analysis/yarp.pl
changeset 143 f2ac8aeae6bb
parent 138 d3c5dd0ae0b0
child 203 011f16c9778b
equal deleted inserted replaced
142:247e27021cd0 143:f2ac8aeae6bb
       
     1 #!/usr/bin/perl
       
     2 # Copyright (c) 2009 Symbian Foundation Ltd
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Symbian Foundation Ltd - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 # Matt Davies <mattd@symbian.org>
       
    13 #
       
    14 # Description:
       
    15 # YARP - Yet Another Recipe Parser
       
    16 # This tool parses Raptor logs looking for failures, and writes a CSV file of the results
       
    17 #
       
    18 # Usage:
       
    19 # perl yarp.pl <logfile> <csvfile>
       
    20 #
       
    21 # Notes:
       
    22 # Currently it won't tell you any info about why it fails, with the exception of arm licence issues.
       
    23 # It also uses a lot of memory, so while there is a subroutine for doing multiple files, it's not used, and is out of date.
       
    24 # Writing output to a file is hacked in, so it's not too pretty.
       
    25 
       
    26 use strict;
       
    27 use XML::Simple;
       
    28 use Data::Dumper;
       
    29 
       
    30 my @header = qw(line layer component name armlicence platform phase code bldinf mmp target source);
       
    31 
       
    32 main();
       
    33 
       
    34 
       
    35 sub main()
       
    36 {
       
    37   my $filename = shift @ARGV;
       
    38   my $output = shift @ARGV;
       
    39   open(OUT,">$output") or die "Coudn't open $output\n";
       
    40   foreach my $key (@header)
       
    41   {
       
    42     print OUT $key.",";
       
    43   } 
       
    44   print OUT "\n";
       
    45 
       
    46   parsefile($filename);
       
    47   close OUT;
       
    48 }
       
    49 sub scandir()
       
    50 {
       
    51   my $path = shift @ARGV;
       
    52   my @files = glob($path."/*compile.log");
       
    53    
       
    54   foreach my $filename (@files)
       
    55   {
       
    56 #    print $filename."\n";
       
    57     parsefile($filename);
       
    58   }  
       
    59 }
       
    60   
       
    61 sub  parsefile($filename)
       
    62 {
       
    63     my $filename = shift;
       
    64 #    print "Scanning $filename\n";
       
    65     open(FILE,"<$filename") or die "Couldn't open filename\n";
       
    66     my $recipe;
       
    67     my %attempts;
       
    68     my %licenceattempts;
       
    69     my $counter = 0;
       
    70     my $licence = 0;
       
    71     while( my $line = <FILE>)
       
    72     {
       
    73       ++$counter;
       
    74       if($line =~ m/^<recipe\s+(\S.+)>/)
       
    75       {
       
    76         $recipe = XMLin($line."</recipe>");
       
    77         $recipe->{'line'} = $counter;
       
    78 #        print Dumper($recipe);
       
    79       }
       
    80       elsif($line =~ m/<\/recipe>/)
       
    81       {
       
    82         if(defined $recipe)
       
    83         {         
       
    84 #          if($recipe->{'exit'} !~ m/ok/)
       
    85           if($recipe->{'exit'} =~ m/failed/)
       
    86           {
       
    87 #            if($recipe->{'target'} =~ m/\S:epoc32\//i) 
       
    88 #               && $recipe->{'target'} !~ m/\S:epoc32\/build/i)
       
    89             {
       
    90               DumpRecipe($recipe);
       
    91 
       
    92             }
       
    93           }         
       
    94         $recipe = undef;
       
    95         }
       
    96       }
       
    97       elsif($line =~ m/Error:\sC3397E:\s/) #ARM Licence error code...
       
    98       {
       
    99         ++$licence;
       
   100         if(defined $recipe)
       
   101         {
       
   102           $recipe->{'armlicence'} = 1;
       
   103         }  
       
   104       }
       
   105       elsif($line =~ m/(<status\s.+\/>)/)
       
   106       {
       
   107         my $status = XMLin($1);
       
   108         if(defined $recipe)
       
   109         {
       
   110           $recipe->{'exit'} = $status->{'exit'};
       
   111           $recipe->{'attempt'} = $status->{'attempt'};
       
   112           if(defined $status->{'code'})
       
   113           {
       
   114             $recipe->{'code'} = $status->{'code'}; 
       
   115           }
       
   116           if(!defined $attempts{$status->{'attempt'}})
       
   117             {
       
   118               $attempts{$status->{'attempt'}} = 0;
       
   119             }
       
   120           $attempts{$status->{'attempt'}} = $attempts{$status->{'attempt'}} + 1;
       
   121           if(defined $recipe->{'armlicence'})
       
   122           {
       
   123             if(!defined $licenceattempts{$status->{'attempt'}})
       
   124               {
       
   125                 $licenceattempts{$status->{'attempt'}} = 0;
       
   126               }
       
   127             $licenceattempts{$status->{'attempt'}} = $licenceattempts{$status->{'attempt'}} + 1;
       
   128           }               
       
   129         }      
       
   130       }
       
   131     }
       
   132   close FILE;
       
   133   print OUT "\n\nSummaries\n\n";
       
   134   foreach my $attempt (sort keys %attempts)
       
   135   {
       
   136     print OUT "Overall attempts: $attempt,".$attempts{$attempt}.",\n";
       
   137   }
       
   138   foreach my $attempt (sort keys %licenceattempts)
       
   139   {
       
   140     print OUT "ARM Licence Fail attempts: $attempt,".$licenceattempts{$attempt}.",\n";
       
   141   }
       
   142   print OUT "Total ARM Licence failures,$licence\n";
       
   143   
       
   144    
       
   145 }
       
   146 
       
   147 sub DumpRecipe($)
       
   148 {
       
   149   my $recipe = shift;
       
   150   foreach my $key (@header)
       
   151   {
       
   152     if(defined $recipe->{$key})
       
   153     {
       
   154       print OUT $recipe->{$key};
       
   155     }
       
   156     print OUT ",";
       
   157   }
       
   158   print OUT "\n";            
       
   159   #print Dumper($recipe);
       
   160 
       
   161 }