From 57460edd3557af6f1843be273768f3d39d5e2a8c Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 20 Apr 2017 17:15:15 +0100 Subject: [PATCH 1/2] utils/android: when not specified systrace the use 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's the systrace_start API silently use the default device if not specified by the target configuration. Signed-off-by: Patrick Bellasi --- libs/utils/android/system.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/utils/android/system.py b/libs/utils/android/system.py index 42e8c4dec..f863ca3ef 100644 --- a/libs/utils/android/system.py +++ b/libs/utils/android/system.py @@ -47,8 +47,12 @@ 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'], + try: + device = "-e {}".format(target.conf['device']) + except: + 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 deaa8f585c971331790e2cf4f1deb53d9d773d63 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 20 Apr 2017 17:25:11 +0100 Subject: [PATCH 2/2] 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 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libs/utils/android/workload.py b/libs/utils/android/workload.py index 626b65d50..a42f77256 100644 --- a/libs/utils/android/workload.py +++ b/libs/utils/android/workload.py @@ -134,4 +134,31 @@ 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: + if os.name == 'posix': + os.popen("xdg-open {}".format(self.trace_file)) + elif sys.platform.startswith('darwin'): + os.popen("open {}".format(self.trace_file)) + elif os.name == 'nt': + os.startfile(self.trace_file) + return + + self._log.warning('No trace collected since last run') + # vim :set tabstop=4 shiftwidth=4 expandtab -- GitLab