Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2571868
  • 博文数量: 315
  • 博客积分: 3901
  • 博客等级: 少校
  • 技术积分: 3640
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-08 15:32
个人简介

知乎:https://www.zhihu.com/people/monkey.d.luffy Android高级开发交流群2: 752871516

文章分类

全部博文(315)

文章存档

2019年(2)

2018年(1)

2016年(7)

2015年(32)

2014年(39)

2013年(109)

2012年(81)

2011年(44)

分类: 项目管理

2013-10-26 10:53:20

    脚本确实写的很烂,牛逼的可能几行、十行就搞定,不说了,不过对于我们经常开发了自己测试还是有帮助的,之前写的也行,不过需要手动去粘贴到excel里面,比较不直观,应同事建议,加了几个计数数组保存值和个数,方便计算平均值并输出【顺便提下,global地方需要注意】;

    log.py

点击(此处)折叠或打开

  1. # -*- coding: utf-8 -*-
  2. #! /usr/bin/env python

  3. #
  4. # 时间获取测试脚本;
  5. # 以'#'作为分隔符,如:
  6. # 12-25 12:25:50.953: D/sys_dbgprintf(32417):AAAAAAAAAAAAAAAAAAAAAA ^_^ draw times#73
  7. # 最后截取到73,并追加到输出文件,方便粘贴到excell中,计算.
  8. #
  9. #
  10. #使用方式: python log.py -i 测试文件 -o 输出文件
  11. #@修改: 2013.10.25 增加终端输出平均值

  12. import sys, getopt, os, string

  13. #输入文件
  14. input_file = ""
  15. #输出文件
  16. output_file = ""
  17. #平均值
  18. average = [0 for I in range(0,100)]
  19. loops = [0 for I in range(0, 100)]
  20. counter = 0
  21. isLoop = False

  22. #简单日志信息打印
  23. def usage(message):
  24.     print message
  25. #字符串截取函数
  26. def handle(src, dst):
  27.     global counter
  28.     global isLoop
  29.     if os.path.exists(dst):
  30.         os.remove(dst)
  31.     file_in = open(src, "r")
  32.     file_out = open(dst, "a")
  33.     try:
  34.         for line in file_in:
  35.             spStr = line.split('#') #以字典的形式存储分隔符前后的字符串
  36.             #tmp = spStr[1].strip('\n')
  37.             #print "hhhhhh", spStr
  38.             list_length = len(spStr)
  39.             #print "qqqqq", list_length
  40.             if list_length != 2:
  41.                 if list_length == 1:
  42.                         tmp = spStr[0]
  43.                         file_out.write(tmp)
  44.                 isLoop = True
  45.                 continue
  46.             tmp = spStr[1]
  47.             if tmp != "":
  48.                 file_out.write(tmp)
  49.                 if True == isLoop:
  50.                     isLoop = False
  51.                     counter += 1
  52.                 average[counter] += string.atoi(tmp)
  53.                 loops[counter] += 1
  54.             #print tmp
  55.     finally:
  56.         for i in range(0, (counter + 1)):
  57.             print "第%d个平均值: %f"%(i, average[i]/(float)(loops[i]))
  58.         file_in.close()
  59.         file_out.close()

  60. if __name__ == "__main__":
  61.     #1st 获得输入可选项和对应的参数
  62.     opts, args = getopt.getopt(sys.argv[1:], "hi:o:")
  63.     
  64.     for op, value in opts:
  65.         if op == "-i":
  66.             input_file = value
  67.         elif op == "-o":
  68.             output_file = value
  69.         elif op == "-h":
  70.             usage("Using: python log.py -i input_file -o outputfile")
  71.             sys.exit()
  72.     
  73.     #2nd 简单判空
  74.     if input_file == "" or input_file == "-o":
  75.         usage("no input file")
  76.         sys.exit()
  77.     print "测试文件:", input_file

  78.     if output_file == "":
  79.         usage("no output file")
  80.         sys.exit()
  81.     
  82.     #get time(int type) from each in lines
  83.     handle(input_file, output_file)

  84.     print "输出文件:", output_file

用法:【REDME文件】

点击(此处)折叠或打开

  1. 为了咋方便,这是很早之前的脚本,改了下,用来咋测平均值用一下,愿意用的可以用;
  2. 使用方法:
  3. python log.py -i 输入文本文件 -o 输出文件文件
  4. 由于规定截取方式,因此时间日志打印个数需如下:
  5. dbgprintf("xxxxxx #%d", clock() - t1); ///< 需要再%d前面加上#号;
  6. 之后从android工程截取的日志一般如下: 【保存到文本文件 qq.txt】
  7. 6-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#4
  8. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#5
  9. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#16
  10. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#16
  11. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#134
  12. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#14
  13. 然后执行命令 python log.py -i qq.txt -o 东直门附近基本地图性能.txt
  14. 最后再终端获得如下信息:
  15. 测试文件: qq.txt
  16. 第0个平均值: 31.500000
  17. 输出文件: 东直门附近基本地图性能.txt ///< 这里存了了下时间,便于核对
  18. 说明下: 1.文本第一行要保证是一行时间打印日志 【如下文件dont.txt, 所示】;
  19. 2.我们可以同时记录多个时间日志信息,一次信计算,如下: 获得信息
  20. dont.txt
  21. 06-26 15:00:20.585: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#6
  22. 06-26 15:00:20.960: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#4
  23. qqqq
  24. 06-26 14:59:04.835: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  25. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  26. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  27. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  28. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  29. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  30. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  31. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  32. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  33. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  34. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#10
  35. sfdsfsaf dluti time
  36. 6-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#4
  37. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#5
  38. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#16
  39. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#16
  40. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#134
  41. 06-26 14:59:05.218: D/sys_dbgprintf(3554): BBBBBBBBBBBBBBBBBB ^_^ draw times#14
  42. 最后结果:
  43. 测试文件: Dont.txt
  44. 第0个平均值: 5.000000
  45. 第1个平均值: 10.000000
  46. 第2个平均值: 31.500000
  47. 输出文件: don.txt

阅读(3249) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~