sbsv2/raptor/bin/buildstats.py
changeset 0 044383f39525
child 3 e1eecf4d390d
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 #
       
     2 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     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 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 # Generate some useful statistics from a Raptor build log
       
    16 #
       
    17 
       
    18 import sys
       
    19 from  optparse import OptionParser
       
    20 from raptorlog import *
       
    21 import os
       
    22 from stat import *
       
    23 import time
       
    24 
       
    25 def genstats(file, logitems, logdate):
       
    26 	bytecount=0.0
       
    27 	lastbytecount=0.0
       
    28 	print """<?xml version="1.0" encoding="UTF-8"?>
       
    29        <stats xmlns="http://symbian.com/2007/xml/build/raptor/stats"
       
    30        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       
    31        xsi:schemaLocation="http://symbian.com/2007/xml/build/raptor/stats http://symbian.com/2007/xml/build/raptor/stats1_0.xsd">
       
    32 	"""
       
    33 
       
    34 	if S_ISREG(os.stat(file.name)[ST_MODE]) > 0:
       
    35 	 	totalbytes = os.stat(file.name)[ST_SIZE]+0.0
       
    36 	else:
       
    37 		totalbytes=0.0
       
    38 
       
    39 	print "<build log='%s' size='%9.0f' date='%s'>" % (file.name,totalbytes,logdate)
       
    40 	for l in file.xreadlines():
       
    41 		if totalbytes > 0.0:
       
    42 			bytecount += len(l)
       
    43 			if (bytecount-lastbytecount)/totalbytes > 0.05:
       
    44 				lastbytecount = bytecount
       
    45 				sys.stderr.write("%3.0f %%" % ((bytecount/totalbytes)*100.0))
       
    46 
       
    47 		for i in logitems:
       
    48 			i.match(l)
       
    49 
       
    50 	for i in logitems:
       
    51 		print i.xml()+"\n"
       
    52 		
       
    53 	print "</build>"
       
    54 	print "</stats>"
       
    55 
       
    56 
       
    57 
       
    58 ## Command Line Interface ####################################################
       
    59 
       
    60 parser = OptionParser(prog = "buildstats",
       
    61 	usage = "%prog [-h | options] [<file>]")
       
    62 
       
    63 parser.add_option("-k", "--keep", default = False,
       
    64 	 action="store_true", dest="keep", help="Retain matched log lines and display them.") 
       
    65 parser.add_option("-d", "--logdate", default = None,
       
    66 	 action="store", dest="logdate", help="Specify the date on which the log was started (yyyymmdd).") 
       
    67 
       
    68 (options, args) = parser.parse_args()
       
    69 
       
    70 logname="stdin"
       
    71 if len(args) > 0:
       
    72 	logname=args[0]
       
    73 	file = open(logname,"r")
       
    74 	if options.logdate != None:
       
    75 		logdate = options.logdate
       
    76 	else:
       
    77 		logdate = time.strftime("%Y%m%d",time.localtime(os.stat(file.name)[ST_CTIME]))
       
    78 else:
       
    79 	file = sys.stdin
       
    80 	logdate = time.strftime("%Y%m%d")
       
    81 
       
    82 
       
    83 if options.keep != False:
       
    84 	LogItem.keep = True
       
    85 
       
    86 
       
    87 
       
    88 logitems = [ 
       
    89 	LogItem("compile attempt", "<compile.*>"), 
       
    90 	LogItem("compile success", "<buildstat [^<]*name='compile'[^<]*/>"), 
       
    91 	LogItem("compile fail", "<buildstat [^<]*name='failed_compile'[^<]*/>"), 
       
    92 	LogItem('link attempt','<link>'), 
       
    93 	LogItem("link success", "<buildstat [^<]*name='link'[^<]*/>"), 
       
    94 	LogItem("link fail", "<buildstat [^<]*name=.failed_link.[^<]*/>"), 
       
    95 	LogItem('postlink attempt','<postlink.*>'), 
       
    96 	LogItem("postlink success", "<buildstat [^<]*name=.postlink[^<]*/>"), 
       
    97 	LogItem("postlink fail", "<buildstat [^<]*name=.failed_postlink.[^<]*/>"), 
       
    98 	LogItem('flmcalls', '<flm'), 
       
    99 	LogItem('e32 flmcalls', "<flm +name=[\"']e32abiv2[\"'].* type=[\"'](?!implib)"),
       
   100 	#LogItem('mmp_processed', "<parsing[ \t]*file='.*\.[Mm][Mm][Pp]'.*>"),
       
   101 	#LogItem('bldinf_processed', "Processing bld.inf:"),
       
   102 	LogItem('armar','armar'),
       
   103 	LogItem("failed stringtable export", "<buildstat [^<]*name=.failed_exportstringtableheader.[^<]*/>"), 
       
   104 	LogItem("failed template extension makefile", "<buildstat [^<]*name=.failed_tem.[^<]*/>"), 
       
   105 	LogItem("make error",'^make: \*\*\*.*$', True),
       
   106 	LogItem("make no rule",'^make: \*\*\*.* No rule to make target.*$', True),
       
   107 	LogItem("raptor error",'^ERROR: raptor:*$', True),
       
   108 	LogItem("armcc/armcpp error",'^.*line [0-9]+:.*Error: *#[0-9]+.*$', True),
       
   109 	LogItem("gcc/gcc-cpp error",'^[^ \t]+:[0-9]+:[0-9]+ .+:.+$', True),
       
   110 	LogItem("armlink error",'^Error: *L[0-9A-F]+:.*$', True),
       
   111 	LogItem("Resource File error",'[\t ]*Error:.*cannot open source input file.*\.[Rr][Ss][Gg]\".*$', True),
       
   112 	LogItem("String Table error",'[\t ]*Error:.*cannot open source input file.*[Ss]tr[^ ]*\.h\".*$', True),
       
   113 	LogItem("Armcc license fail",'^.*Error: C3397E: Cannot obtain license for Compiler.*'),
       
   114 	LogItem("Armlink license fail",'^.*Error: ......: Cannot obtain license for .*ink.*')
       
   115 	] 
       
   116 
       
   117 genstats(file,logitems,logdate)
       
   118 
       
   119 if file != sys.stdin:
       
   120 	file.close()