Home | History | Annotate | Download | only in tests
      1 #    Copyright 2016-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 
     16 import utils_tests
     17 
     18 import trappy
     19 
     20 import numpy as np
     21 
     22 class TestSystrace(utils_tests.SetupDirectory):
     23 
     24     def __init__(self, *args, **kwargs):
     25         super(TestSystrace, self).__init__(
     26              [("trace_systrace.html", "trace.html"),
     27              ("trace_surfaceflinger.html", "trace_sf.html")],
     28              *args,
     29              **kwargs)
     30 
     31     def test_systrace_html(self):
     32         """Tests parsing of a systrace embedded textual trace """
     33 
     34         events = ["sched_switch", "sched_wakeup", "trace_event_clock_sync"]
     35         trace = trappy.SysTrace("trace.html", events=events)
     36 
     37         self.assertTrue(hasattr(trace, "sched_switch"))
     38         self.assertEquals(len(trace.sched_switch.data_frame), 4)
     39         self.assertTrue("prev_comm" in trace.sched_switch.data_frame.columns)
     40 
     41         self.assertTrue(hasattr(trace, "sched_wakeup"))
     42         self.assertEquals(len(trace.sched_wakeup.data_frame), 4)
     43         self.assertTrue("target_cpu" in trace.sched_wakeup.data_frame.columns)
     44 
     45         self.assertTrue(hasattr(trace, "trace_event_clock_sync"))
     46         self.assertEquals(len(trace.trace_event_clock_sync.data_frame), 1)
     47         self.assertTrue("realtime_ts" in trace.trace_event_clock_sync.data_frame.columns)
     48 
     49     def test_cpu_counting(self):
     50         """SysTrace traces know the number of cpus"""
     51 
     52         trace = trappy.SysTrace("trace.html")
     53 
     54         self.assertTrue(hasattr(trace, "_cpus"))
     55         self.assertEquals(trace._cpus, 3)
     56 
     57     def test_systrace_userspace(self):
     58         """Test parsing of userspace events"""
     59 
     60         # Test a 'B' event (begin)
     61         trace = trappy.SysTrace("trace_sf.html")
     62         dfr = trace.tracing_mark_write.data_frame
     63         self.assertEquals(dfr['__pid'].iloc[2], 7591)
     64         self.assertEquals(dfr['__comm'].iloc[2], 'RenderThread')
     65         self.assertEquals(dfr['pid'].iloc[2], 7459)
     66         self.assertEquals(dfr['event'].iloc[2], 'B')
     67         self.assertEquals(dfr['func'].iloc[2], 'notifyFramePending')
     68         self.assertEquals(dfr['data'].iloc[2], None)
     69 
     70         # Test a 'C' event (count)
     71         self.assertEquals(dfr['__pid'].iloc[-2], 612)
     72         self.assertEquals(dfr['__comm'].iloc[-2], 'HwBinder:594_1')
     73         self.assertEquals(dfr['pid'].iloc[-2], 594)
     74         self.assertEquals(dfr['func'].iloc[-2], 'HW_VSYNC_0')
     75         self.assertEquals(dfr['event'].iloc[-2], 'C')
     76         self.assertEquals(dfr['data'].iloc[-2], '0')
     77 
     78         # Test an 'E' event (end)
     79         edfr = dfr[dfr['event'] == 'E']
     80         self.assertEquals(edfr['__pid'].iloc[0], 7591)
     81         self.assertEquals(edfr['__comm'].iloc[0], 'RenderThread')
     82         self.assertTrue(np.isnan(edfr['pid'].iloc[0]))
     83         self.assertEquals(edfr['func'].iloc[0], None)
     84         self.assertEquals(edfr['event'].iloc[0], 'E')
     85         self.assertEquals(edfr['data'].iloc[0], None)
     86 
     87     def test_systrace_line_num(self):
     88         """Test for line numbers in a systrace"""
     89         trace = trappy.SysTrace("trace_sf.html")
     90         dfr = trace.sched_switch.data_frame
     91         self.assertEquals(trace.lines, 2506)
     92         self.assertEquals(dfr['__line'].iloc[0], 0)
     93         self.assertEquals(dfr['__line'].iloc[1], 6)
     94         self.assertEquals(dfr['__line'].iloc[-1], 2505)
     95 
     96 class TestLegacySystrace(utils_tests.SetupDirectory):
     97 
     98     def __init__(self, *args, **kwargs):
     99         super(TestLegacySystrace, self).__init__(
    100              [("trace_legacy_systrace.html", "trace.html")],
    101              *args,
    102              **kwargs)
    103 
    104     def test_systrace_html(self):
    105         """Tests parsing of a legacy systrace embedded textual trace """
    106 
    107         events = ["sched_switch", "sched_wakeup", "sched_contrib_scale_f"]
    108         trace = trappy.SysTrace("trace.html", events=events)
    109 
    110         self.assertTrue(hasattr(trace, "sched_switch"))
    111         self.assertEquals(len(trace.sched_switch.data_frame), 3)
    112         self.assertTrue("prev_comm" in trace.sched_switch.data_frame.columns)
    113 
    114         self.assertTrue(hasattr(trace, "sched_wakeup"))
    115         self.assertEquals(len(trace.sched_wakeup.data_frame), 2)
    116         self.assertTrue("target_cpu" in trace.sched_wakeup.data_frame.columns)
    117 
    118         self.assertTrue(hasattr(trace, "sched_contrib_scale_f"))
    119         self.assertEquals(len(trace.sched_contrib_scale_f.data_frame), 2)
    120         self.assertTrue("freq_scale_factor" in trace.sched_contrib_scale_f.data_frame.columns)
    121 
    122     def test_cpu_counting(self):
    123         """In a legacy SysTrace trace, trappy gets the number of cpus"""
    124 
    125         trace = trappy.SysTrace("trace.html")
    126 
    127         self.assertTrue(hasattr(trace, "_cpus"))
    128         self.assertEquals(trace._cpus, 8)
    129