blob: 3ab311467be64d09cd28eeb41e46976d32cfcba5 [file] [log] [blame]
Brendan Jackmane81fdcb2017-01-04 17:10:29 +00001# Copyright 2015-2017 ARM Limited
Javi Merino034e7cc2015-04-22 18:39:21 +01002#
Javi Merinoaace7c02015-08-10 14:10:47 +01003# 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
Javi Merinoe4c1d452014-04-01 17:00:47 +010016
Javi Merino86f3bb92014-08-11 17:07:35 +010017import matplotlib
Javi Merinofff33672014-06-18 16:56:34 +010018import pandas as pd
19
Javi Merino076277d2014-07-02 18:48:18 +010020from test_thermal import BaseTestThermal
Javi Merino435457c2015-08-10 15:59:10 +010021import trappy
Javi Merino2cfd1e82015-04-21 17:22:28 +010022import cpu_power
Javi Merinoe4c1d452014-04-01 17:00:47 +010023
Javi Merino2cfd1e82015-04-21 17:22:28 +010024class TestCpuPower(BaseTestThermal):
Javi Merino34f9da12014-06-19 15:48:16 +010025 def __init__(self, *args, **kwargs):
Javi Merino2cfd1e82015-04-21 17:22:28 +010026 super(TestCpuPower, self).__init__(*args, **kwargs)
Javi Merinod721b272015-04-20 15:37:53 +010027 self.map_label = {"00000000,00000039": "A53", "00000000,00000006": "A57"}
Javi Merino34f9da12014-06-19 15:48:16 +010028
Javi Merinofff33672014-06-18 16:56:34 +010029 def test_pivot_with_labels(self):
30 """Test pivot_with_labels()"""
Javi Merinoc68e3792014-07-02 18:14:33 +010031 map_label = {"000000f0": "A15", "0000000f": "A7"}
Javi Merinofff33672014-06-18 16:56:34 +010032 dfr_in = pd.DataFrame({'cpus': ["000000f0", "0000000f", "000000f0", "0000000f"],
33 'freq': [1, 3, 2, 6]})
Javi Merinofff33672014-06-18 16:56:34 +010034
Javi Merino2cfd1e82015-04-21 17:22:28 +010035 dfr_out = cpu_power.pivot_with_labels(dfr_in, "freq", "cpus", map_label)
Javi Merinofff33672014-06-18 16:56:34 +010036
37 self.assertEquals(dfr_out["A15"].iloc[0], 1)
38 self.assertEquals(dfr_out["A15"].iloc[1], 1)
39 self.assertEquals(dfr_out["A15"].iloc[2], 2)
40 self.assertEquals(dfr_out["A7"].iloc[1], 3)
41
Javi Merino221d44a2015-06-17 17:53:34 +010042 def test_num_cpus_in_mask(self):
43 """num_cpus_in_mask() works with the masks we usually use"""
44 mask = "000000f0"
45 self.assertEquals(cpu_power.num_cpus_in_mask(mask), 4)
46
47 mask = sorted(self.map_label)[0]
48 self.assertEquals(cpu_power.num_cpus_in_mask(mask), 2)
49
50 mask = sorted(self.map_label)[1]
51 self.assertEquals(cpu_power.num_cpus_in_mask(mask), 4)
52
Javi Merino2cfd1e82015-04-21 17:22:28 +010053 def test_cpuoutpower_dataframe(self):
54 """Test that CpuOutPower() creates a proper data_frame"""
Javi Merinoc26a3232015-12-11 18:00:30 +000055 outp = trappy.FTrace().cpu_out_power
Javi Merinoe4c1d452014-04-01 17:00:47 +010056
Javi Merinod721b272015-04-20 15:37:53 +010057 self.assertEquals(outp.data_frame["power"].iloc[0], 1344)
Javi Merino92f4d012014-08-08 17:55:32 +010058 self.assertTrue("cdev_state" in outp.data_frame.columns)
Javi Merino62c56dc2014-05-07 17:41:12 +010059
Javi Merino2cfd1e82015-04-21 17:22:28 +010060 def test_cpuoutpower_get_all_freqs(self):
61 """Test CpuOutPower.get_all_freqs()"""
Javi Merinoc26a3232015-12-11 18:00:30 +000062 dfr = trappy.FTrace().cpu_out_power.get_all_freqs(self.map_label)
Javi Merino73234c12014-06-18 17:27:16 +010063
Javi Merinod721b272015-04-20 15:37:53 +010064 self.assertEquals(dfr["A57"].iloc[0], 1100)
65 self.assertEquals(dfr["A53"].iloc[1], 850)
Javi Merino73234c12014-06-18 17:27:16 +010066
Javi Merino2cfd1e82015-04-21 17:22:28 +010067 def test_cpuinpower_get_dataframe(self):
68 """Test that CpuInPower() creates a proper data_frame()"""
Javi Merinoc26a3232015-12-11 18:00:30 +000069 inp = trappy.FTrace().cpu_in_power
Javi Merino62c56dc2014-05-07 17:41:12 +010070
Javi Merino92f4d012014-08-08 17:55:32 +010071 self.assertTrue("load0" in inp.data_frame.columns)
Javi Merinod721b272015-04-20 15:37:53 +010072 self.assertEquals(inp.data_frame["load0"].iloc[0], 24)
Javi Merino8a79fb32014-05-07 17:56:23 +010073
Javi Merino2cfd1e82015-04-21 17:22:28 +010074 def test_cpuinpower_big_cpumask(self):
75 """CpuInPower()'s data_frame is not confused by 64-bit cpumasks"""
Javi Merino66492492015-01-12 15:43:43 +000076 in_data = """ kworker/2:2-679 [002] 676.256284: thermal_power_cpu_get: cpus=00000000,0000000f freq=261888 cdev_state=5 power=12
77 kworker/2:2-679 [002] 676.276200: thermal_power_cpu_get: cpus=00000000,00000030 freq=261888 cdev_state=5 power=0
78 kworker/2:2-679 [002] 676.416202: thermal_power_cpu_get: cpus=00000000,0000000f freq=261888 cdev_state=5 power=0
Javi Merino35c1ac72014-07-04 10:29:04 +010079 """
80 with open("trace.txt", "w") as fout:
81 fout.write(in_data)
82
Javi Merinoc26a3232015-12-11 18:00:30 +000083 inp = trappy.FTrace(normalize_time=False).cpu_in_power
Javi Merino92f4d012014-08-08 17:55:32 +010084 self.assertEquals(round(inp.data_frame.index[0], 6), 676.256284)
Javi Merinod6284da2014-08-14 12:12:13 +010085 self.assertEquals(inp.data_frame["cpus"].iloc[1], "00000000,00000030")
Javi Merino35c1ac72014-07-04 10:29:04 +010086
Javi Merino2cfd1e82015-04-21 17:22:28 +010087 def test_cpuinpower_data_frame_asymmetric_clusters(self):
88 """Test that CpuInPower()'s data_frame can handle asymmetric clusters
Javi Merino9ce2fb62014-07-04 20:02:13 +010089
90 That is 2 cpus in one cluster and 4 in another, like Juno
91 """
Javi Merino978ebfb2015-02-17 15:30:38 +000092 in_data = """
93 kworker/2:2-679 [002] 676.256261: thermal_power_cpu_get: cpus=00000000,00000030 freq=1900000 raw_cpu_power=1259 load={74 49} power=451
94 kworker/2:2-679 [002] 676.256271: thermal_power_cpu_get: cpus=00000000,0000000f freq=450000 raw_cpu_power=36 load={1 2 1 3} power=9
Javi Merino9ce2fb62014-07-04 20:02:13 +010095"""
96
97 with open("trace.txt", "w") as fout:
98 fout.write(in_data)
99
Javi Merinoc26a3232015-12-11 18:00:30 +0000100 inp = trappy.FTrace(normalize_time=False).cpu_in_power
Javi Merino9ce2fb62014-07-04 20:02:13 +0100101
Javi Merino978ebfb2015-02-17 15:30:38 +0000102 self.assertEquals(inp.data_frame["load0"].iloc[0], 74)
103 self.assertEquals(inp.data_frame["load1"].iloc[0], 49)
104 self.assertEquals(inp.data_frame["load2"].iloc[0], 0)
105 self.assertEquals(inp.data_frame["load3"].iloc[0], 0)
106 self.assertEquals(inp.data_frame["load0"].iloc[1], 1)
107 self.assertEquals(inp.data_frame["load1"].iloc[1], 2)
108 self.assertEquals(inp.data_frame["load2"].iloc[1], 1)
109 self.assertEquals(inp.data_frame["load3"].iloc[1], 3)
Javi Merino35c1ac72014-07-04 10:29:04 +0100110
Javi Merino2cfd1e82015-04-21 17:22:28 +0100111 def test_cpuinpower_get_all_freqs(self):
112 """Test CpuInPower.get_all_freqs()"""
Javi Merinoc26a3232015-12-11 18:00:30 +0000113 dfr = trappy.FTrace().cpu_in_power.get_all_freqs(self.map_label)
Javi Merino73234c12014-06-18 17:27:16 +0100114
Javi Merinod721b272015-04-20 15:37:53 +0100115 self.assertEquals(dfr["A57"].iloc[0], 1100)
116 self.assertEquals(dfr["A53"].iloc[1], 850)
117 self.assertEquals(dfr["A57"].iloc[5], 1100)
Javi Merino73234c12014-06-18 17:27:16 +0100118
Javi Merino2cfd1e82015-04-21 17:22:28 +0100119 def test_cpuinpower_get_load_data(self):
120 """Test CpuInPower.get_load_data()"""
Javi Merinoc26a3232015-12-11 18:00:30 +0000121 trace = trappy.FTrace()
122 first_load = trace.cpu_in_power.data_frame["load0"].iloc[0]
123 load_data = trace.cpu_in_power.get_load_data(self.map_label)
Javi Merino9237a3c2014-06-18 12:18:51 +0100124
Javi Merinod721b272015-04-20 15:37:53 +0100125 self.assertEquals(load_data["A57"].iloc[0], 24 + 19)
126 self.assertEquals(load_data["A53"].iloc[3], 32 + 28 + 46 + 44)
127 self.assertEquals(load_data["A57"].iloc[0], load_data["A57"].iloc[1])
Javi Merino7ad9ce02015-06-16 16:34:10 +0100128
Javi Merinoc26a3232015-12-11 18:00:30 +0000129 self.assertEquals(trace.cpu_in_power.data_frame["load0"].iloc[0],
Javi Merino7ad9ce02015-06-16 16:34:10 +0100130 first_load)
Javi Merino86abee12015-06-16 17:22:06 +0100131
132 def test_cpuinpower_get_normalized_load_data(self):
133 """Test CpuInPower.get_normalized_load_data()"""
Javi Merinoc26a3232015-12-11 18:00:30 +0000134 trace = trappy.FTrace()
135 first_load = trace.cpu_in_power.data_frame["load0"].iloc[0]
136 load_data = trace.cpu_in_power.get_normalized_load_data(self.map_label)
Javi Merino86abee12015-06-16 17:22:06 +0100137
138 # Ideally the trace should have an event in which the cpus are
139 # not running at maximum frequency
140 self.assertEquals(load_data["A57"].iloc[0],
141 (24. + 19) * 1100000 / (1100000 * 2))
142 self.assertEquals(load_data["A53"].iloc[1],
143 (36. + 49 + 48 + 7) * 850000 / (850000 * 4))
Javi Merinoc26a3232015-12-11 18:00:30 +0000144 self.assertEquals(trace.cpu_in_power.data_frame["load0"].iloc[0],
Javi Merino86abee12015-06-16 17:22:06 +0100145 first_load)