-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmaps.py
More file actions
executable file
·76 lines (67 loc) · 2.08 KB
/
smaps.py
File metadata and controls
executable file
·76 lines (67 loc) · 2.08 KB
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
#!/bin/env python3
# wrapper script for smap_analyzer.py allowing one to analyze smaps for
# one or multiple processes based on a regex.
import io
import subprocess
import os
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument(
"-p", "--process-string",
help="pattern to match processes to analyze",
required=False,
type=str,
default="com.android",
)
parser.add_argument(
"-s", "--serial",
help="ADB device serial number",
required=False,
type=str,
default="",
)
parser.add_argument(
"-o", "--output",
help="output directory",
required=False,
type=str,
default="/tmp",
)
parser.add_argument(
"-S", "--smap-analyzer",
help="Location of smap_analyzer.py",
required=False,
type=str,
default="smap_analyzer.py",
)
parser.add_argument(
"-t", "--type",
help="Analyze by pss, rss, or size (vss)",
required=False,
type=str,
default="pss",
)
if __name__ == '__main__':
args = parser.parse_args()
serial = ""
if args.serial:
serial = " -s" + args.serial
fd = subprocess.Popen(["adb"+serial+" shell ps -fe"], shell=True, stdout=subprocess.PIPE)
ptable = {}
for l in io.TextIOWrapper(fd.stdout, encoding="utf-8"):
if args.process_string in l:
line = l.split()
ptable[line[1]] = line[7]
for p in ptable:
smap_filename = args.output + "/" + ptable[p] + "-" + str(p) + ".smap"
adb = "adb" + serial
cmd = adb + " pull /proc/" + str(p) + "/smaps " + smap_filename
fd2 = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
fd2.communicate()[0]
analyze_filename = smap_filename + ".analyzed"
analyzefd = open(analyze_filename, "w")
smap_analyzer_cmd = args.smap_analyzer + " -f " + smap_filename + " -t " + args.type
print("Analyzing smaps " + analyze_filename)
fd3 = subprocess.Popen(smap_analyzer_cmd, shell=True, stdin=subprocess.PIPE, stdout=analyzefd)
fd3.communicate()[0]
analyzefd.close()