Monday, March 23, 2009

Parsing a 10046 trace with Python

Try the following...


import fileinput
import string
import sys

b=0
sqls = [0 for x in range(400)] #need to make array/list size dynamic
tok=""
cur=0
tim=0
prevtim=0

for line in fileinput.input([sys.argv[1:][0]]):
if (b==1 and line.startswith("END OF STMT")):
sqls[cur]=tok
tok=""
b=0
elif line.startswith("PARSING IN CURSOR"):
c=int(string.replace(string.split(line," ")[3],"#",""))
cur=int(c) * 1
b=1
elif line.startswith("EXEC #"):
c=int(string.replace(string.split(line,":")[0],"EXEC #",""))
if prevtim>0:
prevtim=tim
tim=int(string.replace(string.split(line,",")[9],"tim=",""))
print str((tim - prevtim) / 1000) + " milliseconds since the previous statement."
print str((tim - start) / 1000) + " milliseconds since the start of the trace."
else:
prevtim=tim
tim=int(string.replace(string.split(line,",")[9],"tim=",""))
start=tim
print "Executing " + sqls[c]
elif (b==1):
tok=tok + line

Locations of visitors to this page