2020-12-07 23:17:40 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
"""
|
|
|
|
A script to set up startup profiling with the Firefox Profiler. See
|
|
|
|
https://profiler.firefox.com/docs/#/./guide-remote-profiling?id=startup-profiling
|
|
|
|
for more information.
|
|
|
|
"""
|
|
|
|
|
2021-09-13 21:50:17 +00:00
|
|
|
import argparse
|
2020-12-07 23:17:40 +00:00
|
|
|
import os
|
2021-01-07 19:53:31 +00:00
|
|
|
import tempfile
|
2020-12-07 23:17:40 +00:00
|
|
|
from subprocess import run
|
|
|
|
|
2021-07-21 18:56:54 +00:00
|
|
|
PATH_PREFIX = '/data/local/tmp'
|
2020-12-07 23:17:40 +00:00
|
|
|
|
2021-09-13 22:00:46 +00:00
|
|
|
PROD_FENIX = 'fenix'
|
|
|
|
PROD_GVE = 'geckoview_example'
|
|
|
|
PRODUCTS = [PROD_FENIX, PROD_GVE]
|
|
|
|
|
2021-07-21 18:56:54 +00:00
|
|
|
GV_CONFIG = b'''env:
|
2021-01-07 19:53:31 +00:00
|
|
|
MOZ_PROFILER_STARTUP: 1
|
|
|
|
MOZ_PROFILER_STARTUP_INTERVAL: 5
|
2021-03-30 21:33:21 +00:00
|
|
|
MOZ_PROFILER_STARTUP_FEATURES: threads,js,stackwalk,leaf,screenshots,ipcmessages,java,cpu
|
2021-01-07 19:53:31 +00:00
|
|
|
MOZ_PROFILER_STARTUP_FILTERS: GeckoMain,Compositor,Renderer,IPDL Background
|
|
|
|
'''
|
|
|
|
|
2021-07-21 18:56:54 +00:00
|
|
|
|
2021-09-13 21:50:17 +00:00
|
|
|
def parse_args():
|
|
|
|
p = argparse.ArgumentParser(
|
|
|
|
description=("Easily enable start up profiling using the Firefox Profiler. Finish capturing the profile in "
|
|
|
|
"about:debugging on desktop. See "
|
|
|
|
"https://profiler.firefox.com/docs/#/./guide-remote-profiling?id=startup-profiling for "
|
|
|
|
"details."))
|
|
|
|
p.add_argument('command', choices=['activate', 'deactivate'], help=("whether to activate or deactive start up "
|
|
|
|
"profiling for the given release channel"))
|
|
|
|
p.add_argument('release_channel', choices=['nightly', 'beta', 'release', 'debug'], help=("the release channel to "
|
|
|
|
"change the startup profiling state of the command on"))
|
2021-09-13 22:00:46 +00:00
|
|
|
|
|
|
|
p.add_argument('-p', '--product', choices=PRODUCTS, default=PROD_FENIX, help="which product to work on")
|
2021-09-13 21:50:17 +00:00
|
|
|
return p.parse_args()
|
2020-12-07 23:17:40 +00:00
|
|
|
|
2021-07-21 18:56:54 +00:00
|
|
|
|
2020-12-07 23:17:40 +00:00
|
|
|
def push(id, filename):
|
2021-01-07 19:53:31 +00:00
|
|
|
config = tempfile.NamedTemporaryFile(delete=False)
|
|
|
|
try:
|
|
|
|
# I think the file needs to be closed to save its contents for adb push to
|
|
|
|
# work correctly so we close it here and later delete it manually.
|
|
|
|
with config.file as f:
|
|
|
|
f.write(GV_CONFIG)
|
|
|
|
|
2021-01-07 20:11:17 +00:00
|
|
|
print('Pushing {} to device.'.format(filename))
|
2021-01-07 19:53:31 +00:00
|
|
|
run(['adb', 'push', config.name, os.path.join(PATH_PREFIX, filename)])
|
|
|
|
run(['adb', 'shell', 'am', 'set-debug-app', '--persistent', id])
|
2021-02-24 23:12:30 +00:00
|
|
|
print('\nStartup profiling enabled on all future start ups, possibly even after reinstall.')
|
|
|
|
print('Call script with `deactivate` to disable it.')
|
|
|
|
print('DON\'T FORGET TO ENABLE \'Remote debugging via USB\' IN THE APP SETTINGS!')
|
2021-01-07 19:53:31 +00:00
|
|
|
finally:
|
|
|
|
os.remove(config.name)
|
2020-12-07 23:17:40 +00:00
|
|
|
|
2021-07-21 18:56:54 +00:00
|
|
|
|
2020-12-07 23:17:40 +00:00
|
|
|
def remove(filename):
|
2021-01-07 20:11:17 +00:00
|
|
|
print('Removing {} from device.'.format(filename))
|
2020-12-07 23:17:40 +00:00
|
|
|
run(['adb', 'shell', 'rm', PATH_PREFIX + '/' + filename])
|
|
|
|
run(['adb', 'shell', 'am', 'clear-debug-app'])
|
|
|
|
|
2021-07-21 18:56:54 +00:00
|
|
|
|
2021-09-13 22:00:46 +00:00
|
|
|
def convert_channel_to_id(product, channel):
|
|
|
|
if product == PROD_FENIX:
|
|
|
|
mapping = {
|
|
|
|
'release': 'org.mozilla.firefox',
|
|
|
|
'beta': 'org.mozilla.firefox_beta',
|
|
|
|
'nightly': 'org.mozilla.fenix',
|
|
|
|
'debug': 'org.mozilla.fenix.debug'
|
|
|
|
}
|
|
|
|
return mapping[channel]
|
|
|
|
elif product == PROD_GVE:
|
|
|
|
return 'org.mozilla.geckoview_example'
|
2021-01-07 20:11:17 +00:00
|
|
|
|
2021-07-21 18:56:54 +00:00
|
|
|
|
2021-01-07 19:54:56 +00:00
|
|
|
def main():
|
2021-09-13 21:50:17 +00:00
|
|
|
args = parse_args()
|
2021-01-07 19:54:56 +00:00
|
|
|
|
2021-09-13 22:00:46 +00:00
|
|
|
id = convert_channel_to_id(args.product, args.release_channel)
|
2021-01-07 19:54:56 +00:00
|
|
|
filename = id + '-geckoview-config.yaml'
|
2020-12-07 23:17:40 +00:00
|
|
|
|
2021-09-13 21:50:17 +00:00
|
|
|
if args.command == 'activate':
|
2021-01-07 19:54:56 +00:00
|
|
|
push(id, filename)
|
2021-09-13 21:50:17 +00:00
|
|
|
elif args.command == 'deactivate':
|
2021-01-07 19:54:56 +00:00
|
|
|
remove(filename)
|
2020-12-07 23:17:40 +00:00
|
|
|
|
2021-07-21 18:56:54 +00:00
|
|
|
|
2021-01-07 19:54:56 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|