common/tools/raptor/summarize.pl
changeset 374 52675b624b66
equal deleted inserted replaced
373:cc469b3fe547 374:52675b624b66
       
     1 # Copyright (c) 2009 Symbian Foundation Ltd
       
     2 # This component and the accompanying materials are made available
       
     3 # under the terms of the License "Eclipse Public License v1.0"
       
     4 # which accompanies this distribution, and is available
       
     5 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 #
       
     7 # Initial Contributors:
       
     8 # Symbian Foundation Ltd - initial contribution.
       
     9 #
       
    10 # Contributors:
       
    11 #
       
    12 # Description:
       
    13 # Generate an HTML summary of the Raptor build from the output of the raptor parser
       
    14 
       
    15 use strict;
       
    16 use FindBin;
       
    17 use lib $FindBin::Bin;
       
    18 use Getopt::Long;
       
    19 
       
    20 my $raptorbitsdir = 0;
       
    21 my $outputdir = '.';
       
    22 my $help = 0;
       
    23 GetOptions((
       
    24 	'raptorbitsdir=s' => \$raptorbitsdir,
       
    25 	'outputdir=s' => \$outputdir,
       
    26 	'help!' => \$help
       
    27 ));
       
    28 
       
    29 $help = 1 if (!$raptorbitsdir);
       
    30 
       
    31 if ($help)
       
    32 {
       
    33 	print "Generate an HTML summary of the Raptor build from a summary.csv file\n";
       
    34 	print "Usage: perl summarize.pl --raptorbitsdir=DIR [--outputdir=DIR]\n";
       
    35 	exit(0);
       
    36 }
       
    37 
       
    38 $outputdir = "$outputdir/html";
       
    39 
       
    40 system("rd /S /Q $outputdir") if (-d $outputdir);
       
    41 mkdir ($outputdir);
       
    42 
       
    43 my $raptor_errors = {};
       
    44 my $raptor_warnings = {};
       
    45 my $raptor_unreciped = {};
       
    46 my $general_failures_num_by_severity = {};
       
    47 my $general_failures_by_category_severity = {};
       
    48 my $recipe_failures_num_by_severity = {};
       
    49 my $recipe_failures_by_package_severity = {};
       
    50 #my $severities = {};
       
    51 my @severities = ('critical', 'major', 'minor', 'unknown');
       
    52 
       
    53 # READ SUMMARY.CSV FILE
       
    54 my $csv_file = "$raptorbitsdir/summary.csv";
       
    55 my $csv_linenum = 0;
       
    56 open(CSV, $csv_file);
       
    57 while(<CSV>)
       
    58 {
       
    59 	$csv_linenum ++;
       
    60 	my $line = $_;
       
    61 	
       
    62 	if ($line =~ /([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)/)
       
    63 	{
       
    64 		my $failure = {};
       
    65 		$failure->{category} = $1;
       
    66 		$failure->{subcategory} = $2;
       
    67 		$failure->{severity} = $3;
       
    68 		$failure->{config} = $4;
       
    69 		$failure->{component} = $5;
       
    70 		$failure->{phase} = $6;
       
    71 		$failure->{recipe} = $7;
       
    72 		$failure->{file} = $8;
       
    73 		$failure->{linenum} = $9;
       
    74 		
       
    75 		my $failure_package = '';
       
    76 		
       
    77 		if (!$failure->{category})
       
    78 		{
       
    79 			print "WARNING: summary line without a category at $csv_file line $csv_linenum. Skipping\n";
       
    80 			next;
       
    81 		}
       
    82 		
       
    83 		if ($failure->{category} =~ m,^recipe_failure$,i and !$failure->{component})
       
    84 		{
       
    85 			print "WARNING: recipe_failure with component field empty at $csv_file line $csv_linenum. Skipping\n";
       
    86 			next;
       
    87 		}
       
    88 		if ($failure->{component})
       
    89 		{
       
    90 			if ($failure->{component} =~ m,/((os|mw|app|tools|ostools|adaptation)/[^/]*),)
       
    91 			{
       
    92 				$failure_package = $1;
       
    93 			}
       
    94 			else
       
    95 			{
       
    96 				print "WARNING: summary line with wrong component path at $csv_file line $csv_linenum. Skipping\n";
       
    97 				next;
       
    98 			}
       
    99 		}
       
   100 		
       
   101 		$failure->{subcategory} = 'uncategorized' if (!$failure->{subcategory});
       
   102 		$failure->{severity} = 'unknown' if (!$failure->{severity});
       
   103 		
       
   104 		# populate severities dynamically.
       
   105 		#$severities->{$failure->{severity}} = 1;
       
   106 		
       
   107 		# put failure items into their category container
       
   108 		if ($failure->{category} =~ /^raptor_(error|warning|unreciped)$/i)
       
   109 		{
       
   110 			$general_failures_num_by_severity->{$failure->{category}} = {} if (!defined $general_failures_num_by_severity->{$failure->{category}});
       
   111 			my $general_failure = $general_failures_num_by_severity->{$failure->{category}};
       
   112 			
       
   113 			if (!defined $general_failure->{$failure->{severity}})
       
   114 			{
       
   115 				$general_failure->{$failure->{severity}} = 1;
       
   116 			}
       
   117 			else
       
   118 			{
       
   119 				$general_failure->{$failure->{severity}} ++;
       
   120 			}
       
   121 			
       
   122 			$general_failures_by_category_severity->{$failure->{category}} = {} if (!defined $general_failures_by_category_severity->{$failure->{category}});
       
   123 			$general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}} = [] if (!defined $general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}});
       
   124 			push(@{$general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}}}, $failure);
       
   125 		}
       
   126 		elsif ($failure->{category} =~ /^recipe_failure$/i)
       
   127 		{
       
   128 			$recipe_failures_num_by_severity->{$failure_package} = {} if (!defined $recipe_failures_num_by_severity->{$failure_package});
       
   129 			my $package_failure = $recipe_failures_num_by_severity->{$failure_package};
       
   130 			
       
   131 			if (!defined $package_failure->{$failure->{severity}})
       
   132 			{
       
   133 				$package_failure->{$failure->{severity}} = 1;
       
   134 			}
       
   135 			else
       
   136 			{
       
   137 				$package_failure->{$failure->{severity}} ++;
       
   138 			}
       
   139 			
       
   140 			$recipe_failures_by_package_severity->{$failure_package} = {} if (!defined $recipe_failures_by_package_severity->{$failure_package});
       
   141 			$recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}} = [] if (!defined $recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}});
       
   142 			push(@{$recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}}}, $failure);
       
   143 		}
       
   144 	}
       
   145 	else
       
   146 	{
       
   147 		print "WARNING: line does not match expected format at $csv_file line $csv_linenum. Skipping\n";
       
   148 	}
       
   149 }
       
   150 close(CSV);
       
   151 
       
   152 # PRINT HTML SUMMARY
       
   153 my $aggregated_html = "$outputdir/index.html";
       
   154 open(AGGREGATED, ">$aggregated_html");
       
   155 print AGGREGATED "RAPTOR BUILD SUMMARY<br/>\n";
       
   156 
       
   157 print AGGREGATED "<br/>GENERAL FAILURES<br/>\n";
       
   158 print AGGREGATED "<table border='1'>\n";
       
   159 my $tableheader = "<tr><th>category</th>";
       
   160 for (@severities) { $tableheader .= "<th>$_</th>"; }
       
   161 $tableheader .= "</tr>";
       
   162 print AGGREGATED "$tableheader\n";
       
   163 for my $category (keys %{$general_failures_num_by_severity})
       
   164 {
       
   165 	print_category_specific_summary($category, $general_failures_by_category_severity->{$category});
       
   166 	my $categoryline = "<tr><td><a href='$category.html'>$category</a></td>";
       
   167 	for (@severities)
       
   168 	{
       
   169 		my $failuresbyseverity = 0;
       
   170 		$failuresbyseverity = $general_failures_num_by_severity->{$category}->{$_} if (defined $general_failures_num_by_severity->{$category}->{$_});
       
   171 		$categoryline .= "<td>$failuresbyseverity</td>";
       
   172 	}
       
   173 	$categoryline .= "</tr>";
       
   174 	print AGGREGATED "$categoryline\n";
       
   175 }
       
   176 print AGGREGATED "</table>\n";
       
   177 print AGGREGATED "<br/>\n";
       
   178 
       
   179 print AGGREGATED "<br/>PACKGE-SPECIFIC FAILURES<br/>\n";
       
   180 print AGGREGATED "<table border='1'>\n";
       
   181 $tableheader = "<tr><th>package</th>";
       
   182 for (@severities) { $tableheader .= "<th>$_</th>"; }
       
   183 $tableheader .= "</tr>";
       
   184 print AGGREGATED "$tableheader\n";
       
   185 for my $package (keys %{$recipe_failures_num_by_severity})
       
   186 {
       
   187 	print_package_specific_summary($package, $recipe_failures_by_package_severity->{$package});
       
   188 	my $packagesummaryhtml = $package;
       
   189 	$packagesummaryhtml =~ s,/,_,;
       
   190 	$packagesummaryhtml .= ".html";
       
   191 	my $packageline = "<tr><td><a href='$packagesummaryhtml'>$package</a></td>";
       
   192 	for (@severities)
       
   193 	{
       
   194 		my $failuresbyseverity = 0;
       
   195 		$failuresbyseverity = $recipe_failures_num_by_severity->{$package}->{$_} if (defined $recipe_failures_num_by_severity->{$package}->{$_});
       
   196 		$packageline .= "<td>$failuresbyseverity</td>";
       
   197 	}
       
   198 	$packageline .= "</tr>";
       
   199 	print AGGREGATED "$packageline\n";
       
   200 }
       
   201 print AGGREGATED "</table>\n";
       
   202 close(AGGREGATED);
       
   203 
       
   204 translate_detail_files_to_html();
       
   205 
       
   206 
       
   207 sub print_category_specific_summary
       
   208 {
       
   209 	my ($category, $failures_by_severity) = @_;
       
   210 	
       
   211 	my $filenamebase = $category;
       
   212 	$filenamebase =~ s,/,_,;
       
   213 	
       
   214 	open(SPECIFIC, ">$outputdir/$filenamebase.html");
       
   215 	print SPECIFIC "FAILURES FOR CATEGORY $category<br/>\n";
       
   216 		
       
   217 	for my $severity (@severities)
       
   218 	{
       
   219 		if (defined $failures_by_severity->{$severity})
       
   220 		{
       
   221 			print SPECIFIC "<br/>".uc($severity)."<br/>\n";
       
   222 			print SPECIFIC "<table border='1'>\n";
       
   223 			# $subcategory, $severity, $component, $phase, $recipe, $file, $line
       
   224 			my $tableheader = "<tr><th>category</th><th>configuration</th><th>log snippet</th></tr>";
       
   225 			print SPECIFIC "$tableheader\n";
       
   226 			
       
   227 			for my $failure (@{$failures_by_severity->{$severity}})
       
   228 			{
       
   229 				my $failureline = "<tr><td>$failure->{subcategory}</td>";
       
   230 				$failureline .= "<td>$failure->{config}</td>";
       
   231 				$failureline .= "<td><a href='$filenamebase\_failures.html#failure_item_$failure->{linenum}'>item $failure->{linenum}</a></td>";
       
   232 				$failureline .= "</tr>";
       
   233 				print SPECIFIC "$failureline\n";
       
   234 			}
       
   235 			
       
   236 			print SPECIFIC "</table>\n";
       
   237 			print SPECIFIC "<br/>\n";
       
   238 		}
       
   239 	}
       
   240 	
       
   241 	close(SPECIFIC);
       
   242 }
       
   243 
       
   244 sub print_package_specific_summary
       
   245 {
       
   246 	my ($package, $failures_by_severity) = @_;
       
   247 	
       
   248 	my $filenamebase = $package;
       
   249 	$filenamebase =~ s,/,_,;
       
   250 	
       
   251 	open(SPECIFIC, ">$outputdir/$filenamebase.html");
       
   252 	print SPECIFIC "FAILURES FOR PACKAGE $package<br/>\n";
       
   253 		
       
   254 	for my $severity (@severities)
       
   255 	{
       
   256 		if (defined $failures_by_severity->{$severity})
       
   257 		{
       
   258 			print SPECIFIC "<br/>".uc($severity)."<br/>\n";
       
   259 			print SPECIFIC "<table border='1'>\n";
       
   260 			# $subcategory, $severity, $component, $phase, $recipe, $file, $line
       
   261 			my $tableheader = "<tr><th>category</th><th>configuration</th><th>component</th><th>phase</th><th>recipe</th><th>log snippet</th></tr>";
       
   262 			print SPECIFIC "$tableheader\n";
       
   263 			
       
   264 			for my $failure (@{$failures_by_severity->{$severity}})
       
   265 			{
       
   266 				my $failureline = "<tr><td>$failure->{subcategory}</td>";
       
   267 				$failureline .= "<td>$failure->{config}</td>";
       
   268 				$failureline .= "<td>$failure->{component}</td>";
       
   269 				$failureline .= "<td>$failure->{phase}</td>";
       
   270 				$failureline .= "<td>$failure->{recipe}</td>";
       
   271 				$failureline .= "<td><a href='$filenamebase\_failures.html#failure_item_$failure->{linenum}'>item $failure->{linenum}</a></td>";
       
   272 				$failureline .= "</tr>";
       
   273 				print SPECIFIC "$failureline\n";
       
   274 			}
       
   275 			
       
   276 			print SPECIFIC "</table>\n";
       
   277 			print SPECIFIC "<br/>\n";
       
   278 		}
       
   279 	}
       
   280 	
       
   281 	close(SPECIFIC);
       
   282 }
       
   283 
       
   284 sub translate_detail_files_to_html
       
   285 {
       
   286 	opendir(DIR, $raptorbitsdir);
       
   287 	my @failurefiles = readdir(DIR);
       
   288 	closedir(DIR);	
       
   289 	@failurefiles = grep(/\.txt$/, @failurefiles);
       
   290 	
       
   291 	for my $file (@failurefiles)
       
   292 	{
       
   293 		$file =~ /(.*)\.txt$/;
       
   294 		my $filenamebase = $1;
       
   295 		
       
   296 		my $filecontent = '';
       
   297 		open(FILE, "$raptorbitsdir/$file");
       
   298 		{
       
   299 			local $/=undef;
       
   300 			$filecontent = <FILE>;
       
   301 		}
       
   302 		close(FILE);
       
   303 		
       
   304 		$filecontent =~ s,---(failure_item_\d+)---,<a name="$1">---$1---</a>,g;
       
   305 		$filecontent = "<pre>$filecontent</pre>";
       
   306 		
       
   307 		open(FILE, ">$outputdir/$filenamebase\_failures.html");
       
   308 		print FILE $filecontent;
       
   309 		close(FILE);
       
   310 	}
       
   311 }