diff options
author | Valentin Schneider <valentin.schneider@arm.com> | 2017-09-18 11:49:11 +0100 |
---|---|---|
committer | Valentin Schneider <valentin.schneider@arm.com> | 2017-09-18 12:48:01 +0100 |
commit | 211eeb5b8c238f6a2934b92b5bc4200b549f0780 (patch) | |
tree | ab0a38f388bbf211eda678c30357da76ef68ed02 | |
parent | 46660d432e6ecb68dec8ff38180d93ba4e6ec7f0 (diff) | |
download | trappy-211eeb5b8c238f6a2934b92b5bc4200b549f0780.tar.gz |
bare_trace: Fix get_duration() for window use
The previous implementation only looked at the maximum timestamp
of the traces. However, if trace windows are used to analyse a
subset of the full trace, get_duration() would return an
erroneous value:
(times are normalized)
trace = <trace built with window=[5, 10]>
print trace.get_duration()
> 10.0
This commit adds a lower-bound lookup to fix this issue.
tests/test_baretrace.py has also been updated to account
for this change.
-rw-r--r-- | tests/test_baretrace.py | 2 | ||||
-rw-r--r-- | trappy/bare_trace.py | 13 |
2 files changed, 7 insertions, 8 deletions
diff --git a/tests/test_baretrace.py b/tests/test_baretrace.py index 257754d..f1547c3 100644 --- a/tests/test_baretrace.py +++ b/tests/test_baretrace.py @@ -56,7 +56,7 @@ class TestBareTrace(unittest.TestCase): trace.add_parsed_event("pmu_counter", self.dfr[0]) trace.add_parsed_event("load_event", self.dfr[1]) - self.assertEquals(trace.get_duration(), self.dfr[1].index[-1]) + self.assertEquals(trace.get_duration(), self.dfr[1].index[-1] - self.dfr[0].index[0]) def test_bare_trace_get_duration_normalized(self): """BareTrace.get_duration() works if the trace has been normalized""" diff --git a/trappy/bare_trace.py b/trappy/bare_trace.py index a953a60..93a1c6b 100644 --- a/trappy/bare_trace.py +++ b/trappy/bare_trace.py @@ -37,21 +37,20 @@ class BareTrace(object): def get_duration(self): """Returns the largest time value of all classes, returns 0 if the data frames of all classes are empty""" - durations = [] + max_durations = [] + min_durations = [] for trace_class in self.trace_classes: try: - durations.append(trace_class.data_frame.index[-1]) + max_durations.append(trace_class.data_frame.index[-1]) + min_durations.append(trace_class.data_frame.index[0]) except IndexError: pass - if len(durations) == 0: + if len(min_durations) == 0 or len(max_durations) == 0: return 0 - if self.normalized_time: - return max(durations) - else: - return max(durations) - self.basetime + return max(max_durations) - min(min_durations) def get_filters(self, key=""): """Returns an array with the available filters. |