`annotate.py` is used to annotate source files based on profiling data.
-`app_profiler.py` is used to profile Android applications.
+`app_profiler.py` is used to profile Android applications and native programs.
`binary_cache_builder.py` is used to pull libraries from Android devices.
`report_sample.py` is used to generate flamegraph.
+`run_simpleperf_on_device.py` is a simple wrapper to run simpleperf on device.
+
`simpleperf_report_lib.py` provides a python interface for parsing profiling data.
--- /dev/null
+#!/usr/bin/env python
+#
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+"""run_simpleperf_on_device.py:
+ It downloads simpleperf to /data/local/tmp on device, and run it with all given arguments.
+ It saves the time downloading simpleperf and using `adb shell` directly.
+"""
+import subprocess
+import sys
+from utils import *
+
+def main():
+ disable_debug_log()
+ adb = AdbHelper()
+ device_arch = adb.get_device_arch()
+ simpleperf_binary = get_target_binary_path(device_arch, 'simpleperf')
+ adb.check_run(['push', simpleperf_binary, '/data/local/tmp'])
+ adb.check_run(['shell', 'chmod', 'a+x', '/data/local/tmp/simpleperf'])
+ shell_cmd = 'cd /data/local/tmp && ./simpleperf ' + ' '.join(sys.argv[1:])
+ sys.exit(subprocess.call([adb.adb_path, 'shell', shell_cmd]))
+
+if __name__ == '__main__':
+ main()
\ No newline at end of file
for demo in copy_demo_list:
shutil.copytree(os.path.join(from_demo_path, demo), os.path.join(testdata_path, demo))
-class TestExampleBase(unittest.TestCase):
+
+class TestBase(unittest.TestCase):
+ def run_cmd(self, args, return_output=False):
+ if args[0].endswith('.py'):
+ args = [sys.executable] + args
+ try:
+ if not return_output:
+ returncode = subprocess.call(args)
+ else:
+ subproc = subprocess.Popen(args, stdout=subprocess.PIPE)
+ (output_data, _) = subproc.communicate()
+ returncode = subproc.returncode
+ except:
+ returncode = None
+ self.assertEqual(returncode, 0, msg="failed to run cmd: %s" % args)
+ if return_output:
+ return output_data
+
+
+class TestExampleBase(TestBase):
@classmethod
def prepare(cls, example_name, package_name, activity_name, abi=None, adb_root=False):
cls.adb = AdbHelper(enable_switch_to_root=adb_root)
remove("report.txt")
remove("pprof.profile")
- def run_cmd(self, args, return_output=False):
- if args[0].endswith('.py'):
- args = [sys.executable] + args
- try:
- if not return_output:
- returncode = subprocess.call(args)
- else:
- subproc = subprocess.Popen(args, stdout=subprocess.PIPE)
- (output_data, _) = subproc.communicate()
- returncode = subproc.returncode
- except:
- returncode = None
- self.assertEqual(returncode, 0, msg="failed to run cmd: %s" % args)
- if return_output:
- return output_data
-
def run_app_profiler(self, record_arg = "-g --duration 3 -e cpu-cycles:u",
build_binary_cache=True, skip_compile=False, start_activity=True,
native_lib_dir=None):
self.assertAlmostEqual(sleep_percentage, 0.4629, delta=0.0001)
+class TestRunSimpleperfOnDevice(TestBase):
+ def test_smoke(self):
+ self.run_cmd(['run_simpleperf_on_device.py', 'list', '--show-features'])
+
+
def main():
build_testdata()
test_program = unittest.main(failfast=True, exit=False)