-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtools.py
executable file
·147 lines (110 loc) · 3.79 KB
/
tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python
#coding:utf-8
# author ShiWang
import sys, os
PACKAGE = "com.sw.bridge"
DEFAULT_MODULE = "app"
APK_FILE_PATH = "app/build/outputs/apk/debug/app-debug.apk"
def command(cmd):
#print cmd
os.system(cmd)
# ----------- 帮助说明 -----------
def help():
print "帮助说明文档:"
print "./tools.py t 打印栈顶Activity"
print "./tools.py d 进入等待调试模式"
print "./tools.py c 清理app缓存"
print "./tools.py i 安装app"
print "./tools.py task 打印task栈"
print "./tools.py details 打开app设置页面"
print "./tools.py clean_git 清理git仓库"
print "./tools.py profile 打印编译时间profile"
print "./tools.py mem 打印进程内存信息"
print "./tools.py adj 打印进程相关信息(进程id、oom_adj值)"
print "./tools.py window {lines} 查看窗口层级,参数为显示的行数,不输入则为单行"
print "./tools.py depend {module name} 打印module依赖关系,参数为module名,不输入则为主模块"
print "./tools.py search {content} 全局搜索内容"
# ----------- 工具类方法实现 -----------
# 打印栈顶Activity
def top():
command("adb shell dumpsys activity top | grep --color=always ACTIVITY")
# adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' --color=always
# 进入等待调试模式
def debug():
command("adb shell am set-debug-app -w %s" % PACKAGE)
# 清理app缓存
def clear():
command("adb shell pm clear %s" % PACKAGE)
# 安装app
def install():
command("adb install -t -r %s" % APK_FILE_PATH)
# 打开app设置页面
def details():
command("adb shell am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d package:%s" % PACKAGE)
# 打印Task栈
def task():
command("adb shell dumpsys activity activities | grep --color=always ActivityRecord | grep --color=always Hist")
# 清理git仓库
def clean_git():
command("git reset HEAD . && git clean -fd && git checkout -- . && git status")
# 打印编译时间profile
def profile():
command("./gradlew assembleDebug --offline --profile")
# 打印进程内存信息
def mem():
command("adb shell dumpsys meminfo %s" % PACKAGE)
# 打印进程相关信息(进程id、oom_adj值)
def adj():
command_str = "adb shell ps | grep %s | grep -v : | awk '{print $2}'" % PACKAGE
p = os.popen(command_str)
pid = p.readline().strip()
print "process id:%s" % pid
command("adb root")
print "process oom_adj:"
command("adb shell cat /proc/%s/oom_adj" % pid)
# 查看窗口层级
def window(*args):
if len(args)==0:
arg = 0
else:
arg = args[0][0]
command("adb shell dumpsys window windows | grep 'Window #' --color -A %s" % arg)
# 打印module依赖关系
def depend(*args):
if len(args)==0:
arg = DEFAULT_MODULE
else:
arg = args[0][0]
command("./gradlew -q %s:dependencies" % arg)
# 全局搜索内容
def search(*args):
if len(args)==0:
return
else:
arg = args[0][0]
command("grep -E %s --exclude-dir={.git,lib,.gradle,.idea,build,captures} --exclude={*.jar} . -R --color=always -n" % arg)
# ----------- 方法缩写 -----------
def t():
top()
def d():
debug()
def c():
clear()
def i():
install()
def main():
args = None
if len(sys.argv) > 2:
action = sys.argv[1]
args = sys.argv[2:]
elif len(sys.argv) > 1:
action = sys.argv[1]
else:
action = "help"
if args is None:
call = "%s()" % action
else:
call = "%s(%s)" % (action, args)
exec(call)
if __name__ == "__main__":
main()