Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #268 from valschneider/get_duration-fix
Browse files Browse the repository at this point in the history
bare_trace: Fix get_duration() for window use
  • Loading branch information
bjackman authored Sep 18, 2017
2 parents 957826a + 581f936 commit 1015922
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/test_baretrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_bare_trace_get_duration(self):
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"""
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ftrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ def test_ftrace_duration(self):

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"""

Expand Down
13 changes: 6 additions & 7 deletions trappy/bare_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,20 @@ def __init__(self, name=""):
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.
Expand Down

0 comments on commit 1015922

Please sign in to comment.