kernel日志时间转换函数
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 time
import sys
import 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 inpath
print "parameter"def calc_delta(stream):global s_secondglobal s_microsecondglobal a_timeglobal outfileif 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+1time_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 + 1000000seconds = seconds - 1times = str(seconds)x = time.localtime(float(times))realtime = time.strftime('%Y-%m-%d %H:%M:%S', x)new_line = realtime+ "." + str(microseconds) +' ' + lineoutputfile.write(new_line)except:outputfile.write(line)def get_atime(stream):global s_secondglobal s_microsecondglobal a_timefor 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+1date_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;breakdef main():global inputfileglobal outputfileif 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()
kernel日志时间转换函数相关推荐
- Python时间转换函数:时间转化为时间戳、时间戳转化为时间、当前日期、当前时间、星期几、前面或者后面多少天、年、月、日等
Python时间转换函数:时间转化为时间戳.时间戳转化为时间.当前日期.当前时间.星期几.前面或者后面多少天.年.月.日等 #Python时间转换函数:时间转化为时间戳.时间戳转化为时间.当前日期.当 ...
- Linux指令日期转为字符串,linux时间转换函数【转】
Linux下的时间函数 我们在编程中可能会经常用到时间,比如取得系统的时间(获取系统的年.月.日.时.分.秒,星期等),或者是隔一段时间去做某事,那么我们就用到一些时间函数. linux下存储时间常见 ...
- php时间日期函数转字符串,php自定义时间转换函数示例
本文实例讲述了php自定义时间转换函数.分享给大家供大家参考,具体如下: 我们可以把经常用到的函数封装起来,在抽象类中,然后继承来使用. /** * 时间转时间戳 * @param object $s ...
- php整么去掉时间的年月日,php强大的时间转换函数strtotime
php强大的时间转换函数strtotime 在php中strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳,这个函数也是我们经常会用到的`,有需要的朋友参考一下. 使用st ...
- MYSQL 获取当前日期及日期格式,和常用时间转换函数
经过多次尝试本人的目标完成: select newworkorder.WorkOrderNum,newworkorder.ProjectCode, newworkorder.WorkEstComDat ...
- GreenPlum 时间转换函数
从date.timestamp.time.interval类型中抽取子域值 方法一:extract extract函数从日期.时间数值里抽取子域,例如年.小时等. 格式: extract(field ...
- HIVE 的时间转换函数
HIVE 的时间转换函数. 1,select unix_timestamp() 可以得到当前时间的时间戳. select unix_timestamp(时间格式) 可以得到当前时间的时间戳.两个时间戳 ...
- SQL Server(第二章) 字符串函数、日期时间函数、转换函数
--1.CONCAT 函数:字符串连接(支持sql server2012 SQL规则 如果与NULL连接返回NILL) SELECT empid,CONCAT(firstname,lastname) ...
- Unix/Linux编程:时间转换
unix time stamp翻译为时间戳, 就是从1970年1月1日00:00::00以来的秒数. 程序可能会关注两种类型的时间 真实时间.度量这一时间的起点有二: 其一为某个标准点. 也叫做日历时 ...
- mysql 天数减1_mysql 日期操作 增减天数、时间转换、时间戳
MySQL datediff(date1,date2):两个日期相减 date1 - date2,返回天数. select datediff('2008-08-08', '2008-08-01'); ...
最新文章
- Xamarin XAML语言教程构建ControlTemplate控件模板 (三)
- 实现JavaSrcipt页面的跳转
- iOS 设置Label中特定的文字大小和颜色
- SIGMOD回顾:数据库国际大咖组团来阿里,他们都说了啥?
- 常用正则表达 (转)
- 计蒜客NOIP2017提高组模拟赛(四)day1
- bootstrap模态框 遮挡_Bootstrap Modal遮罩弹出层
- 网络安全工作中最可怕的14种自己人
- 造芯片这事情,到底要不要找潘金莲算账?
- 数据结构上机实践第八周项目8-稀疏矩阵的三元组表示的实现及应用
- no SSL-C headers found
- 【网络安全】目前看到最全的恶意软件分析大合集
- 【马克思主义基本原理】--第一章--【世界的物质性及发展规律】
- ThingJS结合图表实现数据展示
- ssb的有效性最好_在AM、DSB、SSB、FM系统中,有效性最好的是AM
- Kafka源码研究--Comsumer获取partition下标
- npm cb() never called!和 Error: getaddrinfo ENOTFOUND registry.npmjs.com registry.npmjs.com:443
- Unicode(ASII)控制字符的含义
- 聊聊服务器性能参数优化~(建议进入收藏夹)
- 小程序实现商城案例(赋源码)