aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Jackman <bjackman@users.noreply.github.com>2017-09-18 14:44:15 +0100
committerGitHub <noreply@github.com>2017-09-18 14:44:15 +0100
commit101592273c8bdf29d95d321a86189666d88a9ddb (patch)
tree16e3202cd82c5c7f2ab5e9abb8e3a261be6cb832
parent957826a0f5991de2c9b31b32274361837aa4406e (diff)
parent581f936a426783d289b0b0ff4e9dfafa874dcddd (diff)
downloadtrappy-101592273c8bdf29d95d321a86189666d88a9ddb.tar.gz
Merge pull request #268 from valschneider/get_duration-fix
bare_trace: Fix get_duration() for window use
-rw-r--r--tests/test_baretrace.py2
-rw-r--r--tests/test_ftrace.py16
-rw-r--r--trappy/bare_trace.py13
3 files changed, 23 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/tests/test_ftrace.py b/tests/test_ftrace.py
index fbc761d..ea702e5 100644
--- a/tests/test_ftrace.py
+++ b/tests/test_ftrace.py
@@ -170,6 +170,22 @@ class TestFTrace(BaseTestThermal):
self.assertEqual(trace.get_duration(), duration)
+ def test_ftrace_duration_window(self):
+ """Test that duration is correct with time window (normalize_time=True)"""
+ trace = trappy.FTrace(normalize_time=True, window=[1, 5])
+
+ duration = trace.thermal_governor.data_frame.index[-1] - trace.thermal.data_frame.index[0]
+
+ self.assertEqual(trace.get_duration(), duration)
+
+ def test_ftrace_duration_window_not_normalized(self):
+ """Test that duration is correct with time window (normalize_time=False)"""
+ trace = trappy.FTrace(normalize_time=False, window=[1, 5])
+
+ duration = trace.thermal_governor.data_frame.index[-1] - trace.thermal.data_frame.index[0]
+
+ self.assertEqual(trace.get_duration(), duration)
+
def test_ftrace_duration_not_normalized(self):
"""Test get_duration: normalize_time=True"""
diff --git a/trappy/bare_trace.py b/trappy/bare_trace.py
index ff4d68d..c2f4b04 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.