aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Redpath <chris.redpath@arm.com>2017-06-17 17:19:55 +0100
committerKP Singh <kpsingh@google.com>2017-06-27 12:08:09 +0200
commitb01c848f3928dfcdf2f3d7dae1343bbe677847ef (patch)
tree7a8c70dc08c9f1bea3f7c47ee6db67c91e197429
parent55c392261a854cd219ec985cbd042e75ec0e922f (diff)
downloadtrappy-b01c848f3928dfcdf2f3d7dae1343bbe677847ef.tar.gz
trappy/Parsing: Split trace class init into two phases
This patch set is to modify the parsing step so that we don't need to build a raw and a formatted trace file. To do that, we need to know which events should have raw output and which should use their default formatting. The events indicate which are which, but currently we generate the trace files before we populate the events. Splitting the initialisation into two parts means that we can populate the events so that a later patch can create the text trace with each event either formatted or raw as required. Signed-off-by: Chris Redpath <chris.redpath@arm.com> Reviewed-by: KP Singh <kpsingh@google.com>
-rw-r--r--tests/test_baretrace.py4
-rw-r--r--tests/test_ftrace.py4
-rw-r--r--trappy/bare_trace.py2
-rw-r--r--trappy/ftrace.py40
-rw-r--r--trappy/systrace.py1
5 files changed, 27 insertions, 24 deletions
diff --git a/tests/test_baretrace.py b/tests/test_baretrace.py
index 33d872c..257754d 100644
--- a/tests/test_baretrace.py
+++ b/tests/test_baretrace.py
@@ -66,7 +66,7 @@ class TestBareTrace(unittest.TestCase):
trace.add_parsed_event("load_event", self.dfr[1].copy())
basetime = self.dfr[0].index[0]
- trace.normalize_time(basetime)
+ trace._normalize_time(basetime)
expected_duration = self.dfr[1].index[-1] - basetime
self.assertEquals(trace.get_duration(), expected_duration)
@@ -80,7 +80,7 @@ class TestBareTrace(unittest.TestCase):
prev_first_time = trace.pmu_counter.data_frame.index[0]
basetime = 3
- trace.normalize_time(basetime)
+ trace._normalize_time(basetime)
self.assertEquals(trace.basetime, basetime)
diff --git a/tests/test_ftrace.py b/tests/test_ftrace.py
index 1377c68..91ea8e3 100644
--- a/tests/test_ftrace.py
+++ b/tests/test_ftrace.py
@@ -181,14 +181,14 @@ class TestFTrace(BaseTestThermal):
def test_ftrace_normalize_time(self):
- """FTrace().normalize_time() works accross all classes"""
+ """FTrace()._normalize_time() works accross all classes"""
trace = trappy.FTrace(normalize_time=False)
prev_inpower_basetime = trace.cpu_in_power.data_frame.index[0]
prev_inpower_last = trace.cpu_in_power.data_frame.index[-1]
- trace.normalize_time()
+ trace._normalize_time()
self.assertEquals(round(trace.thermal.data_frame.index[0], 7), 0)
diff --git a/trappy/bare_trace.py b/trappy/bare_trace.py
index 2d4400b..e4fec48 100644
--- a/trappy/bare_trace.py
+++ b/trappy/bare_trace.py
@@ -67,7 +67,7 @@ class BareTrace(object):
return filters
- def normalize_time(self, basetime=None):
+ def _normalize_time(self, basetime=None):
"""Normalize the time of all the trace classes
:param basetime: The offset which needs to be subtracted from
diff --git a/trappy/ftrace.py b/trappy/ftrace.py
index 213a870..eb3bba5 100644
--- a/trappy/ftrace.py
+++ b/trappy/ftrace.py
@@ -85,14 +85,10 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
setattr(self, attr, trace_class)
self.trace_classes.append(trace_class)
- self.__parse_trace_file(self.trace_path, window, abs_window)
- if self.needs_raw_parsing and (self.trace_path_raw is not None):
- self.__parse_trace_file(self.trace_path_raw, window, abs_window,
- raw=True)
- self.finalize_objects()
-
- if normalize_time:
- self.normalize_time()
+ # save parameters to complete init later
+ self.normalize_time = normalize_time
+ self.window = window
+ self.abs_window = abs_window
@classmethod
def register_parser(cls, cobject, scope):
@@ -133,6 +129,13 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
if cobject == obj:
del scope_classes[name]
+ def _do_parse(self):
+ self.__parse_trace_file(self.trace_path)
+ self.finalize_objects()
+
+ if self.normalize_time:
+ self._normalize_time()
+
def __add_events(self, events):
"""Add events to the class_definitions
@@ -165,7 +168,7 @@ 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 __populate_data(self, fin, cls_for_unique_word, window, abs_window):
+ def __populate_data(self, fin, cls_for_unique_word):
"""Append to trace data from a txt trace"""
def contains_unique_word(line, unique_words=cls_for_unique_word.keys()):
@@ -212,13 +215,13 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
if not self.basetime:
self.basetime = timestamp
- if (timestamp < window[0] + self.basetime) or \
- (timestamp < abs_window[0]):
+ if (timestamp < self.window[0] + self.basetime) or \
+ (timestamp < self.abs_window[0]):
self.lines += 1
continue
- if (window[1] and timestamp > window[1] + self.basetime) or \
- (abs_window[1] and timestamp > abs_window[1]):
+ if (self.window[1] and timestamp > self.window[1] + self.basetime) or \
+ (self.abs_window[1] and timestamp > self.abs_window[1]):
return
# Remove empty arrays from the trace
@@ -258,7 +261,7 @@ is part of the trace.
"""
return lambda x: True
- def __parse_trace_file(self, trace_file, window, abs_window, raw=False):
+ def __parse_trace_file(self, trace_file):
"""parse the trace and create a pandas DataFrame"""
# Memoize the unique words to speed up parsing the trace file
@@ -279,7 +282,7 @@ is part of the trace.
with open(trace_file) as fin:
self.lines = 0
self.__populate_data(
- fin, cls_for_unique_word, window, abs_window)
+ fin, cls_for_unique_word)
except FTraceParseError as e:
raise ValueError('Failed to parse ftrace file {}:\n{}'.format(
trace_file, str(e)))
@@ -500,13 +503,12 @@ class FTrace(GenericFTrace):
def __init__(self, path=".", name="", normalize_time=True, scope="all",
events=[], 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)
+ self.trace_path, self.trace_path_raw = self.__process_path(path)
+ self.__populate_metadata()
+ self._do_parse()
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 2404f92..c7e65e4 100644
--- a/trappy/systrace.py
+++ b/trappy/systrace.py
@@ -63,6 +63,7 @@ class SysTrace(GenericFTrace):
super(SysTrace, self).__init__(name, normalize_time, scope, events,
window, abs_window)
+ self._do_parse()
try:
self._cpus = 1 + self.sched_switch.data_frame["__cpu"].max()
except AttributeError: