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

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

Issue 879853002: Add a --startup option to generate combined traces for startup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Typo. 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
OLDNEW
(Empty)
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.
4
5 import os
6 import re
7 import time
8
9 from pylib import flag_changer
10 from pylib.perf import cache_control
11
12 from profile_chrome import controllers
13
14 class ChromeStartupTracingController(controllers.BaseController):
15 def __init__(self, device, package_info, cold, url):
16 self._device = device
17 self._package_info = package_info
18 self._cold = cold
19 self._url = url
20 self._trace_file = None
21 self._trace_finish_re = re.compile(r' Completed startup tracing to (.*)')
22 self._device.old_interface.StartMonitoringLogcat(clear=False)
23
24 def __repr__(self):
25 return 'Browser Startup Trace'
26
27 def _SetupTracing(self):
28 changer = flag_changer.FlagChanger(
29 self._device, self._package_info.cmdline_file)
30 changer.AddFlags(['--trace-startup'])
31 self._device.old_interface.CloseApplication(self._package_info.package)
32 if self._cold:
33 self._device.old_interface.EnableAdbRoot()
34 cache_control.CacheControl(self._device).DropRamCaches()
35 self._device.old_interface.StartActivity(
36 package=self._package_info.package,
37 activity=self._package_info.activity,
38 data=self._url,
39 extras={'create_new_tab' : True})
40
41 def _TearDownTracing(self):
42 changer = flag_changer.FlagChanger(
43 self._device, self._package_info.cmdline_file)
44 changer.RemoveFlags(['--trace-startup'])
45
46 def StartTracing(self, interval):
47 self._SetupTracing()
48 self._device.old_interface.SyncLogCat()
49
50 def StopTracing(self):
51 try:
52 self._trace_file = self._device.old_interface.WaitForLogMatch(
53 self._trace_finish_re, None, timeout=10).group(1)
54 finally:
55 self._TearDownTracing()
56
57 def PullTrace(self):
58 # Wait a bit for the browser to finish writing the trace file.
59 time.sleep(3)
60 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/')
61 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file))
62 self._device.PullFile(trace_file, host_file)
63 return host_file
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698