diff options
author | Javi Merino <javi.merino@arm.com> | 2015-12-21 17:20:12 +0000 |
---|---|---|
committer | Javi Merino <javi.merino@arm.com> | 2015-12-22 16:02:42 +0000 |
commit | 08f3c34d0a24e7ffeff543e302efc911306e7bea (patch) | |
tree | aaeed6bc426dc72a11093e0d73648ce42cab1513 /tests | |
parent | 4c0e5505be736c393a47880583ea053addf035d8 (diff) | |
download | trappy-08f3c34d0a24e7ffeff543e302efc911306e7bea.tar.gz |
bare_trace: abstract some of the basic FTrace functionality to a generic BareTrace class
Part of the functionality in FTrace is generic. In order to make the
rest of trappy less dependent on FTrace, move the generic parts to a new
BareTrace class and inherit from it.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_baretrace.py | 88 | ||||
-rw-r--r-- | tests/test_ftrace.py | 36 |
2 files changed, 88 insertions, 36 deletions
diff --git a/tests/test_baretrace.py b/tests/test_baretrace.py new file mode 100644 index 0000000..4692d0a --- /dev/null +++ b/tests/test_baretrace.py @@ -0,0 +1,88 @@ +# Copyright 2015-2015 ARM Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import pandas as pd +import trappy +import unittest + +class TestBareTrace(unittest.TestCase): + def __init__(self, *args, **kwargs): + super(TestBareTrace, self).__init__(*args, **kwargs) + dfr0 = pd.DataFrame({"l1_misses": [24, 535, 41], + "l2_misses": [155, 11, 200], + "cpu": [ 0, 1, 0]}, + index=pd.Series([1.020, 1.342, 1.451], name="Time")) + + dfr1 = pd.DataFrame({"load": [ 35, 16, 21, 28], + "util": [279, 831, 554, 843]}, + index=pd.Series([1.279, 1.718, 2.243, 2.465], name="Time")) + + self.dfr = [dfr0, dfr1] + + def test_bare_trace_accepts_name(self): + """The BareTrace() accepts a name parameter""" + + trace = trappy.BareTrace(name="foo") + + self.assertEquals(trace.name, "foo") + + def test_bare_trace_can_add_parsed_event(self): + """The BareTrace() class can add parsed events to its collection of trace events""" + trace = trappy.BareTrace() + trace.add_parsed_event("pmu_counters", self.dfr[0]) + + self.assertEquals(len(trace.pmu_counters.data_frame), 3) + self.assertEquals(trace.pmu_counters.data_frame["l1_misses"].iloc[0], 24) + + trace.add_parsed_event("pivoted_counters", self.dfr[0], pivot="cpu") + self.assertEquals(trace.pivoted_counters.pivot, "cpu") + + def test_bare_trace_get_duration(self): + """BareTrace.get_duration() works for a simple case""" + + trace = trappy.BareTrace() + 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]) + + def test_bare_trace_get_duration_normalized(self): + """BareTrace.get_duration() works if the trace has been normalized""" + + trace = trappy.BareTrace() + trace.add_parsed_event("pmu_counter", self.dfr[0].copy()) + trace.add_parsed_event("load_event", self.dfr[1].copy()) + + basetime = self.dfr[0].index[0] + trace.normalize_time(basetime) + + expected_duration = self.dfr[1].index[-1] - basetime + self.assertEquals(trace.get_duration(), expected_duration) + + def test_bare_trace_normalize_time_accepts_basetime(self): + """BareTrace().normalize_time() accepts an arbitrary basetime""" + + trace = trappy.BareTrace() + trace.add_parsed_event("pmu_counter", self.dfr[0].copy()) + + prev_first_time = trace.pmu_counter.data_frame.index[0] + basetime = 3 + + trace.normalize_time(basetime) + + self.assertEquals(trace.basetime, basetime) + + exp_first_time = prev_first_time - basetime + self.assertEquals(round(trace.pmu_counter.data_frame.index[0] - exp_first_time, 7), 0) diff --git a/tests/test_ftrace.py b/tests/test_ftrace.py index 9f9dd2d..c9e5494 100644 --- a/tests/test_ftrace.py +++ b/tests/test_ftrace.py @@ -87,20 +87,6 @@ class TestFTrace(BaseTestThermal): self.assertTrue(hasattr(trace, "a_dynamic_event")) - def test_ftrace_can_add_parsed_event(self): - """The FTrace() class can add parsed events to its collection of trace events""" - trace = trappy.FTrace(scope="custom") - dfr = pd.DataFrame({"l1_misses": [24, 535, 41], - "l2_misses": [155, 11, 200], - "cpu": [ 0, 1, 0]}, - index=pd.Series([1.020, 1.342, 1.451], name="Time")) - trace.add_parsed_event("pmu_counters", dfr) - - self.assertEquals(len(trace.pmu_counters.data_frame), 3) - self.assertEquals(trace.pmu_counters.data_frame["l1_misses"].iloc[0], 24) - - trace.add_parsed_event("pivoted_counters", dfr, pivot="cpu") - self.assertEquals(trace.pivoted_counters.pivot, "cpu") def test_ftrace_doesnt_overwrite_parsed_event(self): """FTrace().add_parsed_event() should not override an event that's already present""" @@ -111,13 +97,6 @@ class TestFTrace(BaseTestThermal): with self.assertRaises(ValueError): trace.add_parsed_event("sched_switch", dfr) - def test_ftrace_accepts_name(self): - """The FTrace() class has members for all classes""" - - trace = trappy.FTrace(name="foo") - - self.assertEquals(trace.name, "foo") - def test_fail_if_no_trace_dat(self): """Raise an IOError with the path if there's no trace.dat and trace.txt""" os.remove("trace.txt") @@ -216,21 +195,6 @@ class TestFTrace(BaseTestThermal): exp_inpower_last = prev_inpower_last - trace.basetime self.assertEquals(round(trace.cpu_in_power.data_frame.index[-1] - exp_inpower_last, 7), 0) - def test_ftrace_normalize_time_accepts_basetime(self): - """FTrace().normalize_time() accepts an arbitrary basetime""" - - trace = trappy.FTrace(normalize_time=False) - - prev_inpower_first = trace.cpu_in_power.data_frame.index[0] - basetime = 3 - - trace.normalize_time(basetime) - - self.assertEquals(trace.basetime, 3) - - exp_inpower_first = prev_inpower_first - 3 - self.assertEquals(round(trace.cpu_in_power.data_frame.index[0] - exp_inpower_first, 7), 0) - def test_ftrace_accepts_events(self): """The FTrace class accepts an events parameter with only the parameters interesting for a trace""" |