Update V8 to version 4.7.24.
[chromium-blink-merge.git] / tools / profile_chrome / chrome_startup_controller.py
blob84c08d4cb63fc04ff5530794ca932de2bcc5c4ca
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 launch_intent = None
39 if self._url == '':
40 launch_intent = intent.Intent(
41 action='android.intent.action.MAIN',
42 package=self._package_info.package,
43 activity=self._package_info.activity)
44 else:
45 launch_intent = intent.Intent(
46 package=self._package_info.package,
47 activity=self._package_info.activity,
48 data=self._url,
49 extras={'create_new_tab': True})
50 self._device.StartActivity(launch_intent, blocking=True)
52 def _TearDownTracing(self):
53 changer = flag_changer.FlagChanger(
54 self._device, self._package_info.cmdline_file)
55 changer.RemoveFlags(['--trace-startup'])
57 def StartTracing(self, interval):
58 self._SetupTracing()
59 self._logcat_monitor.Start()
61 def StopTracing(self):
62 try:
63 self._trace_file = self._logcat_monitor.WaitFor(
64 self._trace_finish_re).group(1)
65 finally:
66 self._TearDownTracing()
68 def PullTrace(self):
69 # Wait a bit for the browser to finish writing the trace file.
70 time.sleep(3)
71 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/')
72 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file))
73 self._device.PullFile(trace_file, host_file)
74 return host_file