common/tools/raptor/uh.pl
changeset 764 d00048f1b036
child 791 9054e820b1e6
equal deleted inserted replaced
763:5fdd5e70280d 764:d00048f1b036
       
     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 # Unite and HTML-ize Raptor log files
       
    14 
       
    15 use strict;
       
    16 use FindBin;
       
    17 use lib $FindBin::Bin;
       
    18 use RaptorError;
       
    19 use RaptorWarning;
       
    20 use RaptorInfo;
       
    21 use RaptorUnreciped;
       
    22 use RaptorRecipe;
       
    23 
       
    24 use XML::SAX;
       
    25 use RaptorSAXHandler;
       
    26 use Getopt::Long;
       
    27 
       
    28 our $raptorbitsdir = 'raptorbits';
       
    29 our $basedir = '';
       
    30 my $outputdir = "html";
       
    31 our $raptor_config = 'dummy_config';
       
    32 our $current_log_file = '';
       
    33 my $help = 0;
       
    34 GetOptions((
       
    35 	'basedir=s' => \$basedir,
       
    36 	'help!' => \$help
       
    37 ));
       
    38 my @logfiles = @ARGV;
       
    39 
       
    40 $help = 1 if (!@logfiles);
       
    41 
       
    42 if ($help)
       
    43 {
       
    44 	print "Unite and HTML-ize Raptor log files.\n";
       
    45 	print "Usage: perl uh.pl [OPTIONS] FILE1 FILE2 ...\n";
       
    46 	print "where OPTIONS are:\n";
       
    47 	print "\t--basedir=DIR Generate output under DIR (defaults to current dir)\n";
       
    48 	exit(0);
       
    49 }
       
    50 
       
    51 if ($basedir)
       
    52 {
       
    53 	$raptorbitsdir = "$basedir/raptorbits";
       
    54 	$outputdir = "$basedir/html";
       
    55 }
       
    56 mkdir($basedir) if (!-d$basedir);
       
    57 
       
    58 system("rmdir /S /Q $raptorbitsdir") if (-d $raptorbitsdir);
       
    59 mkdir($raptorbitsdir);
       
    60 #print "Created dir $raptorbitsdir.\n";
       
    61 
       
    62 # create empty summary file anyway
       
    63 open(SUMMARY, ">$raptorbitsdir/summary.csv");
       
    64 close(SUMMARY);
       
    65 
       
    66 my $saxhandler = RaptorSAXHandler->new();
       
    67 $saxhandler->add_observer('RaptorError', $RaptorError::reset_status);
       
    68 $saxhandler->add_observer('RaptorWarning', $RaptorWarning::reset_status);
       
    69 $saxhandler->add_observer('RaptorInfo', $RaptorInfo::reset_status);
       
    70 $saxhandler->add_observer('RaptorUnreciped', $RaptorUnreciped::reset_status);
       
    71 $saxhandler->add_observer('RaptorRecipe', $RaptorRecipe::reset_status);
       
    72 
       
    73 my $parser = XML::SAX::ParserFactory->parser(Handler=>$saxhandler);
       
    74 for (@logfiles)
       
    75 {
       
    76 	print "Reading file: $_\n";
       
    77 	$current_log_file = $_;
       
    78 	$parser->parse_uri($_);
       
    79 }
       
    80 
       
    81 print "Generating HTML...\n";
       
    82 
       
    83 system("rd /S /Q $outputdir") if (-d $outputdir);
       
    84 mkdir ($outputdir);
       
    85 
       
    86 my $raptor_errors = {};
       
    87 my $raptor_warnings = {};
       
    88 my $raptor_unreciped = {};
       
    89 my $general_failures_num_by_severity = {};
       
    90 my $general_failures_by_category_severity = {};
       
    91 my $recipe_failures_num_by_severity = {};
       
    92 my $recipe_failures_by_package_severity = {};
       
    93 #my $severities = {};
       
    94 my @severities = ('critical', 'major', 'minor', 'unknown');
       
    95 
       
    96 # READ SUMMARY.CSV FILE
       
    97 my $csv_file = "$raptorbitsdir/summary.csv";
       
    98 my $csv_linenum = 0;
       
    99 open(CSV, $csv_file);
       
   100 while(<CSV>)
       
   101 {
       
   102 	$csv_linenum ++;
       
   103 	my $line = $_;
       
   104 	
       
   105 	if ($line =~ /([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)/)
       
   106 	{
       
   107 		my $failure = {};
       
   108 		$failure->{category} = $1;
       
   109 		$failure->{subcategory} = $2;
       
   110 		$failure->{severity} = $3;
       
   111 		$failure->{config} = $4;
       
   112 		$failure->{component} = $5;
       
   113 		$failure->{mmp} = $6;
       
   114 		$failure->{phase} = $7;
       
   115 		$failure->{recipe} = $8;
       
   116 		$failure->{file} = $9;
       
   117 		$failure->{linenum} = $10;
       
   118 		
       
   119 		my $failure_package = '';
       
   120 		
       
   121 		if (!$failure->{category})
       
   122 		{
       
   123 			print "WARNING: summary line without a category at $csv_file line $csv_linenum. Skipping\n";
       
   124 			next;
       
   125 		}
       
   126 		
       
   127 		if ($failure->{category} =~ m,^recipe_failure$,i and !$failure->{component})
       
   128 		{
       
   129 			print "WARNING: recipe_failure with component field empty at $csv_file line $csv_linenum. Skipping\n";
       
   130 			next;
       
   131 		}
       
   132 		if ($failure->{component})
       
   133 		{
       
   134 			if ($failure->{component} =~ m,/((os|mw|app|tools|ostools|adaptation)/[^/]*),)
       
   135 			{
       
   136 				$failure_package = $1;
       
   137 			}
       
   138 			else
       
   139 			{
       
   140 				print "WARNING: summary line with wrong component path at $csv_file line $csv_linenum. Skipping\n";
       
   141 				next;
       
   142 			}
       
   143 		}
       
   144 		
       
   145 		$failure->{subcategory} = 'uncategorized' if (!$failure->{subcategory});
       
   146 		$failure->{severity} = 'unknown' if (!$failure->{severity});
       
   147 		$failure->{mmp} = '-' if (!$failure->{mmp});
       
   148 		
       
   149 		# populate severities dynamically.
       
   150 		#$severities->{$failure->{severity}} = 1;
       
   151 		
       
   152 		# put failure items into their category container
       
   153 		if ($failure->{category} =~ /^raptor_(error|warning|unreciped)$/i)
       
   154 		{
       
   155 			$general_failures_num_by_severity->{$failure->{category}} = {} if (!defined $general_failures_num_by_severity->{$failure->{category}});
       
   156 			my $general_failure = $general_failures_num_by_severity->{$failure->{category}};
       
   157 			
       
   158 			if (!defined $general_failure->{$failure->{severity}})
       
   159 			{
       
   160 				$general_failure->{$failure->{severity}} = 1;
       
   161 			}
       
   162 			else
       
   163 			{
       
   164 				$general_failure->{$failure->{severity}} ++;
       
   165 			}
       
   166 			
       
   167 			$general_failures_by_category_severity->{$failure->{category}} = {} if (!defined $general_failures_by_category_severity->{$failure->{category}});
       
   168 			$general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}} = [] if (!defined $general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}});
       
   169 			push(@{$general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}}}, $failure);
       
   170 		}
       
   171 		elsif ($failure->{category} =~ /^recipe_failure$/i)
       
   172 		{
       
   173 			$recipe_failures_num_by_severity->{$failure_package} = {} if (!defined $recipe_failures_num_by_severity->{$failure_package});
       
   174 			my $package_failure = $recipe_failures_num_by_severity->{$failure_package};
       
   175 			
       
   176 			if (!defined $package_failure->{$failure->{severity}})
       
   177 			{
       
   178 				$package_failure->{$failure->{severity}} = 1;
       
   179 			}
       
   180 			else
       
   181 			{
       
   182 				$package_failure->{$failure->{severity}} ++;
       
   183 			}
       
   184 			
       
   185 			$recipe_failures_by_package_severity->{$failure_package} = {} if (!defined $recipe_failures_by_package_severity->{$failure_package});
       
   186 			$recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}} = [] if (!defined $recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}});
       
   187 			push(@{$recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}}}, $failure);
       
   188 		}
       
   189 	}
       
   190 	else
       
   191 	{
       
   192 		print "WARNING: line does not match expected format at $csv_file line $csv_linenum. Skipping\n";
       
   193 	}
       
   194 }
       
   195 close(CSV);
       
   196 
       
   197 # PRINT HTML SUMMARY
       
   198 my $aggregated_html = "$outputdir/index.html";
       
   199 open(AGGREGATED, ">$aggregated_html");
       
   200 print AGGREGATED "RAPTOR BUILD SUMMARY<br/>\n";
       
   201 
       
   202 print AGGREGATED "<br/>GENERAL FAILURES<br/>\n";
       
   203 print AGGREGATED "<table border='1'>\n";
       
   204 my $tableheader = "<tr><th>category</th>";
       
   205 for (@severities) { $tableheader .= "<th>$_</th>"; }
       
   206 $tableheader .= "</tr>";
       
   207 print AGGREGATED "$tableheader\n";
       
   208 for my $category (keys %{$general_failures_num_by_severity})
       
   209 {
       
   210 	print_category_specific_summary($category, $general_failures_by_category_severity->{$category});
       
   211 	my $categoryline = "<tr><td><a href='$category.html'>$category</a></td>";
       
   212 	for (@severities)
       
   213 	{
       
   214 		my $failuresbyseverity = 0;
       
   215 		$failuresbyseverity = $general_failures_num_by_severity->{$category}->{$_} if (defined $general_failures_num_by_severity->{$category}->{$_});
       
   216 		$categoryline .= "<td>$failuresbyseverity</td>";
       
   217 	}
       
   218 	$categoryline .= "</tr>";
       
   219 	print AGGREGATED "$categoryline\n";
       
   220 }
       
   221 print AGGREGATED "</table>\n";
       
   222 print AGGREGATED "<br/>\n";
       
   223 
       
   224 print AGGREGATED "<br/>PACKGE-SPECIFIC FAILURES<br/>\n";
       
   225 print AGGREGATED "<table border='1'>\n";
       
   226 $tableheader = "<tr><th>package</th>";
       
   227 for (@severities) { $tableheader .= "<th>$_</th>"; }
       
   228 $tableheader .= "</tr>";
       
   229 print AGGREGATED "$tableheader\n";
       
   230 for my $package (keys %{$recipe_failures_num_by_severity})
       
   231 {
       
   232 	print_package_specific_summary($package, $recipe_failures_by_package_severity->{$package});
       
   233 	my $packagesummaryhtml = $package;
       
   234 	$packagesummaryhtml =~ s,/,_,;
       
   235 	$packagesummaryhtml .= ".html";
       
   236 	my $packageline = "<tr><td><a href='$packagesummaryhtml'>$package</a></td>";
       
   237 	for (@severities)
       
   238 	{
       
   239 		my $failuresbyseverity = 0;
       
   240 		$failuresbyseverity = $recipe_failures_num_by_severity->{$package}->{$_} if (defined $recipe_failures_num_by_severity->{$package}->{$_});
       
   241 		$packageline .= "<td>$failuresbyseverity</td>";
       
   242 	}
       
   243 	$packageline .= "</tr>";
       
   244 	print AGGREGATED "$packageline\n";
       
   245 }
       
   246 print AGGREGATED "</table>\n";
       
   247 close(AGGREGATED);
       
   248 
       
   249 translate_detail_files_to_html();
       
   250 
       
   251 print "OK, done. Please open $outputdir/index.html.\n";
       
   252 
       
   253 
       
   254 sub print_category_specific_summary
       
   255 {
       
   256 	my ($category, $failures_by_severity) = @_;
       
   257 	
       
   258 	my $filenamebase = $category;
       
   259 	$filenamebase =~ s,/,_,;
       
   260 	
       
   261 	open(SPECIFIC, ">$outputdir/$filenamebase.html");
       
   262 	print SPECIFIC "FAILURES FOR CATEGORY $category<br/>\n";
       
   263 		
       
   264 	for my $severity (@severities)
       
   265 	{
       
   266 		if (defined $failures_by_severity->{$severity})
       
   267 		{
       
   268 			print SPECIFIC "<br/>".uc($severity)."<br/>\n";
       
   269 			print SPECIFIC "<table border='1'>\n";
       
   270 			# $subcategory, $severity, $mmp, $phase, $recipe, $file, $line
       
   271 			my $tableheader = "<tr><th>category</th><th>log file</th><th>log snippet</th></tr>";
       
   272 			print SPECIFIC "$tableheader\n";
       
   273 			
       
   274 			for my $failure (@{$failures_by_severity->{$severity}})
       
   275 			{
       
   276 				my $failureline = "<tr><td>$failure->{subcategory}</td>";
       
   277 				$failureline .= "<td>$failure->{config}</td>";
       
   278 				$failureline .= "<td><a href='$filenamebase\_failures.html#failure_item_$failure->{linenum}'>item $failure->{linenum}</a></td>";
       
   279 				$failureline .= "</tr>";
       
   280 				print SPECIFIC "$failureline\n";
       
   281 			}
       
   282 			
       
   283 			print SPECIFIC "</table>\n";
       
   284 			print SPECIFIC "<br/>\n";
       
   285 		}
       
   286 	}
       
   287 	
       
   288 	close(SPECIFIC);
       
   289 }
       
   290 
       
   291 sub print_package_specific_summary
       
   292 {
       
   293 	my ($package, $failures_by_severity) = @_;
       
   294 	
       
   295 	my $filenamebase = $package;
       
   296 	$filenamebase =~ s,/,_,;
       
   297 	
       
   298 	open(SPECIFIC, ">$outputdir/$filenamebase.html");
       
   299 	print SPECIFIC "FAILURES FOR PACKAGE $package<br/>\n";
       
   300 		
       
   301 	for my $severity (@severities)
       
   302 	{
       
   303 		if (defined $failures_by_severity->{$severity})
       
   304 		{
       
   305 			print SPECIFIC "<br/>".uc($severity)."<br/>\n";
       
   306 			print SPECIFIC "<table border='1'>\n";
       
   307 			# $subcategory, $severity, $mmp, $phase, $recipe, $file, $line
       
   308 			my $tableheader = "<tr><th>category</th><th>configuration</th><th>mmp</th><th>phase</th><th>recipe</th><th>log snippet</th></tr>";
       
   309 			print SPECIFIC "$tableheader\n";
       
   310 			
       
   311 			for my $failure (@{$failures_by_severity->{$severity}})
       
   312 			{
       
   313 				my $failureline = "<tr><td>$failure->{subcategory}</td>";
       
   314 				$failureline .= "<td>$failure->{config}</td>";
       
   315 				$failureline .= "<td>$failure->{mmp}</td>";
       
   316 				$failureline .= "<td>$failure->{phase}</td>";
       
   317 				$failureline .= "<td>$failure->{recipe}</td>";
       
   318 				$failureline .= "<td><a href='$filenamebase\_failures.html#failure_item_$failure->{linenum}'>item $failure->{linenum}</a></td>";
       
   319 				$failureline .= "</tr>";
       
   320 				print SPECIFIC "$failureline\n";
       
   321 			}
       
   322 			
       
   323 			print SPECIFIC "</table>\n";
       
   324 			print SPECIFIC "<br/>\n";
       
   325 		}
       
   326 	}
       
   327 	
       
   328 	close(SPECIFIC);
       
   329 }
       
   330 
       
   331 sub translate_detail_files_to_html
       
   332 {
       
   333 	opendir(DIR, $raptorbitsdir);
       
   334 	my @failurefiles = readdir(DIR);
       
   335 	closedir(DIR);	
       
   336 	@failurefiles = grep(/\.txt$/, @failurefiles);
       
   337 	
       
   338 	for my $file (@failurefiles)
       
   339 	{
       
   340 		$file =~ /(.*)\.txt$/;
       
   341 		my $filenamebase = $1;
       
   342 		
       
   343 		my $filecontent = '';
       
   344 		open(FILE, "$raptorbitsdir/$file");
       
   345 		{
       
   346 			local $/=undef;
       
   347 			$filecontent = <FILE>;
       
   348 		}
       
   349 		close(FILE);
       
   350 		
       
   351 		$filecontent =~ s,---(failure_item_\d+)---,<a name="$1">---$1---</a>,g;
       
   352 		$filecontent = "<pre>$filecontent</pre>";
       
   353 		
       
   354 		open(FILE, ">$outputdir/$filenamebase\_failures.html");
       
   355 		print FILE $filecontent;
       
   356 		close(FILE);
       
   357 	}
       
   358 }