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 profile_chrome
import controllers
10 from profile_chrome
import util
12 _DDMS_SAMPLING_FREQUENCY_US
= 100
15 class DdmsController(controllers
.BaseController
):
16 def __init__(self
, device
, package_info
):
17 controllers
.BaseController
.__init
__(self
)
19 self
._package
= package_info
.package
20 self
._output
_file
= None
21 self
._supports
_sampling
= self
._SupportsSampling
()
26 def _SupportsSampling(self
):
27 for line
in self
._device
.RunShellCommand('am --help'):
28 if re
.match(r
'.*am profile start.*--sampling', line
):
32 def StartTracing(self
, _
):
34 '/data/local/tmp/ddms-profile-%s' % util
.GetTraceTimestamp())
35 cmd
= 'am profile start '
36 if self
._supports
_sampling
:
37 cmd
+= '--sampling %d ' % _DDMS_SAMPLING_FREQUENCY_US
38 cmd
+= '%s %s' % (self
._package
, self
._output
_file
)
39 self
._device
.RunShellCommand(cmd
)
41 def StopTracing(self
):
42 self
._device
.RunShellCommand('am profile stop %s' % self
._package
)
45 if not self
._output
_file
:
48 # Wait for the trace file to get written.
51 host_file
= os
.path
.join(
52 os
.path
.curdir
, os
.path
.basename(self
._output
_file
))
53 self
._device
.PullFile(self
._output
_file
, host_file
)