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