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.
9 from pylib
import flag_changer
10 from pylib
.perf
import cache_control
12 from profile_chrome
import controllers
14 class ChromeStartupTracingController(controllers
.BaseController
):
15 def __init__(self
, device
, package_info
, cold
, url
):
17 self
._package
_info
= package_info
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)
25 return 'Browser Startup Trace'
27 def _SetupTracing(self
):
28 # TODO(lizeb): Figure out how to clean up the command-line file when
29 # _TearDownTracing() is not executed in StopTracing().
30 changer
= flag_changer
.FlagChanger(
31 self
._device
, self
._package
_info
.cmdline_file
)
32 changer
.AddFlags(['--trace-startup'])
33 self
._device
.old_interface
.CloseApplication(self
._package
_info
.package
)
35 self
._device
.old_interface
.EnableAdbRoot()
36 cache_control
.CacheControl(self
._device
).DropRamCaches()
37 self
._device
.old_interface
.StartActivity(
38 package
=self
._package
_info
.package
,
39 activity
=self
._package
_info
.activity
,
41 extras
={'create_new_tab' : True})
43 def _TearDownTracing(self
):
44 changer
= flag_changer
.FlagChanger(
45 self
._device
, self
._package
_info
.cmdline_file
)
46 changer
.RemoveFlags(['--trace-startup'])
48 def StartTracing(self
, interval
):
50 self
._device
.old_interface
.SyncLogCat()
52 def StopTracing(self
):
54 self
._trace
_file
= self
._device
.old_interface
.WaitForLogMatch(
55 self
._trace
_finish
_re
, None, timeout
=10).group(1)
57 self
._TearDownTracing
()
60 # Wait a bit for the browser to finish writing the trace file.
62 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 self
._device
.PullFile(trace_file
, host_file
)