common/tools/analysis/analyse_components.pl
changeset 131 1f3285cd5668
child 145 430173497dd4
equal deleted inserted replaced
130:22e8d3918a31 131:1f3285cd5668
       
     1 #!/usr/bin/perl
       
     2 
       
     3 # Copyright (c) 2009 Symbian Foundation Ltd
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Symbian Foundation Ltd - initial contribution.
       
    11 # 
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # Adds info form a file to a CSV
       
    16 
       
    17 use strict;
       
    18 use HTTP::Date;
       
    19 
       
    20 my $srccsvfile = shift @ARGV;
       
    21 my $whatlogfile = shift @ARGV;
       
    22 my @sysmodelfiles = @ARGV;
       
    23 
       
    24 if(! -e $srccsvfile)
       
    25 {
       
    26   die "cannot find $srccsvfile\n";
       
    27 }
       
    28 
       
    29 if(! -e $whatlogfile)
       
    30 {
       
    31   die "cannot find $whatlogfile\n";
       
    32 }
       
    33 
       
    34 foreach my $sysmodelfile (@sysmodelfiles)
       
    35 {
       
    36 	if(! -e $sysmodelfile)
       
    37 	{
       
    38 	  die "cannot find $sysmodelfile\n";
       
    39 	}
       
    40 }
       
    41 
       
    42 # Search for timestamp threshold in whatlog file
       
    43 # It corresponds to the first timestamp for which the target was genuinly rebuilt
       
    44 # Every target that has a timestamp below is considered as not rebuilt properly
       
    45 open(WHATLOG,"<$whatlogfile") or die "Error: Couldn't open $whatlogfile\n";
       
    46 my %bldtimes;
       
    47 my $timestampLimit = 0;
       
    48 while (my $line = <WHATLOG>)
       
    49 {
       
    50 	if($line =~ m/,\s*(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\s*$/){
       
    51 		$bldtimes{str2time($1)} = $1;
       
    52 	}
       
    53 }
       
    54 my $previoustime = 0;
       
    55 foreach my $decimaltime (sort(keys %bldtimes))
       
    56 {
       
    57   if ($previoustime == 0) {$previoustime = $decimaltime;}
       
    58   if ( ($decimaltime - (30*60) ) > $previoustime )
       
    59   {
       
    60 	$timestampLimit = $bldtimes{$decimaltime};
       
    61 	print "Timestamp Threshold found: $timestampLimit\n";
       
    62 	last;
       
    63   }
       
    64 }
       
    65 close(WHATLOG);
       
    66 
       
    67 # Create the Package List from sources.csv
       
    68 # And assign license type
       
    69 # Everything that is not found FCL or MCL are considered RND
       
    70 my @pkgList;
       
    71 open(SRCCSV,"<$srccsvfile") or die "Error: Couldn't open $srccsvfile\n";
       
    72 while (my $line = <SRCCSV>)
       
    73 {
       
    74 	if ($line =~ m/^source,/) {next;}
       
    75 	if ($line =~ m/^([^,]+),\/([^,]+),/){
       
    76 		my $pkglicense = $1;
       
    77 		my $pkgpath=$2;
       
    78 		if ($pkglicense =~ m/^[^,]+\/(\w+)\/(MCL|FCL)\/\w+/i) {$pkglicense = uc($1);}
       
    79 		else {$pkglicense = "RND";}
       
    80 		push @pkgList, "$pkgpath,$pkglicense";
       
    81 	}
       
    82 }
       
    83 print "Number of Packages to analyse: $#pkgList\n";
       
    84 close(SRCCSV);
       
    85 
       
    86 # Create System Definition Component List
       
    87 my @sysdefcomplist;
       
    88 foreach my $sysdeffile (@sysmodelfiles)
       
    89 {
       
    90 	open(SYSDEF,"<$sysdeffile") or die "Error: Couldn't open $sysdeffile\n";
       
    91 	while (my $line = <SYSDEF>)
       
    92 	{
       
    93 		if ($line =~ m/(\s*)<!--\s*(<.*?>)\s*-->/) {next;}
       
    94 		if ($line =~m/bldFile=\"([^"]*)"/i)
       
    95 		{
       
    96 			#push @sysdefcomplist, &getComponentInfo($1);
       
    97 			push @sysdefcomplist, $1;
       
    98 		}
       
    99 	}
       
   100 	close(SYSDEF);
       
   101 }
       
   102 
       
   103 # For each package in the list, process the whatlog to verify if it's built clean
       
   104 # And build the final summary log
       
   105 open(WHATLOG,"<$whatlogfile") or die "Error: Couldn't open $whatlogfile\n";
       
   106 my @whatlogs = <WHATLOG>;
       
   107 my @outputList;
       
   108 foreach my $package (@pkgList)
       
   109 {
       
   110 	my $corruptbldinfcount = 0;
       
   111 	# Write a CSV entry for pkgpath, license
       
   112 	my $pkgline = "$package";
       
   113 	# Search whatlog and match -> extract bldfiles -> clean vs not_clean
       
   114 	$package =~ s/,.*//;
       
   115 	foreach my $whatlog (@whatlogs)
       
   116 	{	
       
   117 		if ($whatlog =~ /^[^,]+,($package\/[^,]+),[^,]*,[^,]*,[^,]*,[^,]*(,([^,]*))?(,([^,]*))?/)
       
   118 		{
       
   119 			my $bldfilepath = $1;
       
   120 			my $status = $3;
       
   121 			my $timestamp = $5;
       
   122 			if (($status =~ /fail/i) || ($status eq "") ||
       
   123 				(($status =~ /untouched/i) and ($timestamp ne "") and (str2time($timestamp) < str2time($timestampLimit))) )
       
   124 			{
       
   125 				chomp($status);chomp($timestamp);
       
   126 				$status = "KO ($status - $timestamp)";
       
   127 			}
       
   128 			else {$status = "OK"; }
       
   129 			#if ($status =~ /KO/ ) {print "$pkgline,$bldfilepath,$status\n";}
       
   130 			push @outputList, "$pkgline,$bldfilepath,$status\n";
       
   131 		}
       
   132 	}
       
   133 }
       
   134 
       
   135 # Write the Full Analysis log
       
   136 open(OUTPUT,">PkgComponentAnalysisFull.csv") or die "Error: Couldn't open PkgComponentAnalysisFull.csv for writing\n";
       
   137 print OUTPUT "Package Path (from Sources.csv), License, BldFile (from whatlog), Status\n"; 
       
   138 print OUTPUT @outputList;
       
   139 close(OUTPUT);
       
   140 
       
   141 # Keep only uniq bldfile in the list
       
   142 # And calculate final status
       
   143 #my @uniq = keys %{{ map { $_ => 1 } @outputList }};
       
   144 my %seen = ();
       
   145 my $value; my $remains; my $status;
       
   146 foreach my $item (@outputList) {
       
   147 	$item =~ /^([^,]+,[^,]+,([^,]+)),([^,]+)/;
       
   148 	$remains = $1;
       
   149 	$value = $2;
       
   150 	$status = $3;
       
   151 	chomp($status);
       
   152 	if ($status ne "OK") {$status = "KO"};
       
   153     if ($seen{$value}) 
       
   154 	{
       
   155 		$seen{$value} =~ /^[^,]+,([^,]+)/;
       
   156 		my $currentstatus = $1;
       
   157 		if ($currentstatus eq "KO")
       
   158 		{
       
   159 			$status = "KO";
       
   160 		}
       
   161 	}
       
   162 	$seen{$value} = "$remains,$status\n";
       
   163 }
       
   164 my @uniq = values(%seen);
       
   165 
       
   166 # Prepend system model info (block name, component name)
       
   167 foreach my $line (@uniq)
       
   168 {
       
   169 	if ($line =~ /^[^,]+,[^,]+,([^,]+),/)
       
   170 	{
       
   171 		my $bldfile = $1;
       
   172 		my $sysmodelinfo = &getSysModelInfo($bldfile);
       
   173 		$line = "$sysmodelinfo, $line";
       
   174 	}
       
   175 }
       
   176 
       
   177 
       
   178 # Write the summary log
       
   179 open(OUTPUT,">PkgComponentAnalysisSummary.csv") or die "Error: Couldn't open PkgComponentAnalysisSummary.csv for writing\n";
       
   180 print OUTPUT "Package Name, Component Name, Package Path (from Sources.csv), License, BldFile (from whatlog), Status\n"; 
       
   181 print OUTPUT @uniq;
       
   182 close(OUTPUT);
       
   183 close(WHATLOG);
       
   184 
       
   185 # Status statistics
       
   186 my $componentOkCount = 0;
       
   187 my $componentKoCount = 0;
       
   188 my $totalcompCount = 0;
       
   189 foreach my $line (@uniq)
       
   190 {
       
   191 	if ($line =~ /OK$/) {$componentOkCount++;}
       
   192 	else {$componentKoCount++;}
       
   193 	$totalcompCount++;
       
   194 }
       
   195 print "Total number of Components: $totalcompCount\n";
       
   196 print "Number of Components Cleanly rebuilt: $componentOkCount\n";
       
   197 print "Number of Components not rebuilt properly: $componentKoCount\n";
       
   198 
       
   199 
       
   200 
       
   201 sub getSysModelInfo
       
   202 {
       
   203 	my $bldfilepath = shift;
       
   204 	
       
   205 	# remove prepending sf dir, and trailing bld.inf
       
   206 	$bldfilepath =~ s/^sf\///;
       
   207 	$bldfilepath =~ s/\/bld.inf$//i;
       
   208 	#print "Looking for bldfile path: $bldfilepath ...\n";
       
   209 	
       
   210 	my $packageName = "";
       
   211 	my $componentName = "";
       
   212 	
       
   213 	MODEL_LOOP:	foreach my $sysmodelfile (@sysmodelfiles)
       
   214 	{
       
   215 		open(SYSFILE,"<$sysmodelfile") or die "Error: Couldn't open $sysmodelfile\n";
       
   216 		my @model_lines = <SYSFILE>;
       
   217 		foreach my $line (@model_lines)
       
   218 		{
       
   219 			$line =~ s/\\/\//g;
       
   220 			
       
   221 			if ($line =~ m/bldFile=\"$bldfilepath"/i)
       
   222 			{
       
   223 				#print "Component $packageName/$componentName found in model $sysmodelfile\n"; 
       
   224 				last MODEL_LOOP;
       
   225 			}
       
   226 			elsif ($line =~ m/<component/)
       
   227 			{
       
   228 				$line =~m/\slong-name="([^"]*)"/;
       
   229 				$componentName = $1;
       
   230 			}
       
   231 			elsif ($line=~ m/<\/component/)
       
   232 			{
       
   233 				$componentName = "";
       
   234 			}
       
   235 			elsif ($line =~ m/<block/)
       
   236 			{
       
   237 				$line =~m/\slong-name="([^"]*)"/;
       
   238 				$packageName = $1;
       
   239 			}
       
   240 			elsif ($line=~ m/<\/block/)
       
   241 			{
       
   242 				$packageName = "";				
       
   243 			}
       
   244 		}
       
   245 		close(SYSFILE);
       
   246 	}
       
   247 	
       
   248 	# One mode file remains open if match found
       
   249 	if ($packageName ne "") { close(SYSFILE)}
       
   250 	
       
   251 	return "$packageName, $componentName";
       
   252 }