Module parsedatalistening |
[hide private]
[frames] | no frames]

# Source Code for Module parsedatalistening

      1  #============================================================================
      2  #Name        : parsedatalistening.py
      3  #Part of     : Helium
      4
      5  #Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
      6  #All rights reserved.
      7  #This component and the accompanying materials are made available
      8  #under the terms of the License "Eclipse Public License v1.0"
      9  #which accompanies this distribution, and is available
     10  #at the URL "http://www.eclipse.org/legal/epl-v10.html".
     11  #
     12  #Initial Contributors:
     13  #Nokia Corporation - initial contribution.
     14  #
     15  #Contributors:
     16  #
     17  #Description:
     18  #===============================================================================
     19
     20  import urllib
     21  import gzip
     22  import tempfile
     23  import os
     24  import sys
     25  import xml.etree.ElementTree as ElementTree
     26  from processing import Pool, freezeSupport
     27
     28 -class Target:
     29 -    def __init__(self, name, start, end):
     30          self.name = name
     31          self.start = start
     32          self.end = end
     33
     34 -class Build:
     35 -    def __init__(self, id, user, success, targets):
     36          self.id = id
     37          self.user = user
     38          self.success = success
     39          self.targets = targets
     40
     41 -def parseXml(infile):
     42      f = gzip.open(infile, 'r')
     43      success = True
     44      username = ''
     45      targets = []
     46      for event, elem in ElementTree.iterparse(f):
     47          if elem.tag == 'build':
     48              name = elem.get('status')
     49              if name != 'successful':
     50                  success = False
     51          if elem.tag == 'target':
     52              name = elem.get('name')
     53              id = elem.get('id')
     54              if name != None:
     55                  targets.append(Target(name, id, 0))
     56          if elem.tag == 'targetRef':
     57              ref = elem.get('reference')
     58              if ref != None:
     59                  for t in targets:
     60                      if t.start == ref:
     61                          t.start = int(elem.get('startTime'))
     62                          t.end = int(elem.get('endTime'))
     63          if elem.tag == 'property':
     64              if elem.get('name') == 'user.name':
     65                  username = elem.get('value')
     66
     67          elem.clear()
     68
     69      f.close()
     70
     71      return Build(infile, username, success, targets)
     72
     73  if __name__ == '__main__':
     74      freezeSupport()
     75
     76      outdir = os.path.join(tempfile.gettempdir(), 'helium_data')
     77      if not os.path.exists(outdir):
     78          os.mkdir(outdir)
     79
     80      files = []
     81      pool = Pool()
     82
     83      for n in range(1, 100):
     84
     85          try:
     86              #r'C:\USERS\helium\helium_data'
     87              infile = os.path.join(outdir, '%(#)08d_data.xml.gz' % {"#": n})
     88              #print infile
     89              if not os.path.exists(infile):
     90                  urllib.urlretrieve("http://helium.nmp.nokia.com/data/internaldata/%(#)08d_data.xml.gz" % {"#": n}, infile)
     91
     92              files.append(infile)
     93
     94          except Exception, e:
     95              print e
     96
     97      builds = pool.map(parseXml, files)
     98
     99      targets = {}
    100      targetsfailing = {}
    101      users = {}
    102
    103      for build in builds:
    104
    105          if users.has_key(build.user):
    106              users[build.user] = users[build.user] + 1
    107          else:
    108              users[build.user] = 1
    109
    110          for value in build.targets:
    111              #print build.targets
    112              #value = build.targets.pop()
    113              #print value.name
    114              #print (value.end - value.start)/1000
    115
    116              if targets.has_key(value.name):
    117                  #targets[value.name] = targets[value.name] + 1
    118                  (no, time) = targets[value.name]
    119                  targets[value.name] = (no + 1, time + (value.end - value.start))
    120              else:
    121                  targets[value.name] = (1, (value.end - value.start))
    122
    123              if not build.success:
    124                  if targetsfailing.has_key(value.name):
    125                      targetsfailing[value.name] = targetsfailing[value.name] + 1
    126                  else:
    127                      targetsfailing[value.name] = 1
    128
    129      print 'Users:'
    130
    131      for key in users.keys():
    132          print '%05d' % users[key] + ' ' + key
    133
    134      print 'Calls,Targets,TimeSeconds'
    135
    136      for key in targets.keys():
    137          (no, time) = targets[key]
    138          print '%05d' % no + ',' + key + ',%07d' % int(time/1000)
    139
    140      print 'Targets failing:'
    141
    142      for key in targetsfailing.keys():
    143          print '%05d' % targetsfailing[key] + ' ' + key
    144