Skip to content

Commit 0268d1d

Browse files
committed
add get_app_crash_log.py
1 parent 98d2a82 commit 0268d1d

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Android测试中常用到的脚本
77

88
批量安装应用(支持以中文命名的 apk)、批量卸载、截屏、录制视频、获取当前应用的 apk 文件、包名、Activity 名等。<br>
99

10+
###2015.06.02
11+
增加 `get_app_crash_log`, 应用发生 crash ,未及时从 logcat 获取到有效 log 时,可通过该脚本获取 log
12+
1013
###2015.05.30
1114
增加 `get_app_permission.py`,获取设备当前应用的权限详情,windows 下会将结果写入 `permission.txt` 文件中,其他系统打印在控制台:
1215

python/get_app_crash_log.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/env python
2+
# -*- coding=utf-8 -*-
3+
4+
'''
5+
Created on 2015年6月2日
6+
7+
@author: xuxu
8+
'''
9+
10+
import os
11+
12+
from scriptUtils import utils
13+
14+
# app发生crash,未及时在logcat中抓取到有效log时,可通过该脚本获取到log
15+
16+
PATH = lambda p : os.path.abspath(p)
17+
18+
path = PATH("%s/crash_log" %os.getcwd())
19+
if not os.path.isdir(path):
20+
os.mkdir(path)
21+
22+
# 获取app发生crash的时间列表
23+
def get_crash_time_list():
24+
time_list = []
25+
result_list = utils.shell("dumpsys dropbox | %s data_app_crash" %utils.find_util).stdout.readlines()
26+
for time in result_list:
27+
temp_list = time.split(" ")
28+
temp_time= []
29+
temp_time.append(temp_list[0])
30+
temp_time.append(temp_list[1])
31+
time_list.append(" ".join(temp_time))
32+
33+
return time_list
34+
35+
def get_crash_log(time_list):
36+
log_file = PATH("%s/crash_log/%s.txt" %(os.getcwd(), utils.timestamp()))
37+
f = open(log_file, "w")
38+
for time in time_list:
39+
cash_log = utils.shell("dumpsys dropbox --print %s" %time).stdout.read()
40+
f.write(cash_log)
41+
f.close()
42+
43+
if __name__ == '__main__':
44+
time_list = get_crash_time_list()
45+
get_crash_log(time_list)
46+
print "Completed"
47+

0 commit comments

Comments
 (0)