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 16import os 17import sys 18import unittest 19 20import pandas as pd 21from pandas.util.testing import assert_series_equal 22 23import utils_tests 24import trappy 25 26@unittest.skipUnless(utils_tests.trace_cmd_installed(), 27 "trace-cmd not installed") 28class TestCpuIdle(utils_tests.SetupDirectory): 29 def __init__(self, *args, **kwargs): 30 super(TestCpuIdle, self).__init__( 31 [("trace_idle.dat", "trace.dat")], 32 *args, 33 **kwargs) 34 35 def test_get_dataframe(self): 36 """Test that CpuIdle creates a proper data_frame""" 37 38 df = trappy.FTrace(normalize_time=False).cpu_idle.data_frame 39 40 exp_index = pd.Float64Index([ 41 162534.215764, 42 162534.216001, 43 162534.216552, 44 162534.216568, 45 162534.217401, 46 162534.217521, 47 162534.217655, 48 162534.219077, 49 162534.219252, 50 162534.219268, 51 162534.219329, 52 162534.219336, 53 162534.219587, 54 162534.219763, 55 162534.219853, 56 162534.220947, 57 162534.220947 58 ], name="Time") 59 60 exp_states = pd.Series([ 61 2, -1, 2, -1, -1, -1, 2, -1, 2, -1, 0, 0, 2, -1, 2, -1, -1 62 ], index=exp_index, name="state") 63 exp_cpus = pd.Series([ 64 5, 2, 2, 1, 3, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 3, 1 65 ], index=exp_index, name="cpu_id") 66 67 assert_series_equal(df["state"], exp_states, check_exact=True) 68 assert_series_equal(df["cpu_id"], exp_cpus, check_exact=True) 69