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

Side by Side Diff: tools/profile_chrome/chrome_startup_controller.py

Issue 896503002: [Android] Add LogcatMonitor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « tools/profile_chrome/chrome_controller.py ('k') | 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 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 import re 6 import re
7 import time 7 import time
8 8
9 from pylib import flag_changer 9 from pylib import flag_changer
10 from pylib.perf import cache_control 10 from pylib.perf import cache_control
11 11
12 from profile_chrome import controllers 12 from profile_chrome import controllers
13 13
14 class ChromeStartupTracingController(controllers.BaseController): 14 class ChromeStartupTracingController(controllers.BaseController):
15 def __init__(self, device, package_info, cold, url): 15 def __init__(self, device, package_info, cold, url):
16 self._device = device 16 self._device = device
17 self._package_info = package_info 17 self._package_info = package_info
18 self._cold = cold 18 self._cold = cold
19 self._logcat_monitor = self._device.GetLogcatMonitor()
19 self._url = url 20 self._url = url
20 self._trace_file = None 21 self._trace_file = None
21 self._trace_finish_re = re.compile(r' Completed startup tracing to (.*)') 22 self._trace_finish_re = re.compile(r' Completed startup tracing to (.*)')
22 self._device.old_interface.StartMonitoringLogcat(clear=False)
23 23
24 def __repr__(self): 24 def __repr__(self):
25 return 'Browser Startup Trace' 25 return 'Browser Startup Trace'
26 26
27 def _SetupTracing(self): 27 def _SetupTracing(self):
28 # TODO(lizeb): Figure out how to clean up the command-line file when 28 # TODO(lizeb): Figure out how to clean up the command-line file when
29 # _TearDownTracing() is not executed in StopTracing(). 29 # _TearDownTracing() is not executed in StopTracing().
30 changer = flag_changer.FlagChanger( 30 changer = flag_changer.FlagChanger(
31 self._device, self._package_info.cmdline_file) 31 self._device, self._package_info.cmdline_file)
32 changer.AddFlags(['--trace-startup']) 32 changer.AddFlags(['--trace-startup'])
33 self._device.old_interface.CloseApplication(self._package_info.package) 33 self._device.ForceStop(self._package_info.package)
34 if self._cold: 34 if self._cold:
35 self._device.old_interface.EnableAdbRoot() 35 self._device.EnableRoot()
36 cache_control.CacheControl(self._device).DropRamCaches() 36 cache_control.CacheControl(self._device).DropRamCaches()
37 self._device.old_interface.StartActivity( 37 self._device.StartActivity(
38 package=self._package_info.package, 38 intent.Intent(
39 activity=self._package_info.activity, 39 package=self._package_info.package,
40 data=self._url, 40 activity=self._package_info.activity,
41 extras={'create_new_tab' : True}) 41 data=self._url,
42 extras={'create_new_tab' : True}))
42 43
43 def _TearDownTracing(self): 44 def _TearDownTracing(self):
44 changer = flag_changer.FlagChanger( 45 changer = flag_changer.FlagChanger(
45 self._device, self._package_info.cmdline_file) 46 self._device, self._package_info.cmdline_file)
46 changer.RemoveFlags(['--trace-startup']) 47 changer.RemoveFlags(['--trace-startup'])
47 48
48 def StartTracing(self, interval): 49 def StartTracing(self, interval):
49 self._SetupTracing() 50 self._SetupTracing()
50 self._device.old_interface.SyncLogCat() 51 self._logcat_monitor.Start()
51 52
52 def StopTracing(self): 53 def StopTracing(self):
53 try: 54 try:
54 self._trace_file = self._device.old_interface.WaitForLogMatch( 55 self._trace_file = self._logcat_monitor.WaitFor(
55 self._trace_finish_re, None, timeout=10).group(1) 56 self._trace_finish_re).group(1)
56 finally: 57 finally:
57 self._TearDownTracing() 58 self._TearDownTracing()
58 59
59 def PullTrace(self): 60 def PullTrace(self):
60 # Wait a bit for the browser to finish writing the trace file. 61 # Wait a bit for the browser to finish writing the trace file.
61 time.sleep(3) 62 time.sleep(3)
62 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') 63 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/')
63 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) 64 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file))
64 self._device.PullFile(trace_file, host_file) 65 self._device.PullFile(trace_file, host_file)
65 return host_file 66 return host_file
OLDNEW
« no previous file with comments | « tools/profile_chrome/chrome_controller.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698