Skip to content
This repository was archived by the owner on Nov 26, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions trappy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def __init__(self, parse_raw=False):
self.comm_array = []
self.pid_array = []
self.cpu_array = []
self.callback = None
self.parse_raw = parse_raw

def finalize_object(self):
Expand Down Expand Up @@ -171,6 +172,11 @@ def append_data(self, time, comm, pid, cpu, data):
self.cpu_array.append(cpu)
self.data_array.append(data)

if not self.callback:
return
data_dict = self.generate_data_dict(comm, pid, cpu, data)
self.callback(time, data_dict)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not making the callback even more generic by passing back the exact signature used by generate_data_dict?

I'm asking that for two main reasons:

  1. the generate_data_dict can still be used from the callback if required
  2. I have a WIP series which aims at adding parsing for non key-value formatted events, like for example the events injected from user-space by the Android run-time. This is an example of these events:
surfaceflinger-543   (  543) [002] ...1  3210.843141: tracing_mark_write: B|543|query
surfaceflinger-543   (  543) [002] ...1  3210.843145: tracing_mark_write: E
surfaceflinger-543   (  543) [002] ...1  3210.843149: tracing_mark_write: B|543|updateTexImage
surfaceflinger-543   (  543) [002] ...1  3210.843168: tracing_mark_write: B|543|acquireBuffer
surfaceflinger-543   (  543) [002] ...1  3210.843178: tracing_mark_write: B|543|com.prefabulated.touchlatency/com.prefabulated.touchlatency.TouchLatencyActivity#0: 1
surfaceflinger-543   (  543) [002] ...1  3210.843180: tracing_mark_write: E
surfaceflinger-543   (  543) [002] ...1  3210.843187: tracing_mark_write: C|543|com.prefabulated.touchlatency/com.prefabulated.touchlatency.TouchLatencyActivity#0|0
surfaceflinger-543   (  543) [002] ...1  3210.843208: tracing_mark_write: E

As you can see, the data portion of these events cannot be parsed by generate_data_dict.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't follow how you wanted this done, can you give an example?

I think if this is to be made generic, it should be made so internal to trappy. The user's callback implementation shouldn't have any business with parsing strings in my opinion, trappy should parse them in a generic way and pass some generic data type to the callback. so in your trace for systrace, it should pass to the callback something like { '__comm': 'surfaceflinger', __pid: 543, 'mark': 'begin', 'name': 'query' }


def generate_data_dict(self, comm, pid, cpu, data_str):
data_dict = {"__comm": comm, "__pid": pid, "__cpu": cpu}
prev_key = None
Expand Down
10 changes: 7 additions & 3 deletions trappy/ftrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class GenericFTrace(BareTrace):
dynamic_classes = {}

def __init__(self, name="", normalize_time=True, scope="all",
events=[], window=(0, None), abs_window=(0, None)):
events=[], event_callbacks={}, window=(0, None),
abs_window=(0, None)):
super(GenericFTrace, self).__init__(name)

if not hasattr(self, "needs_raw_parsing"):
Expand All @@ -73,6 +74,8 @@ def __init__(self, name="", normalize_time=True, scope="all",

for attr, class_def in self.class_definitions.iteritems():
trace_class = class_def()
if event_callbacks.has_key(attr):
trace_class.callback = event_callbacks[attr]
setattr(self, attr, trace_class)
self.trace_classes.append(trace_class)

Expand Down Expand Up @@ -480,14 +483,15 @@ class FTrace(GenericFTrace):
"""

def __init__(self, path=".", name="", normalize_time=True, scope="all",
events=[], window=(0, None), abs_window=(0, None)):
events=[], event_callbacks={}, window=(0, None),
abs_window=(0, None)):
self.trace_path, self.trace_path_raw = self.__process_path(path)
self.needs_raw_parsing = True

self.__populate_metadata()

super(FTrace, self).__init__(name, normalize_time, scope, events,
window, abs_window)
event_callbacks, window, abs_window)

def __process_path(self, basepath):
"""Process the path and return the path to the trace text file"""
Expand Down
5 changes: 3 additions & 2 deletions trappy/systrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ class SysTrace(GenericFTrace):
"""

def __init__(self, path=".", name="", normalize_time=True, scope="all",
events=[], window=(0, None), abs_window=(0, None)):
events=[], event_callbacks={}, window=(0, None),
abs_window=(0, None)):

self.trace_path = path

super(SysTrace, self).__init__(name, normalize_time, scope, events,
window, abs_window)
event_callbacks, window, abs_window)

try:
self._cpus = 1 + self.sched_switch.data_frame["__cpu"].max()
Expand Down