Switch TestFrameNavigationObserver to DidCommitProvisionalLoadForFrame.
[chromium-blink-merge.git] / tools / profile_chrome / chrome_startup_controller.py
blob87353e3fbf4050c8b8c70c9246e268f54bcedb74
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
3 # found in the LICENSE file.
5 import os
6 import re
7 import time
9 from pylib import flag_changer
10 from pylib.device import intent
11 from pylib.perf import cache_control
13 from profile_chrome import controllers
15 class ChromeStartupTracingController(controllers.BaseController):
16 def __init__(self, device, package_info, cold, url):
17 self._device = device
18 self._package_info = package_info
19 self._cold = cold
20 self._logcat_monitor = self._device.GetLogcatMonitor()
21 self._url = url
22 self._trace_file = None
23 self._trace_finish_re = re.compile(r' Completed startup tracing to (.*)')
25 def __repr__(self):
26 return 'Browser Startup Trace'
28 def _SetupTracing(self):
29 # TODO(lizeb): Figure out how to clean up the command-line file when
30 # _TearDownTracing() is not executed in StopTracing().
31 changer = flag_changer.FlagChanger(
32 self._device, self._package_info.cmdline_file)
33 changer.AddFlags(['--trace-startup'])
34 self._device.ForceStop(self._package_info.package)
35 if self._cold:
36 self._device.EnableRoot()
37 cache_control.CacheControl(self._device).DropRamCaches()
38 self._device.StartActivity(
39 intent.Intent(
40 package=self._package_info.package,
41 activity=self._package_info.activity,
42 data=self._url,
43 extras={'create_new_tab' : True}), blocking=True)
45 def _TearDownTracing(self):
46 changer = flag_changer.FlagChanger(
47 self._device, self._package_info.cmdline_file)
48 changer.RemoveFlags(['--trace-startup'])
50 def StartTracing(self, interval):
51 self._SetupTracing()
52 self._logcat_monitor.Start()
54 def StopTracing(self):
55 try:
56 self._trace_file = self._logcat_monitor.WaitFor(
57 self._trace_finish_re).group(1)
58 finally:
59 self._TearDownTracing()
61 def PullTrace(self):
62 # Wait a bit for the browser to finish writing the trace file.
63 time.sleep(3)
64 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/')
65 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file))
66 self._device.PullFile(trace_file, host_file)
67 return host_file