log.py
点击(此处)折叠或打开
- # -*- coding: utf-8 -*-
- #! /usr/bin/env python
- #
- # 时间获取测试脚本;
- # 以'#'作为分隔符,如:
- # 12-25 12:25:50.953: D/sys_dbgprintf(32417):AAAAAAAAAAAAAAAAAAAAAA ^_^ draw times#73
- # 最后截取到73,并追加到输出文件,方便粘贴到excell中,计算.
- #
- #
- #使用方式: python log.py -i 测试文件 -o 输出文件
- #@修改: 2013.10.25 增加终端输出平均值
- import sys, getopt, os, string
- #输入文件
- input_file = ""
- #输出文件
- output_file = ""
- #平均值
- average = [0 for I in range(0,100)]
- loops = [0 for I in range(0, 100)]
- counter = 0
- isLoop = False
- #简单日志信息打印
- def usage(message):
- print message
- #字符串截取函数
- def handle(src, dst):
- global counter
- global isLoop
- if os.path.exists(dst):
- os.remove(dst)
- file_in = open(src, "r")
- file_out = open(dst, "a")
- try:
- for line in file_in:
- spStr = line.split('#') #以字典的形式存储分隔符前后的字符串
- #tmp = spStr[1].strip('\n')
- #print "hhhhhh", spStr
- list_length = len(spStr)
- #print "qqqqq", list_length
- if list_length != 2:
- if list_length == 1:
- tmp = spStr[0]
- file_out.write(tmp)
- isLoop = True
- continue
- tmp = spStr[1]
- if tmp != "":
- file_out.write(tmp)
- if True == isLoop:
- isLoop = False
- counter += 1
- average[counter] += string.atoi(tmp)
- loops[counter] += 1
- #print tmp
- finally:
- for i in range(0, (counter + 1)):
- print "第%d个平均值: %f"%(i, average[i]/(float)(loops[i]))
- file_in.close()
- file_out.close()
- if __name__ == "__main__":
- #1st 获得输入可选项和对应的参数
- opts, args = getopt.getopt(sys.argv[1:], "hi:o:")
-
- for op, value in opts:
- if op == "-i":
- input_file = value
- elif op == "-o":
- output_file = value
- elif op == "-h":
- usage("Using: python log.py -i input_file -o outputfile")
- sys.exit()
-
- #2nd 简单判空
- if input_file == "" or input_file == "-o":
- usage("no input file")
- sys.exit()
- print "测试文件:", input_file
- if output_file == "":
- usage("no output file")
- sys.exit()
-
- #get time(int type) from each in lines
- handle(input_file, output_file)
- print "输出文件:", output_file
用法:【REDME文件】
点击(此处)折叠或打开
- 为了咋方便,这是很早之前的脚本,改了下,用来咋测平均值用一下,愿意用的可以用;
- 使用方法:
- python log.py -i 输入文本文件 -o 输出文件文件
- 由于规定截取方式,因此时间日志打印个数需如下:
- dbgprintf("xxxxxx #%d", clock() - t1); ///< 需要再%d前面加上#号;
- 之后从android工程截取的日志一般如下: 【保存到文本文件 qq.txt】
- 6-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#4
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#5
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#16
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#16
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#134
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#14
- 然后执行命令 python log.py -i qq.txt -o 东直门附近基本地图性能.txt
- 最后再终端获得如下信息:
- 测试文件: qq.txt
- 第0个平均值: 31.500000
- 输出文件: 东直门附近基本地图性能.txt ///< 这里存了了下时间,便于核对
- 说明下: 1.文本第一行要保证是一行时间打印日志 【如下文件dont.txt, 所示】;
- 2.我们可以同时记录多个时间日志信息,一次信计算,如下: 获得信息
- dont.txt
- 06-26 15:00:20.585: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#6
- 06-26 15:00:20.960: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#4
- qqqq
- 06-26 14:59:04.835: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
- sfdsfsaf dluti time
- 6-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#4
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#5
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#16
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#16
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#134
- 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#14
- 最后结果:
- 测试文件: Dont.txt
- 第0个平均值: 5.000000
- 第1个平均值: 10.000000
- 第2个平均值: 31.500000
- 输出文件: don.txt