gk2csv.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. # Copyright (c) 2011 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. gk2csv.py
  10. Converts the stats output about a build from grokbuild.py (in an XML format)
  11. and makes a csv format file from it. Looks for <annofile> tags and outputs
  12. all the value attributes of the <metric> tags within them.
  13. Usage:
  14. python gk2csv.py grokfilename.xml > output.csv
  15. """
  16. import os
  17. import sys
  18. import re
  19. # following might match: mcl_201123_hw79u_08_ncp_main_build_dfs_variants.resource_deps.emake.anno
  20. name_re=re.compile("^([a-zA-Z0-9]*_[0-9]+_[a-zA-Z0-9]+_[0-9]+)_(.*?).emake.anno.*")
  21. from xml.dom import minidom
  22. try:
  23. inputfilename = sys.argv[1]
  24. xmldoc = minidom.parse(inputfilename)
  25. except IndexError as e:
  26. sys.stderr.write("Need a filename parameter: {0}\n".format(__doc__))
  27. sys.exit(1)
  28. except IOError as e:
  29. sys.stderr.write("parameter '{0}' could not be parsed must be an existing xml format file\n".format(inputfilename))
  30. sys.exit(1)
  31. headlines=[]
  32. headered=False
  33. build_id = None
  34. for node in xmldoc.getElementsByTagName('annofile'):
  35. fname = os.path.split(node.attributes['name'].value)[1]
  36. m = name_re.match(fname)
  37. if build_id == None:
  38. build_id = m.group(1)
  39. print("Build: {0}".format(build_id))
  40. stepname = m.group(2)
  41. line = [stepname]
  42. for c in node.getElementsByTagName('metric'):
  43. line.append(c.attributes['value'].value)
  44. if not headered:
  45. headlines.append(c.attributes['name'].value)
  46. if not headered:
  47. print("stepname,{0}".format(",".join(headlines)))
  48. headered = True
  49. print(",".join(line))