aboutsummaryrefslogtreecommitdiff
path: root/trappy
diff options
context:
space:
mode:
authorJoel Fernandes <joelaf@google.com>2017-04-23 02:27:29 -0700
committerJoel Fernandes <joelaf@google.com>2017-06-02 12:49:36 -0700
commitac25b4e59ed854c8ef7139083f5327850ce46973 (patch)
tree9a5b80c73b76b137d6aa69bd3143c78459cb1404 /trappy
parent1d8d74d032697c24977fe026ded7dc74a918625a (diff)
downloadtrappy-ac25b4e59ed854c8ef7139083f5327850ce46973.tar.gz
trappy: Add support for ftrace event callbacks
Event callback are called per-event depending on the trace class, the callback is passed the event's timestamp and a dict of all parsed fields. Signed-off-by: Joel Fernandes <joelaf@google.com>
Diffstat (limited to 'trappy')
-rw-r--r--trappy/base.py6
-rw-r--r--trappy/ftrace.py10
-rw-r--r--trappy/systrace.py5
3 files changed, 16 insertions, 5 deletions
diff --git a/trappy/base.py b/trappy/base.py
index 14de582..41820bf 100644
--- a/trappy/base.py
+++ b/trappy/base.py
@@ -105,6 +105,7 @@ class Base(object):
self.comm_array = []
self.pid_array = []
self.cpu_array = []
+ self.callback = None
self.parse_raw = parse_raw
def finalize_object(self):
@@ -171,6 +172,11 @@ class Base(object):
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)
+
def generate_data_dict(self, comm, pid, cpu, data_str):
data_dict = {"__comm": comm, "__pid": pid, "__cpu": cpu}
prev_key = None
diff --git a/trappy/ftrace.py b/trappy/ftrace.py
index dd0a2fc..2df91b4 100644
--- a/trappy/ftrace.py
+++ b/trappy/ftrace.py
@@ -57,7 +57,8 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
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"):
@@ -76,6 +77,8 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
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)
@@ -490,14 +493,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"""
diff --git a/trappy/systrace.py b/trappy/systrace.py
index 6e917a6..c619011 100644
--- a/trappy/systrace.py
+++ b/trappy/systrace.py
@@ -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()