Android kernel log 加上android logcat -v time 一样的时间戳
来源:互联网 发布:死神觉醒辅助软件 编辑:程序博客网 时间:2024/05/17 03:15
当看到其他人开始开始在kernel log前加上时间戳感觉自己一定要找到方法,在从网上找到一个python脚本并加以研究后终于可以,这对于后面分析问题有帮助,记录便于后续使用,
现在很多平台如高通,MTK会在kernel log打上android time , 众所周知, 启动时间一直就在,因此根据这两个时间就可以打出来,借助以下脚本可以完成:
import time
import datetime
import sys
import getopt
import os
a_time = None
s_second = None
s_microsecone = None
abs_time = 0.0
inputfile = None
outputfile = None
def usage():
print('''Help Information:
-h, --help: Show help information
-i, --inputfile: input file to parse
-o, --outputfile: output fiel parsed
''')
def calc_delta(stream):
global s_second
global s_microsecond
global a_time
global outfile
begin_index = None
end_index = None
delta_second = 0
delta_mircosecond = 0
delta_time = 0
d_time = None
new_line = None
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))
delta_time = datetime.timedelta(seconds=delta_second,microseconds=delta_microsecond)
d_time = a_time + delta_time
new_line = d_time.strftime("%m-%d %H:%M:%S.%f")+' ' + line
outputfile.write(new_line)
except:
outputfile.write(line)
def get_atime(stream):
global s_second
global s_microsecond
global a_time
a_time_op = None
begin_index = None
end_index = None
for line in stream:
if line:
a_time_op = line.find('android time')
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+13:].strip()
abs_time = line[begin_index + 1 :end_index]
[s_second,s_microsecond] = abs_time.split('.')
a_time = datetime.datetime.strptime(date_string, "%Y-%m-%d %H:%M:%S.%f")
break
def main(argv):
global inputfile
global outputfile
inputpath = None
outputpath = None
try:
opts, args = getopt.getopt(argv,"hi:o:",["help","inputfile=","outputfile="])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
if opt in ("-i", "--inputfile"):
inputpath = arg
if opt in ("-o", "outputfile"):
outputpath = arg
if inputpath == None:
usage()
sys.exit()
if outputpath == None:
outputpath = os.getcwd()+"/out.txt"
inputfile = open(inputpath, 'r')
outputfile = open(outputpath, 'w')
get_atime(inputfile)
inputfile.seek(0)
calc_delta(inputfile)
inputfile.close()
outputfile.close()
if __name__ == "__main__":
main(sys.argv[1:])
使用后保存为kernel.py, 并且加入可执行权限, 执行./kernel.py -i kernel_log -o kernel.txt , 打开kernel.txt 以后看到了时间点:
04-17 10:25:42.613815 <6>[ 85.920214]-(2)[1859:kworker/u:3][[FH]] dis ok
04-17 10:25:42.613832 <6>[ 85.920231]-(2)[1859:kworker/u:3][Power/clkmgr] [mt_disable_clock]: id=96, names=MFG
04-17 10:25:42.615021 <7>[ 85.921420] (1)[1019:iatek.mtklogger][1019:iatek.mtklogger] fork [2253:iatek.mtklogger]
04-17 10:25:42.617548 <6>[ 85.923947] (0)[270:mobile_log_d]socket_create[11339]:fd=24
- Android kernel log 加上android logcat -v time 一样的时间戳
- android kernel 添加时间log
- 编译能自动保存 logcat 和kernel log 的android镜像
- 如何在kernel log里找到对应的android时间
- Android 之 LogCat Log
- android的Log组件和logcat命令
- android的Log组件和logcat命令
- 同时抓取带时间的logcat和kernel log的方法
- 同时抓取带时间的logcat和kernel log的方法
- logcat 打印kernel log
- Android的Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)!
- Android的Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)
- Android的Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)
- Android的Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)!
- Android的Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)
- android的Log详解(Log.v Log.d Log.i Log.w Log.e)
- android查看kernel log
- Android kernel log获取
- iOS 图片上传之压缩
- GlusterFS Translator API
- ubuntu自动挂载新分区
- Win7+OpenCV2.4.9+VS2010配置
- [Object-C语言随笔1-4]
- Android kernel log 加上android logcat -v time 一样的时间戳
- iOS程序中自动滚动TableView到某行的方法
- Struts2中的Action类与ActionSupport类
- 【Struts2+Spring3+Hibernate3】SSH框架整合实现CRUD
- 记住不要把Bitmap往List等集合放
- uva2852
- OS堆栈
- 执行一个查询返回新的datatable或dataset
- POJ 3646 Dragon of Loowater