import re,osimport sys,getoptdef usage(): print("Usage:%s [-h] [-f] [-t] -f snapshotxxx.out -t topsql"); def TOPSQL(infile): myfile=open(infile,'r') m_lines=myfile.readlines() m_file=''.join(m_lines) pattern=re.compile(r'Number of executionss+=.*?n*Statement texts+=.*?n',re.MULTILINE | re.DOTALL) DynSQL=pattern.findall(m_file) Dynsqllist={} SortDynsqllist = [] # main #analysis the dynamice sql snapshot ,get the top sql for i in range(len(DynSQL)): Dynallcols=DynSQL[i].split('n') Dynallcols=Dynallcols[:len(Dynallcols)-1] Dyn_dict={} for j in range(len(Dynallcols)): Dyncols=Dynallcols[j].split('=',1) Dyncols[0]=Dyncols[0].replace(' ','') Dyncols[1]=Dyncols[1].replace(' ','',1) Dyn_dict[Dyncols[0]]=Dyncols[1] Dynsqllist[i]= Dyn_dict for k in range(len(Dynsqllist)): col1= float (Dynsqllist[k]['Rowsread'] )/ float( int( Dynsqllist[k]['Numberofexecutions'] ) +1 ) col2= float (Dynsqllist[k]['Totalexecutiontime(sec.microsec)'] )/ float( int( Dynsqllist[k]['Numberofexecutions'] ) +1 ) col3= float (Dynsqllist[k]['Numberofexecutions'] )/ float( int( Dynsqllist[k]['Numberofexecutions'] ) +1 ) SortDynsqllist.append((Dynsqllist[k]['Statementtext'] ,col1,col2,col3)) TopDynsqllist = sorted(SortDynsqllist,cmp=lambda x,y : cmp(x[1],y[1])) str1="" str2="" for i in range(-10,-1): for k in range(len(DynSQL)): str1="".join(DynSQL[k]) str2="".join(TopDynsqllist[i][0]) if ( str1.find(str2)<> -1 ): print str1 str1="" str2=""
def main(): options,args = getopt.getopt(sys.argv[1:],"hf:t:",["help","infile=","type="]) for option,arg in options: if option in ("-h","--help"): usage(); sys.exit(1); elif option in ("-f","--infile"): infile = options[0][1] print infile else: type = options[1][1] if (type == "topsql") : TOPSQL(infile) print type
main();
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!
关于TWT使用指南社区专家合作厂商入驻社区企业招聘投诉建议版权与免责声明联系我们 © 2024talkwithtrend — talk with trend,talk with technologist京ICP备09031017号-30
添加新评论0 条评论