神剑山庄资源网 Design By www.hcban.com
我们在压力测试过程会收集到很多log,怎样快速从中找到有用信息呢?让python脚本帮我们做这部分工作吧!
废话不说,上代码
环境:win10 + python2.7.14
#-*- encoding: utf-8 -*- #author : beihuijie #version 1.1 import re import sys import os import countTime def getParameters(): ''' get parameters from console command ''' with open(sys.argv[1], "r") as fread: lines = fread.readlines() keywords=[] for line in lines: temp = line.split(', ') keywords.append(temp) for i in range(0, (len(keywords[0]) - 1)): print ' Keyword = %s' % keywords[0][i] return keywords[0] def isFileExists(strfile): ''' check the file whether exists ''' return os.path.isfile(strfile) def Search(keyword, filename): ''' search the keyword in a assign file ''' if(isFileExists(filename) == False): print 'Input filepath is wrong,please check again!' sys.exit() linenum = 1 findtime = 0 with open(filename, 'r') as fread: lines = fread.readlines() for line in lines: rs = re.findall(keyword, line, re.IGNORECASE) if rs: #output linenum of keyword place sys.stdout.write('line:%d '%linenum) lsstr = line.split(keyword) strlength = len(lsstr) findtime = findtime + 1 #print strlength for i in range(strlength): if(i < (strlength - 1)): sys.stdout.write(lsstr[i].strip()) sys.stdout.write(keyword) else: sys.stdout.write(lsstr[i].strip() + '\n') linenum = linenum + 1 print '+----------------------------------------------------------------------------+' print (' Search result: find keyword: %s %d times'%(keyword, findtime)) print '+----------------------------------------------------------------------------+' def executeSearch(): ''' this is a execute search method ''' ls = getParameters() start = countTime.getTime() parameter_number = len(ls) print 'Filename = %s ' % ls[parameter_number - 1] print '--------------------start search-------------------------' if(parameter_number >= 2): for i in range(parameter_number - 1): Search(ls[i], ls[parameter_number - 1]) else: print 'There is a parameter error occured in executeSearch()!' end = countTime.getTime() print '+----------------------------------------------------------------------------+' print ' Total cost time: %s'%countTime.formatTime(end - start) print '+============================================================================+' if __name__=='__main__': executeSearch()
countTime.py
#-*- encoding: utf-8 -*- #author : beihuijie #version 1.1 import datetime import time def getTime(): ''' return time is format of time(unit is second) ''' return time.time() def getCPUClockTime(): ''' return time is CPU Clock time ''' return time.clock() def formatTime(timevalue): ''' format the time numbers ''' hour = 0 minute = 0 second = 0 if timevalue > 0: #count hour hour = timevalue // 3600 remain = timevalue % 3600 #count minute minute = remain // 60 remain = remain % 60 #count second second = round(remain, 3) return '%.0fh:%.0fm:%.3fs'%(hour, minute, second) if __name__=='__main__': value = 134.45632 print value print formatTime(value)
关键字及被扫描的日志路径信息,记录到文件中,以逗号+空格隔开,如,“, ”日志路径信息放到最后。
格式如下:
anr, dalvikvm: Could not find class 'android.app.usage., panic, C:\Users\BHJ\logcat1.log
执行结果:
以上这篇python实现扫描日志关键字的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
标签:
python,关键字
神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com
暂无python实现扫描日志关键字的示例的评论...
更新日志
2024年10月02日
2024年10月02日
- 孙悦.1996-伙伴【正大国际】【WAV+CUE】
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】