Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: tools/cygprofile/profile_android_startup.py

Issue 2614483002: [android] Make profile_android_startup.py runnable on its own. (Closed)
Patch Set: prereview: fixes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #! /usr/bin/env python
1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 4 # found in the LICENSE file.
4 5
5 """Utility library for running a startup profile on an Android device. 6 """Utility library for running a startup profile on an Android device.
6 7
7 Sets up a device for cygprofile, disables sandboxing permissions, and sets up 8 Sets up a device for cygprofile, disables sandboxing permissions, and sets up
8 support for web page replay, device forwarding, and fake certificate authority 9 support for web page replay, device forwarding, and fake certificate authority
9 to make runs repeatable. 10 to make runs repeatable.
10 """ 11 """
11 12
13 import argparse
12 import logging 14 import logging
13 import os 15 import os
14 import shutil 16 import shutil
15 import subprocess 17 import subprocess
16 import sys 18 import sys
17 import tempfile 19 import tempfile
18 import time 20 import time
19 21
20 sys.path.append(os.path.join(sys.path[0], '..', '..', 22 sys.path.append(os.path.join(sys.path[0], '..', '..',
21 'third_party', 'catapult', 'devil')) 23 'third_party', 'catapult', 'devil'))
24 from devil.android import apk_helper
22 from devil.android import device_errors 25 from devil.android import device_errors
23 from devil.android import device_utils 26 from devil.android import device_utils
24 from devil.android import flag_changer 27 from devil.android import flag_changer
25 from devil.android import forwarder 28 from devil.android import forwarder
26 from devil.android.sdk import intent 29 from devil.android.sdk import intent
27 30
28 sys.path.append(os.path.join(sys.path[0], '..', '..', 'build', 'android')) 31 sys.path.append(os.path.join(sys.path[0], '..', '..', 'build', 'android'))
32 import devil_chromium
29 from pylib import constants 33 from pylib import constants
30 34
31 sys.path.append(os.path.join(sys.path[0], '..', '..', 'tools', 'perf')) 35 sys.path.append(os.path.join(sys.path[0], '..', '..', 'tools', 'perf'))
32 from chrome_telemetry_build import chromium_config 36 from chrome_telemetry_build import chromium_config
33 sys.path.append(chromium_config.GetTelemetryDir()) 37 sys.path.append(chromium_config.GetTelemetryDir())
34 from telemetry.internal.util import wpr_server 38 from telemetry.internal.util import wpr_server
35 39
36 sys.path.append(os.path.join(sys.path[0], '..', '..', 40 sys.path.append(os.path.join(sys.path[0], '..', '..',
37 'third_party', 'webpagereplay')) 41 'third_party', 'webpagereplay'))
38 import adb_install_cert 42 import adb_install_cert
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 200
197 _DEVICE_CYGLOG_DIR = '/data/local/tmp/chrome/cyglog' 201 _DEVICE_CYGLOG_DIR = '/data/local/tmp/chrome/cyglog'
198 202
199 # TEST_URL must be a url in the WPR_ARCHIVE. 203 # TEST_URL must be a url in the WPR_ARCHIVE.
200 _TEST_URL = 'https://www.google.com/#hl=en&q=science' 204 _TEST_URL = 'https://www.google.com/#hl=en&q=science'
201 _WPR_ARCHIVE = os.path.join( 205 _WPR_ARCHIVE = os.path.join(
202 constants.DIR_SOURCE_ROOT, 'tools', 'perf', 'page_sets', 'data', 206 constants.DIR_SOURCE_ROOT, 'tools', 'perf', 'page_sets', 'data',
203 'top_10_mobile_002.wpr') 207 'top_10_mobile_002.wpr')
204 208
205 209
206 def __init__(self, output_directory): 210 def __init__(self, output_directory, host_cyglog_dir=None):
pasko 2017/01/04 14:17:24 why do we need this be optional? is it hard to mak
jbudorick 2017/01/04 15:11:52 Doing so in this CL would break the downstream use
pasko 2017/01/04 15:44:14 OK, sure, please add a TODO to make this a mandato
jbudorick 2017/01/04 17:08:51 Done.
207 devices = device_utils.DeviceUtils.HealthyDevices() 211 devices = device_utils.DeviceUtils.HealthyDevices()
208 self._device = devices[0] 212 self._device = devices[0]
209 self._cygprofile_tests = os.path.join( 213 self._cygprofile_tests = os.path.join(
210 output_directory, 'cygprofile_unittests') 214 output_directory, 'cygprofile_unittests')
211 self._host_cyglog_dir = os.path.join( 215 self._host_cyglog_dir = host_cyglog_dir or os.path.join(
212 output_directory, 'cyglog_data') 216 output_directory, 'cyglog_data')
213 self._SetUpDevice() 217 self._SetUpDevice()
214 218
215 def RunCygprofileTests(self): 219 def RunCygprofileTests(self):
216 """Run the cygprofile unit tests suite on the device. 220 """Run the cygprofile unit tests suite on the device.
217 221
218 Args: 222 Args:
219 path_to_tests: The location on the host machine with the compiled 223 path_to_tests: The location on the host machine with the compiled
220 cygprofile test binary. 224 cygprofile test binary.
221 Returns: 225 Returns:
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 # Temporary workaround/investigation: if (for unknown reason) 'adb pull' of 368 # Temporary workaround/investigation: if (for unknown reason) 'adb pull' of
365 # the directory 'cyglog' into '.../Release/cyglog_data' produces 369 # the directory 'cyglog' into '.../Release/cyglog_data' produces
366 # '...cyglog_data/cyglog/files' instead of the usual '...cyglog_data/files', 370 # '...cyglog_data/cyglog/files' instead of the usual '...cyglog_data/files',
367 # list the files deeper in the tree. 371 # list the files deeper in the tree.
368 cyglog_dir = self._host_cyglog_dir 372 cyglog_dir = self._host_cyglog_dir
369 if (len(files) == 1) and (files[0] == 'cyglog'): 373 if (len(files) == 1) and (files[0] == 'cyglog'):
370 cyglog_dir = os.path.join(self._host_cyglog_dir, 'cyglog') 374 cyglog_dir = os.path.join(self._host_cyglog_dir, 'cyglog')
371 files = os.listdir(cyglog_dir) 375 files = os.listdir(cyglog_dir)
372 376
373 return [os.path.join(cyglog_dir, x) for x in files] 377 return [os.path.join(cyglog_dir, x) for x in files]
378
379
380 def main(raw_args):
381 parser = argparse.ArgumentParser()
382 parser.add_argument(
383 '--adb-path', type=os.path.realpath,
384 help='adb binary')
385 parser.add_argument(
386 '--apk-path', type=os.path.realpath, required=True,
387 help='APK to profile')
388 parser.add_argument(
389 '--output-directory', type=os.path.realpath, required=True,
390 help='Chromium output directory (e.g. out/Release)')
391 parser.add_argument(
392 '--trace-directory', type=os.path.realpath,
393 help='Directory in which cyglog traces will be stored. '
394 'Defaults to <output-directory>/cyglog_data')
395
396 args = parser.parse_args(raw_args)
pasko 2017/01/04 14:17:24 why not just parser.parse_args()?
jbudorick 2017/01/04 15:11:52 This is a habit I've been getting into s.t. other
pasko 2017/01/04 15:44:14 ah, ok. I'm probably from a different universe (C
397
398 devil_chromium.Initialize(
399 output_directory=args.output_directory, adb_path=args.adb_path)
400
401 apk = apk_helper.ApkHelper(args.apk_path)
402 package_info = None
403 for p in constants.PACKAGE_INFO.itervalues():
404 if p.package == apk.GetPackageName():
405 package_info = p
406 break
407 else:
408 raise Exception('Unable to determine package info for %s' % args.apk_path)
409
410 profiler = AndroidProfileTool(
411 args.output_directory, host_cyglog_dir=args.trace_directory)
412 profiler.CollectProfile(args.apk_path, package_info)
413 return 0
414
415
416 if __name__ == '__main__':
417 sys.exit(main(sys.argv[1:]))
418
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698