kernel日志时间转换函数
来源:互联网 发布:mysql分页limit0,1 编辑:程序博客网 时间:2024/06/01 19:42
1. 原理说明:参考了这篇文章http://blog.csdn.net/transformer_han/article/details/24741605,但因其只对mtk平台kernel log有效。qcom平台kernel log无效。因为qcom平台kernel log中根本就没有写包含android time标签的信息。所以自己改了一下使其支持qcom平台,原理基本一致区别就是搜索'audit('关键字获取时间戳,然后通过与改时间戳对应的kernel时间的差进行计算得到格式化时间;
2: 使用方式,保存代码成任意XXX.py,然后执行python XXX.px inputfilename,其中inputfilename是要转换的kmsg文件名称,然后会在XXX.py所在目录生成inputfilename_translated文件
import timeimport sysimport osdef usage(): print('''Help Information: kmsg_translate inputfile: input file to parse ''')if len(sys.argv) < 2: usage() sys.exit(2)inpath = sys.argv[1]print "parameter"print inpathprint "parameter"def calc_delta(stream): global s_second global s_microsecond global a_time global outfile if a_time ==None: print("Can't convert to android time") exit(-1) for line in stream: if line: try: begin_index = line.index('[') end_index = line[begin_index+1:].index(']')+begin_index+1 time_string = line[begin_index + 1 :end_index] [d_second,d_microsecond] = time_string.split('.') delta_second = int(int(d_second) - int(s_second)) delta_microsecond = int(int(d_microsecond)-int(s_microsecond)) [t_second, t_microsecond] = a_time.split('.') seconds = (delta_second + int(t_second)) microseconds = (delta_microsecond + int(t_microsecond) * 1000) if microseconds < 0: microseconds = microseconds + 1000000 seconds = seconds - 1 times = str(seconds) x = time.localtime(float(times)) realtime = time.strftime('%Y-%m-%d %H:%M:%S', x) new_line = realtime+ "." + str(microseconds) +' ' + line outputfile.write(new_line) except: outputfile.write(line) def get_atime(stream): global s_second global s_microsecond global a_time for line in stream: if line: a_time_op = line.find('audit(') if a_time_op>=1: begin_index = line.index('[') end_index = line[begin_index+1:].index(']')+begin_index+1 date_string = line[a_time_op + 6 :a_time_op+20] abs_time = line[begin_index + 1 :end_index] [s_second,s_microsecond] = abs_time.split('.') a_time = date_string; break def main(): global inputfile global outputfile if inpath == None: usage() sys.exit(2) inputfile = open(inpath, 'r') outputfile = open(os.getcwd() + '/' + inpath + '_translated', 'w') get_atime(inputfile) inputfile.seek(0) calc_delta(inputfile) inputfile.close() outputfile.close()if __name__ == "__main__": main()
阅读全文
2 0
- kernel日志时间转换函数
- kernel地址转换的函数
- 时间函数与时间转换
- 转换日期时间函数
- Sqlserver时间转换函数
- ASP时间转换函数
- java时间转换函数
- 时间格式转换函数
- 时间转换函数
- 时间转换函数
- python 时间转换函数
- hive时间函数转换
- 时间转换UDF函数
- 时间转换函数
- 日志和时间函数设计
- MySQL 日期转换函数、时间转换函数
- MySQL 日期转换函数、时间转换函数
- python转换日志中的时间格式
- 当自动化安装遇到ncurse界面的解决方法(取消交互的通用方法)
- SpringBoot系列(4)---SpringMVC测试用例
- 解决Lightmap在PC上与ios和Android上表现不…
- mysql分页大数据性能优化
- Q_OBJECT宏
- kernel日志时间转换函数
- collection集合学习笔记
- OpenCv基础(一)附:vs2017 配置 opencv 3.2.0
- centeros7 最小安装,沉默安装oracle
- Ubuntu安装OpenGTS-GPS追踪系统
- XSS跨站脚本攻击初探
- android选择器
- Html5之canvas绘图
- Android Studio安装freeline插件