diff options
Diffstat (limited to 'trappy/systrace.py')
-rw-r--r-- | trappy/systrace.py | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/trappy/systrace.py b/trappy/systrace.py index c11601d..c7e65e4 100644 --- a/trappy/systrace.py +++ b/trappy/systrace.py @@ -14,6 +14,10 @@ # from trappy.ftrace import GenericFTrace +import re + +SYSTRACE_EVENT = re.compile( + r'^(?P<event>[A-Z])(\|(?P<pid>\d+)\|(?P<func>[^|]*)(\|(?P<data>.*))?)?') class drop_before_trace(object): """Object that, when called, returns True if the line is not part of @@ -23,24 +27,26 @@ the trace the headers that start with # """ - def __init__(self): + def __init__(self, tracer): self.before_begin_trace = True - self.before_script_trace_data = True self.before_actual_trace = True + self.tracer = tracer def __call__(self, line): if self.before_begin_trace: if line.startswith("<!-- BEGIN TRACE -->") or \ line.startswith("<title>Android System Trace</title>"): self.before_begin_trace = False - elif self.before_script_trace_data: + elif self.before_actual_trace: if line.startswith(' <script class="trace-data"') or \ line.startswith(" var linuxPerfData"): - self.before_script_trace_data = False - elif not line.startswith("#"): - self.before_actual_trace = False + self.before_actual_trace = False - return self.before_actual_trace + if not self.before_actual_trace: + base_call = super(SysTrace, self.tracer).trace_hasnt_started() + return base_call(line) + else: + return True class SysTrace(GenericFTrace): """A wrapper that parses all events of a SysTrace run @@ -50,23 +56,21 @@ class SysTrace(GenericFTrace): """ def __init__(self, path=".", name="", normalize_time=True, scope="all", - events=[], event_callbacks={}, window=(0, None), - abs_window=(0, None), build_df=True): + events=[], window=(0, None), abs_window=(0, None)): self.trace_path = path super(SysTrace, self).__init__(name, normalize_time, scope, events, - event_callbacks, window, abs_window, - build_df) - if not build_df: - return + window, abs_window) + + self._do_parse() try: self._cpus = 1 + self.sched_switch.data_frame["__cpu"].max() except AttributeError: pass def trace_hasnt_started(self): - return drop_before_trace() + return drop_before_trace(self) def trace_hasnt_finished(self): """Return a function that returns True while the current line is still part of the trace @@ -78,3 +82,18 @@ class SysTrace(GenericFTrace): """ return lambda x: not x.endswith("</script>\n") + + def generate_data_dict(self, data_str): + """ Custom parsing for systrace's userspace events """ + data_dict = None + + match = SYSTRACE_EVENT.match(data_str) + if match: + data_dict = { + 'event': match.group('event'), + 'pid' : int(match.group('pid')) if match.group('pid') else None, + 'func' : match.group('func' ), + 'data' : match.group('data' ) + } + + return data_dict |