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

Unified Diff: systrace/profile_chrome/ddms_controller.py

Issue 1726783002: Copy adb_profile_chrome to catapult (Closed) Base URL: https://github.com/catapult-project/catapult.git@master
Patch Set: add OWNERS file to bin files Created 4 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 side-by-side diff with in-line comments
Download patch
Index: systrace/profile_chrome/ddms_controller.py
diff --git a/systrace/profile_chrome/ddms_controller.py b/systrace/profile_chrome/ddms_controller.py
new file mode 100644
index 0000000000000000000000000000000000000000..3f26297f420b5f7befaf718a16b1b726a4e06887
--- /dev/null
+++ b/systrace/profile_chrome/ddms_controller.py
@@ -0,0 +1,54 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import re
+import time
+
+from profile_chrome import controllers
+from profile_chrome import util
+
+_DDMS_SAMPLING_FREQUENCY_US = 100
+
+
+class DdmsController(controllers.BaseController):
+ def __init__(self, device, package_info):
+ controllers.BaseController.__init__(self)
+ self._device = device
+ self._package = package_info.package
+ self._output_file = None
+ self._supports_sampling = self._SupportsSampling()
+
+ def __repr__(self):
+ return 'ddms profile'
+
+ def _SupportsSampling(self):
+ for line in self._device.RunShellCommand('am --help'):
+ if re.match(r'.*am profile start.*--sampling', line):
+ return True
+ return False
+
+ def StartTracing(self, _):
+ self._output_file = (
+ '/data/local/tmp/ddms-profile-%s' % util.GetTraceTimestamp())
+ cmd = 'am profile start '
+ if self._supports_sampling:
+ cmd += '--sampling %d ' % _DDMS_SAMPLING_FREQUENCY_US
+ cmd += '%s %s' % (self._package, self._output_file)
+ self._device.RunShellCommand(cmd)
+
+ def StopTracing(self):
+ self._device.RunShellCommand('am profile stop %s' % self._package)
+
+ def PullTrace(self):
+ if not self._output_file:
+ return None
+
+ # Wait for the trace file to get written.
+ time.sleep(1)
+
+ host_file = os.path.join(
+ os.path.curdir, os.path.basename(self._output_file))
+ self._device.PullFile(self._output_file, host_file)
+ return host_file
« no previous file with comments | « systrace/profile_chrome/controllers_unittest.py ('k') | systrace/profile_chrome/ddms_controller_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698