diff --git a/tests/test_systrace.py b/tests/test_systrace.py index 608ed8ec715be341853a99739c9e8470b2812d01..55480813f40f35835e39f172714a9cb5e4776e16 100644 --- a/tests/test_systrace.py +++ b/tests/test_systrace.py @@ -39,10 +39,6 @@ class TestSystrace(utils_tests.SetupDirectory): self.assertEquals(len(trace.sched_wakeup.data_frame), 4) self.assertTrue("target_cpu" in trace.sched_wakeup.data_frame.columns) - self.assertTrue(hasattr(trace, "trace_event_clock_sync")) - self.assertEquals(len(trace.trace_event_clock_sync.data_frame), 1) - self.assertTrue("realtime_ts" in trace.trace_event_clock_sync.data_frame.columns) - def test_cpu_counting(self): """SysTrace traces know the number of cpus""" diff --git a/trappy/ftrace.py b/trappy/ftrace.py index 6a5fce0a3e7946f754c9eb2d58d552c6d79ba961..89d485e22f8f30d5007947f36c8226b69bde5bad 100644 --- a/trappy/ftrace.py +++ b/trappy/ftrace.py @@ -156,6 +156,11 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace.""" trace_class = DynamicTypeFactory(event_name, (Base,), kwords) self.class_definitions[event_name] = trace_class + def format_data(self, unique_word, data_str): + """Reformat data before parsing + """ + return data_str + def __populate_data(self, fin, cls_for_unique_word, window, abs_window): """Append to trace data from a txt trace""" @@ -202,12 +207,16 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace.""" (abs_window[1] and timestamp > abs_window[1]): return + # Allow the trace class to reformat data + data_str = line[line.find(unique_word) + len(unique_word):] + data_str = self.format_data(unique_word, data_str) + try: - data_start_idx = start_match.search(line).start() + data_start_idx = start_match.search(data_str).start() except AttributeError: continue - data_str = line[data_start_idx:] + data_str = data_str[data_start_idx:] # Remove empty arrays from the trace data_str = re.sub(r"[A-Za-z0-9_]+=\{\} ", r"", data_str) diff --git a/trappy/systrace.py b/trappy/systrace.py index 6e917a6515e4e0d25d2d10290e424af6ce7bc42c..bf0f54996517716c5c4758e1a65b314cafb8e216 100644 --- a/trappy/systrace.py +++ b/trappy/systrace.py @@ -13,7 +13,10 @@ # limitations under the License. # +import re + from trappy.ftrace import GenericFTrace +from trappy.utils import listify class drop_before_trace(object): """Object that, when called, returns True if the line is not part of @@ -54,6 +57,13 @@ class SysTrace(GenericFTrace): self.trace_path = path + # Android injects useful events from userspace, unfortunately not using + # a specific attention word. Thus, let's capture tracing_mark events + # and reformat them in a local format_data callback. + events = listify(events) + if 'tracing_mark_write' not in events: + events.append('tracing_mark_write') + super(SysTrace, self).__init__(name, normalize_time, scope, events, window, abs_window) @@ -75,3 +85,24 @@ class SysTrace(GenericFTrace): """ return lambda x: not x.endswith("\n") + + def format_data(self, unique_word, data_str): + if unique_word != 'tracing_mark_write:': + return data_str + + # Disacrd not useful clock synchronization events + if 'trace_event_clock_sync' in data_str: + return '' + + match = SYSTRACE_EVENT.match(data_str) + if match: + data_str = "event={} pid={} func={} data={}".format( + match.group('event'), match.group('pid'), + match.group('func'), match.group('data')) + return data_str + + raise ValueError('Unexpected systrace marker: {}'.format(data_str)) + return data_str + +SYSTRACE_EVENT = re.compile( + r'^ (?P[A-Z])(\|(?P\d+)\|(?P.*)(\|(?P\d+))?)?')