Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
android_systrace_test Namespace Reference

Functions

 install_apk (apk_path, package_name, adb_path='adb')
 
 start_perfetto (package_name, adb_path='adb')
 
 launch_package (package_name, activity_name, adb_path='adb')
 
 collect_and_validate_trace (adb_path='adb')
 
 main ()
 

Variables

 BUILDROOT_DIR = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..'))
 
str PERFETTO_SESSION_KEY = 'session1'
 
str PERFETTO_TRACE_FILE = '/data/misc/perfetto-traces/trace'
 
str PERFETTO_CONFIG
 

Function Documentation

◆ collect_and_validate_trace()

android_systrace_test.collect_and_validate_trace (   adb_path = 'adb')

Definition at line 75 of file android_systrace_test.py.

75def collect_and_validate_trace(adb_path='adb'):
76 print('Fetching trace')
77 subprocess.check_output([
78 adb_path, 'shell', 'perfetto', '--attach', PERFETTO_SESSION_KEY, '--stop'
79 ],
80 stderr=subprocess.STDOUT)
81 subprocess.check_output([adb_path, 'pull', PERFETTO_TRACE_FILE, 'trace.pb'],
82 stderr=subprocess.STDOUT)
83
84 print('Validating trace')
85 traceconv = os.path.join(
86 BUILDROOT_DIR, 'third_party', 'android_tools', 'trace_to_text', 'trace_to_text'
87 )
88 traceconv_output = subprocess.check_output([traceconv, 'systrace', 'trace.pb'],
89 stderr=subprocess.STDOUT,
90 universal_newlines=True)
91
92 print('Trace output:')
93 print(traceconv_output)
94
95 if 'ShellSetupUISubsystem' in traceconv_output:
96 return 0
97
98 print('Trace did not contain ShellSetupUISubsystem, failing.')
99 return 1
100
101
void print(void *str)
Definition bridge.cpp:126

◆ install_apk()

android_systrace_test.install_apk (   apk_path,
  package_name,
  adb_path = 'adb' 
)

Definition at line 36 of file android_systrace_test.py.

36def install_apk(apk_path, package_name, adb_path='adb'):
37 print('Installing APK')
38 subprocess.check_output([adb_path, 'shell', 'am', 'force-stop', package_name])
39 # Allowed to fail if APK was never installed.
40 subprocess.call([adb_path, 'uninstall', package_name], stdout=subprocess.DEVNULL)
41 subprocess.check_output([adb_path, 'install', apk_path])
42
43

◆ launch_package()

android_systrace_test.launch_package (   package_name,
  activity_name,
  adb_path = 'adb' 
)

Definition at line 54 of file android_systrace_test.py.

54def launch_package(package_name, activity_name, adb_path='adb'):
55 print('Scanning logcat')
56 subprocess.check_output([adb_path, 'logcat', '-c'], stderr=subprocess.STDOUT)
57 logcat = subprocess.Popen([adb_path, 'logcat'],
58 stdout=subprocess.PIPE,
59 stderr=subprocess.STDOUT,
60 universal_newlines=True)
61
62 print('Launching %s (%s)' % (package_name, activity_name))
63 subprocess.check_output([
64 adb_path, 'shell', 'am ', 'start', '-n',
65 '%s/%s' % (package_name, activity_name)
66 ],
67 stderr=subprocess.STDOUT)
68 for line in logcat.stdout:
69 print('>>>>>>>> ' + line.strip())
70 if ('Observatory listening' in line) or ('Dart VM service is listening' in line):
71 logcat.kill()
72 break
73
74

◆ main()

android_systrace_test.main ( )

Definition at line 102 of file android_systrace_test.py.

102def main():
103 parser = argparse.ArgumentParser()
104
105 parser.add_argument(
106 '--apk-path', dest='apk_path', action='store', help='Provide the path to the APK to install'
107 )
108 parser.add_argument(
109 '--package-name',
110 dest='package_name',
111 action='store',
112 help='The package name of the APK, e.g. dev.flutter.scenarios'
113 )
114 parser.add_argument(
115 '--activity-name',
116 dest='activity_name',
117 action='store',
118 help='The activity to launch as it appears in AndroidManifest.xml, '
119 'e.g. .PlatformViewsActivity'
120 )
121 parser.add_argument(
122 '--adb-path',
123 dest='adb_path',
124 action='store',
125 default='adb',
126 help='Provide the path of adb used for android tests. '
127 'By default it looks on $PATH.'
128 )
129
130 args = parser.parse_args()
131
132 android_api_level = subprocess.check_output([
133 args.adb_path, 'shell', 'getprop', 'ro.build.version.sdk'
134 ],
135 text=True).strip()
136 if int(android_api_level) < 29:
137 print('Android API %s detected. This script requires API 29 or above.' % android_api_level)
138 return 0
139
140 install_apk(args.apk_path, args.package_name, args.adb_path)
141 start_perfetto(args.package_name, args.adb_path)
142 launch_package(args.package_name, args.activity_name, args.adb_path)
143 return collect_and_validate_trace(args.adb_path)
144
145
Type::kYUV Type::kRGBA() int(0.7 *637)
Definition main.py:1

◆ start_perfetto()

android_systrace_test.start_perfetto (   package_name,
  adb_path = 'adb' 
)

Definition at line 44 of file android_systrace_test.py.

44def start_perfetto(package_name, adb_path='adb'):
45 print('Starting trace')
46 cmd = [
47 adb_path, 'shell', 'echo', "'" + PERFETTO_CONFIG % package_name + "'", '|', 'perfetto', '-c',
48 '-', '--txt', '-o', PERFETTO_TRACE_FILE, '--detach', PERFETTO_SESSION_KEY
49 ]
50
51 subprocess.check_output(cmd, stderr=subprocess.STDOUT)
52
53

Variable Documentation

◆ BUILDROOT_DIR

android_systrace_test.BUILDROOT_DIR = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..'))

Definition at line 12 of file android_systrace_test.py.

◆ PERFETTO_CONFIG

str android_systrace_test.PERFETTO_CONFIG
Initial value:
1= """
2write_into_file: true
3file_write_period_ms: 1000000000
4flush_period_ms: 1000
5
6buffers: {
7 size_kb: 129024
8}
9data_sources: {
10 config {
11 name: "linux.ftrace"
12 ftrace_config {
13 ftrace_events: "ftrace/print"
14 atrace_apps: "%s"
15 }
16 }
17}
18"""

Definition at line 16 of file android_systrace_test.py.

◆ PERFETTO_SESSION_KEY

str android_systrace_test.PERFETTO_SESSION_KEY = 'session1'

Definition at line 14 of file android_systrace_test.py.

◆ PERFETTO_TRACE_FILE

str android_systrace_test.PERFETTO_TRACE_FILE = '/data/misc/perfetto-traces/trace'

Definition at line 15 of file android_systrace_test.py.