statcollate.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. # statcollate
  16. #
  17. """
  18. Produce output for a graphing program or spreadsheet from
  19. the statistic logs produced by buildstats.py from Raptor logs.
  20. e.g. by analysing several logs we can see how
  21. "number of successful compiles" improves over time.
  22. """
  23. import sys
  24. from optparse import OptionParser
  25. import os
  26. import xml.dom.minidom
  27. from stat import *
  28. namespace = "http://symbian.com/2007/xml/build/raptor/stats"
  29. class StatsFail(Exception):
  30. pass
  31. def pullStats(statnames, file):
  32. """Load a Statistics document and pull stats for a graph"""
  33. # try to read and parse the XML file
  34. try:
  35. dom = xml.dom.minidom.parse(file)
  36. except Exception,e: # a whole bag of exceptions can be raised here
  37. print "pullStats: %s" % str(e)
  38. raise StatsFail
  39. # <build> is always the root element
  40. stats = dom.documentElement
  41. objects = []
  42. build = stats.childNodes[1]
  43. # create a Data Model object from each sub-element
  44. output = {}
  45. output['date'] = build.getAttribute('date')
  46. #print "statnames %s\n" % str(statnames) #test
  47. for child in build.childNodes:
  48. if child.namespaceURI == namespace \
  49. and child.nodeType == child.ELEMENT_NODE \
  50. and child.hasAttributes():
  51. #print "child node %s\n" % child.getAttribute('name') #test
  52. name = child.getAttribute('name')
  53. if name in statnames:
  54. #print "1" #test
  55. output[name] = child.getAttribute('count')
  56. return output
  57. statnames = ['postlink success', 'compile success', 'compile fail']
  58. ## Command Line Interface ################################################
  59. parser = OptionParser(prog = "statgraph",
  60. usage = "%prog [-h | options] [<statsfile>] [[<statsfile>] ...]")
  61. (options, args) = parser.parse_args()
  62. statfilename = "stdin"
  63. table = sys.stdout
  64. print >> table, 'Date,', # add 'Date' in front of names
  65. comma=""
  66. for name in statnames:
  67. print >> table, comma+name, #! this order is not the order in dictionary
  68. comma=', '
  69. #print 'test,', #test
  70. print >> table, ""
  71. if len(args) > 0:
  72. for statfilename in args:
  73. sys.__stderr__.write("Loading %s\n" % statfilename)
  74. file = open(statfilename, "r")
  75. try:
  76. stats = pullStats(statnames, file)
  77. except StatsFail,e:
  78. sys.__stderr__.write("Can't process file %s\n" % statfilename)
  79. sys.exit(1)
  80. #print stats.items() # test
  81. file.close()
  82. comma=""
  83. print >> table, stats['date'] + ",",
  84. for name in statnames:
  85. print >> table, comma+stats[name],
  86. comma=', '
  87. #print 'test,', # test
  88. print >> table, ""
  89. else:
  90. sys.stderr.write("No files specified")
  91. #pullStats(statnames,sys.stdin)