From dd4af16c44907ffefb6567f522e8ce7637ff3202 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 20 Apr 2017 17:15:15 +0100 Subject: [PATCH 1/3] utils/android: let systrace use the default device A common use-case is to have a single device connected to your host machine and use a notebook to run some experiments. If such a notebook does not specify a device ID we currently raise an exception because we try to access a non existing configuration property. Let the systrace_start API silently use the default device if one if not specified by the target configuration. Signed-off-by: Patrick Bellasi --- libs/utils/android/system.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/utils/android/system.py b/libs/utils/android/system.py index c26b0dd08..ddba9f028 100644 --- a/libs/utils/android/system.py +++ b/libs/utils/android/system.py @@ -47,8 +47,11 @@ class System(object): return None # Format the command according to the specified arguments - systrace_pattern = "{} -e {} -o {} {}" - trace_cmd = systrace_pattern.format(systrace_path, target.conf['device'], + device = target.conf.get('device', '') + if device: + device = "-e {}".format(device) + systrace_pattern = "{} {} -o {} {}" + trace_cmd = systrace_pattern.format(systrace_path, device, trace_file, " ".join(events)) if time is not None: trace_cmd += " -t {}".format(time) -- GitLab From 272ffe5c07c07482b1ee60bac82b02c745515865 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 20 Apr 2017 17:25:11 +0100 Subject: [PATCH 2/3] utils/android: add support to show last collected trace A common usage pattern is to visualise a trace, being either in ftrace or systrace format, which has been collected during the last execution of a workload. This adds a commodity method to the Android::Workload class which allows to visualise the most recently collected trace using the appropriate external visualization tool, i.e. - kernelshark for ftrace - the default browser for systrace Signed-off-by: Patrick Bellasi --- libs/utils/android/workload.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libs/utils/android/workload.py b/libs/utils/android/workload.py index 626b65d50..b7ef3af16 100644 --- a/libs/utils/android/workload.py +++ b/libs/utils/android/workload.py @@ -18,6 +18,7 @@ import logging import os import re +import webbrowser from . import System @@ -134,4 +135,26 @@ class Workload(object): # Dump a platform description self._te.platform_dump(self.out_dir) + def traceShow(self): + """ + Open the collected trace using the most appropriate native viewer. + + The native viewer depends on the specified trace format: + - ftrace: open using kernelshark + - systrace: open using a browser + + In both cases the native viewer is assumed to be available in the host + machine. + """ + + if 'ftrace' in self.collect: + os.popen("kernelshark {}".format(self.trace_file)) + return + + if 'systrace' in self.collect: + webbrowser.open(self.trace_file) + return + + self._log.warning('No trace collected since last run') + # vim :set tabstop=4 shiftwidth=4 expandtab -- GitLab From 7ce0887f7c781f4b9ef8fd294768881eadeb9f5a Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 27 Apr 2017 09:41:31 +0100 Subject: [PATCH 3/3] android/system: add data/wifi/nfc mode control functions The Android `svc` command allows to toggle and tune different subsystems. Data connection, WiFi and NFC are some of the simplest, which can only be toggled on/off. Add a set of utility methods to toggle the state of these systems to a specified mode. Signed-off-by: Patrick Bellasi --- libs/utils/android/system.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/libs/utils/android/system.py b/libs/utils/android/system.py index ddba9f028..3708d9594 100644 --- a/libs/utils/android/system.py +++ b/libs/utils/android/system.py @@ -84,6 +84,37 @@ class System(object): log = logging.getLogger('System') log.warning('Failed to toggle airplane mode, permission denied.') + @staticmethod + def _set_svc(target, cmd, on=True): + mode = 'enable' if on else 'disable' + try: + target.execute('svc {} {}'.format(cmd, mode), as_root=True) + except TargetError: + log = logging.getLogger('System') + log.warning('Failed to toggle {} mode, permission denied.'\ + .format(cmd)) + + @staticmethod + def set_mobile_data(target, on=True): + """ + Set mobile data connectivity + """ + System._set_svc(target, 'data', on) + + @staticmethod + def set_wifi(target, on=True): + """ + Set mobile data connectivity + """ + System._set_svc(target, 'wifi', on) + + @staticmethod + def set_nfc(target, on=True): + """ + Set mobile data connectivity + """ + System._set_svc(target, 'nfc', on) + @staticmethod def start_app(target, apk_name): """ -- GitLab