12BUILDROOT_DIR = os.path.abspath(os.path.join(os.path.realpath(__file__),
'..',
'..',
'..'))
14PERFETTO_SESSION_KEY =
'session1'
15PERFETTO_TRACE_FILE =
'/data/misc/perfetto-traces/trace'
18file_write_period_ms: 1000000000
28 ftrace_events:
"ftrace/print"
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])
40 subprocess.call([adb_path,
'uninstall', package_name], stdout=subprocess.DEVNULL)
41 subprocess.check_output([adb_path,
'install', apk_path])
45 print(
'Starting trace')
47 adb_path,
'shell',
'echo',
"'" + PERFETTO_CONFIG % package_name +
"'",
'|',
'perfetto',
'-c',
48 '-',
'--txt',
'-o', PERFETTO_TRACE_FILE,
'--detach', PERFETTO_SESSION_KEY
51 subprocess.check_output(cmd, stderr=subprocess.STDOUT)
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)
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)
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):
76 print(
'Fetching trace')
77 subprocess.check_output([
78 adb_path,
'shell',
'perfetto',
'--attach', PERFETTO_SESSION_KEY,
'--stop'
80 stderr=subprocess.STDOUT)
81 subprocess.check_output([adb_path,
'pull', PERFETTO_TRACE_FILE,
'trace.pb'],
82 stderr=subprocess.STDOUT)
84 print(
'Validating trace')
85 traceconv = os.path.join(
86 BUILDROOT_DIR,
'flutter',
'third_party',
'android_tools',
'trace_to_text',
'trace_to_text'
88 traceconv_output = subprocess.check_output([traceconv,
'systrace',
'trace.pb'],
89 stderr=subprocess.STDOUT,
90 universal_newlines=
True)
92 print(
'Trace output:')
93 print(traceconv_output)
95 if 'ShellSetupUISubsystem' in traceconv_output:
98 print(
'Trace did not contain ShellSetupUISubsystem, failing.')
103 parser = argparse.ArgumentParser()
106 '--apk-path', dest=
'apk_path', action=
'store', help=
'Provide the path to the APK to install'
112 help=
'The package name of the APK, e.g. dev.flutter.scenarios'
116 dest=
'activity_name',
118 help=
'The activity to launch as it appears in AndroidManifest.xml, '
119 'e.g. .PlatformViewsActivity'
126 help=
'Provide the path of adb used for android tests. '
127 'By default it looks on $PATH.'
130 args = parser.parse_args()
132 android_api_level = subprocess.check_output([
133 args.adb_path,
'shell',
'getprop',
'ro.build.version.sdk'
136 if int(android_api_level) < 29:
137 print(
'Android API %s detected. This script requires API 29 or above.' % android_api_level)
140 install_apk(args.apk_path, args.package_name, args.adb_path)
142 launch_package(args.package_name, args.activity_name, args.adb_path)
146if __name__ ==
'__main__':
def launch_package(package_name, activity_name, adb_path='adb')
def collect_and_validate_trace(adb_path='adb')
def install_apk(apk_path, package_name, adb_path='adb')
def start_perfetto(package_name, adb_path='adb')
def print(*args, **kwargs)