• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#    Copyright 2015-2017 ARM Limited
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16import pandas as pd
17import trappy
18import unittest
19
20class TestBareTrace(unittest.TestCase):
21    def __init__(self, *args, **kwargs):
22        super(TestBareTrace, self).__init__(*args, **kwargs)
23        dfr0 = pd.DataFrame({"l1_misses": [24, 535,  41],
24                             "l2_misses": [155, 11, 200],
25                             "cpu":       [ 0,   1,   0]},
26                            index=pd.Series([1.020, 1.342, 1.451], name="Time"))
27
28        dfr1 = pd.DataFrame({"load": [ 35,  16,  21,  28],
29                             "util": [279, 831, 554, 843]},
30                            index=pd.Series([1.279, 1.718, 2.243, 2.465], name="Time"))
31
32        self.dfr = [dfr0, dfr1]
33
34    def test_bare_trace_accepts_name(self):
35        """The BareTrace() accepts a name parameter"""
36
37        trace = trappy.BareTrace(name="foo")
38
39        self.assertEquals(trace.name, "foo")
40
41    def test_bare_trace_can_add_parsed_event(self):
42        """The BareTrace() class can add parsed events to its collection of trace events"""
43        trace = trappy.BareTrace()
44        trace.add_parsed_event("pmu_counters", self.dfr[0])
45
46        self.assertEquals(len(trace.pmu_counters.data_frame), 3)
47        self.assertEquals(trace.pmu_counters.data_frame["l1_misses"].iloc[0], 24)
48
49        trace.add_parsed_event("pivoted_counters", self.dfr[0], pivot="cpu")
50        self.assertEquals(trace.pivoted_counters.pivot, "cpu")
51
52    def test_bare_trace_get_duration(self):
53        """BareTrace.get_duration() works for a simple case"""
54
55        trace = trappy.BareTrace()
56        trace.add_parsed_event("pmu_counter", self.dfr[0])
57        trace.add_parsed_event("load_event", self.dfr[1])
58
59        self.assertEquals(trace.get_duration(), self.dfr[1].index[-1])
60
61    def test_bare_trace_get_duration_normalized(self):
62        """BareTrace.get_duration() works if the trace has been normalized"""
63
64        trace = trappy.BareTrace()
65        trace.add_parsed_event("pmu_counter", self.dfr[0].copy())
66        trace.add_parsed_event("load_event", self.dfr[1].copy())
67
68        basetime = self.dfr[0].index[0]
69        trace._normalize_time(basetime)
70
71        expected_duration = self.dfr[1].index[-1] - basetime
72        self.assertEquals(trace.get_duration(), expected_duration)
73
74    def test_bare_trace_normalize_time_accepts_basetime(self):
75        """BareTrace().normalize_time() accepts an arbitrary basetime"""
76
77        trace = trappy.BareTrace()
78        trace.add_parsed_event("pmu_counter", self.dfr[0].copy())
79
80        prev_first_time = trace.pmu_counter.data_frame.index[0]
81        basetime = 3
82
83        trace._normalize_time(basetime)
84
85        self.assertEquals(trace.basetime, basetime)
86
87        exp_first_time = prev_first_time - basetime
88        self.assertEquals(round(trace.pmu_counter.data_frame.index[0] - exp_first_time, 7), 0)
89