Difference between revisions of "Item fix.py"

From PeformIQ Upgrade
Jump to navigation Jump to search
(New page: <pre> #! /usr/bin/env python # # Purpose: Parse and display an informix log file # # $Id:$ # #--------------------------------------------------------------------- """ Parse Ben Lee's L...)
 
 
Line 9: Line 9:


"""
"""
Parse Ben Lee's LR log files to show the underlying function
Parse Ben's LR log files to show the underlying function
invocation sequence in the designated log file.  
invocation sequence in the designated log file.  


Line 292: Line 292:


[[Category:Python]]
[[Category:Python]]
[[Category:Examples]]

Latest revision as of 17:13, 19 July 2009

#! /usr/bin/env python
#
#  Purpose: Parse and display an informix log file
#
#  $Id:$
#
#---------------------------------------------------------------------

"""
Parse Ben's LR log files to show the underlying function
invocation sequence in the designated log file. 

Another option shows timing of start of function.

Instructions for use:

1.  You should change to the loadgen directory - the one containing the log files generated by Ben's code.

2.  Run:

       $ prune_log.py -t *.log

    This produces a logs.sorted file contining the merged and sorted rewritten logs.

3.  Then run:

       $ time_line.py

    This produces 'time_line.txt' which contains the time line and concurrency map.

"""

#---------------------------------------------------------------------

import re
import os
import sys
import glob
import time
import getopt
import pickle

#---------------------------------------------------------------------

__version__  = "1.0.0"

debugFlg     = 0
stdoutFlg    = 0
verboseFlg   = 0
directoryFlg = None

filename     = "x.lst"
mode         = None
data         = None

#---------------------------------------------------------------------

class Line:
   Max_0   = 0
   Max_1   = 0

   def __init__(self, l):
      self.flag = None
      self.line = l

   def __str__(self):
      if self.flag:
         s = ' ' * self.leading
         s += self.split[0]
         spacer = ' ' * (Line.Max_0 - len(self.split[0]) + 1)
         s += spacer + self.split[1]
         spacer = ' ' * (Line.Max_1 - len(self.split[1]) + 1)
         s += spacer + self.split[2]
         return s
      else:
         return self.line;

   def leading(self, no):
      self.leading = no

   def split(self, p):
      self.flag  = 1
      self.split = p

#---------------------------------------------------------------------

def startSeconds(s):
   return time.mktime(time.strptime(s, "%Y-%m-%d %H:%M:%S"))

#---------------------------------------------------------------------

def seconds(hms):
   s = hms.split(':')

   return ((s[0] * 60) + s[1]) * 60 + s[2]

#---------------------------------------------------------------------

def hms(t_secs):
   hm     = t_secs / 60
   hours  = hm / 60
   mins   = hm % 60
   secs   = t_secs % 60

   return "%02d:%02d:%02d" % ( hours, mins, secs)

#---------------------------------------------------------------------

def parse(filename):
   global t_start

   print filename

   tmatch = re.search(r'(.*?).lst', filename)
   if tmatch:
      name = tmatch.group(1)
   else:
      name = filename + ".lst"
      filename += ".lst"

   outfile = name + ".out"

   try:
      ifo = open(filename, 'r')
   except IOError, msg:
      sys.stderr.write(filename + ': cannot open: ' + `msg` + '\n')
      sys.exit(1)

   try:
      ofo = open(outfile, 'w')
   except IOError, msg:
      sys.stderr.write(outfile + ': cannot open: ' + `msg` + '\n')
      sys.exit(1)

   cnt = 0

   max_0 = 0
   max_1 = 0

   lines = []

   while 1:
      line = ifo.readline()

      if not line: break

      line = line[:-1]
      line = line.replace("\r","")

      l = Line(line)

      lines.append(l)

      if re.search("^#", line):
         continue

      if re.search("^$", line):
         continue

      if re.search("^\r$", line):
         continue

      cnt += 1

      tmatch = re.search("^  *([^ ]?)", line)
      if tmatch:
         ch                = tmatch.group(1)
         no_leading_spaces = line.index(ch)

         l.leading(no_leading_spaces)

         line = line[no_leading_spaces:]

         p = line.split(' ')

         len_0 = len(p[0])
         if len_0 > max_0:
            max_0 = len_0

         len_1 = len(p[1])
         if len_1 > max_1:
            max_1 = len_1

         l.split(p)

      try:
         print "[%s]" % str(p)
         print >>ofo, "[%s]" % str(p)
      except:
         print "%s" % line
         sys.exit(0)

   print ":::::::::::::::::::::::::"

   Line.Max_0 = max_0
   Line.Max_1 = max_1

   for i in range(len(lines)):
      print lines[i]

   ifo.close()
   ofo.close()

   print >>sys.stderr, "Processed %d lines" % cnt

#---------------------------------------------------------------------

def main():
   global filename
   global debugFlg
   global stdoutFlg
   global verboseFlg

   try:
      opts, args = getopt.getopt(sys.argv[1:], "df:vV?")
   except getopt.error, msg:
      print __doc__
      return 1

   for o, a in opts:
      if o == '-d':
         debugFlg = 1
      elif o == '-f':
         filename = a
      elif o == '-v':
         verboseFlg = 1
      elif o == '-V':
         print "Version: %s" % __version__
         return 1
      elif o == '-?':
         print __doc__
         return 1

   if (debugFlg):
      print ">> Flg    %s" % debugFlg

   parse(filename)

   return 1

#---------------------------------------------------------------------

if __name__ == '__main__' or __name__ == sys.argv[0]:
   sys.exit(main())

#---------------------------------------------------------------------

"""
Revision History:

     Date     Who   Description
   --------   ---   --------------------------------------------------
   20040812   plh   Initial implementation

Problems to fix:

To Do:

Issues:

"""

"""
      "Name=org.apache.struts.taglib.html.TOKEN", "Value={AgentisTOKEN}", ENDITEM,
      "Name=panelControlMap_subFormName", "Value=QueueLinkMap", ENDITEM,
      "Name=panelControlMap_panelName", "Value=null", ENDITEM,
      "Name=MetaDataDrivenTagMap_tableName", "Value=0", ENDITEM,
      "Name=MetaDataDrivenTagMap_columnName", "Value=0", ENDITEM,
      "Name=MetaDataDrivenTagMap_recordNumber", "Value=0", ENDITEM,
      "Name=MetaDataDrivenTagMap_agentId", "Value=0", ENDITEM,
      "Name=", "Value=", ENDITEM,
      "Name=", "Value=", ENDITEM,
      "Name=ConfirmationActionForm_role", "Value=*UNKNOWN:role*", ENDITEM,
      "Name=ConfirmationActionForm_token", "Value=*UNKNOWN:token*", ENDITEM,
      "Name=ConfirmationActionForm_param1", "Value=*UNKNOWN:param1*", ENDITEM,
      "Name=ConfirmationActionForm_param2", "Value=*UNKNOWN:param2*", ENDITEM,

      "Name=QueueLinkMap_taskId", value_task, ENDITEM,

      "Name=QueueLinkMap_requestId", "Value=", ENDITEM,
      "Name=QueueLinkMap_awbNumber", "Value=", ENDITEM,
      "Name=QueueLinkMap_queueLinkId", "Value=", ENDITEM,
      "Name=QueueLinkMap_orgUnitName", "Value=", ENDITEM,
      "Name=QueueLinkMap_orgUnitId", "Value=", ENDITEM,
      "Name=BodyLinkMap_taskId", "Value=", ENDITEM,
      "Name=BodyLinkMap_awbNumber", "Value=", ENDITEM,
      "Name=BodyLinkMap_requestId", "Value=", ENDITEM,
      "Name=BodyLinkMap_queueLinkId", "Value=", ENDITEM,
"""