buildstats.py 4.2 KB

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