blob: 8ecae2f0996d643193cdea3b513922862a56ca7a [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 Merino7f3c8a62014-06-13 11:38:58 +010016
17import unittest
Javi Merino8e8e3212014-06-26 15:24:34 +010018import matplotlib
19import pandas as pd
Javi Merino7f3c8a62014-06-13 11:38:58 +010020
Javi Merino076277d2014-07-02 18:48:18 +010021from test_thermal import BaseTestThermal
Javi Merino435457c2015-08-10 15:59:10 +010022import trappy
Javi Merino7f3c8a62014-06-13 11:38:58 +010023import plot_utils
24
25class TestPlotUtils(unittest.TestCase):
Javi Merino7f3c8a62014-06-13 11:38:58 +010026 def test_normalize_title(self):
27 """Test normalize_title"""
28 self.assertEquals(plot_utils.normalize_title("Foo", ""), "Foo")
29 self.assertEquals(plot_utils.normalize_title("Foo", "Bar"), "Bar - Foo")
Javi Merino3a736552014-06-19 19:22:44 +010030
Javi Merinoa1561272014-06-21 17:49:02 +010031 def test_set_lim(self):
32 """Test set_lim()"""
33
34 class GetSet(object):
35 def __init__(self):
36 self.min = 1
37 self.max = 2
38
39 def get(self):
40 return (self.min, self.max)
41
42 def set(self, minimum, maximum):
43 self.min = minimum
44 self.max = maximum
45
46 gs = GetSet()
47
48 plot_utils.set_lim("default", gs.get, gs.set)
49 self.assertEquals(gs.min, 1)
50 self.assertEquals(gs.max, 2)
51
52 plot_utils.set_lim("range", gs.get, gs.set)
53 self.assertEquals(gs.min, 0.9)
54 self.assertEquals(gs.max, 2.1)
55
56 plot_utils.set_lim((0, 100), gs.get, gs.set)
57 self.assertEquals(gs.min, 0)
58 self.assertEquals(gs.max, 100)
59
60 def test_set_ylim(self):
61 """Test that set_ylim() doesn't bomb"""
62
Javi Merino5981ee82014-08-11 17:45:38 +010063 _, ax = matplotlib.pyplot.subplots()
Javi Merinoa1561272014-06-21 17:49:02 +010064
65 plot_utils.set_ylim(ax, "default")
66 plot_utils.set_ylim(ax, (0, 5))
67
68 def test_set_xlim(self):
69 """Test that set_xlim() doesn't bomb"""
70
Javi Merino5981ee82014-08-11 17:45:38 +010071 _, ax = matplotlib.pyplot.subplots()
Javi Merinoa1561272014-06-21 17:49:02 +010072
73 plot_utils.set_xlim(ax, "default")
74 plot_utils.set_xlim(ax, (0, 5))
75
Javi Merinof9ac5782014-06-21 19:02:50 +010076 def test_pre_plot_setup(self):
77 """Test that plot_utils.pre_plot_setup() doesn't bomb"""
78 plot_utils.pre_plot_setup(None, None)
79 plot_utils.pre_plot_setup(height=9, width=None)
80 plot_utils.pre_plot_setup(height=None, width=9)
81 plot_utils.pre_plot_setup(3, 9)
82
Javi Merino7f88ae32014-08-11 16:53:35 +010083 axis = plot_utils.pre_plot_setup(ncols=2)
84 self.assertEquals(len(axis), 2)
85
Javi Merino270caac2014-08-12 10:41:38 +010086 axis = plot_utils.pre_plot_setup(nrows=2, ncols=3)
87 self.assertEquals(len(axis), 2)
88 self.assertEquals(len(axis[0]), 3)
89 self.assertEquals(len(axis[1]), 3)
90
Javi Merino3a736552014-06-19 19:22:44 +010091 def test_post_plot_setup(self):
92 """Test that post_plot_setup() doesn't bomb"""
93
Javi Merino5981ee82014-08-11 17:45:38 +010094 _, ax = matplotlib.pyplot.subplots()
Javi Merino3a736552014-06-19 19:22:44 +010095
96 plot_utils.post_plot_setup(ax)
97 plot_utils.post_plot_setup(ax, title="Foo")
98 plot_utils.post_plot_setup(ax, ylim=(0, 72))
Javi Merinoa1561272014-06-21 17:49:02 +010099 plot_utils.post_plot_setup(ax, ylim="range")
Javi Merinof9d43af2014-06-21 16:32:04 +0100100 plot_utils.post_plot_setup(ax, xlabel="Bar")
Javi Merinod04643f2014-06-21 17:00:16 +0100101 plot_utils.post_plot_setup(ax, xlim=(0, 100))
Javi Merinoa1561272014-06-21 17:49:02 +0100102 plot_utils.post_plot_setup(ax, xlim="default")
Javi Merino6a5c88d2014-06-19 09:43:18 +0100103
Javi Merinoed977c12014-06-25 17:46:17 +0100104 def test_plot_hist(self):
105 """Test that plost_hist doesn't bomb"""
106 data = pd.Series([1, 1, 2, 4])
107
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100108 _, ax = matplotlib.pyplot.subplots()
Javi Merino23dff5d2015-03-09 19:05:46 +0000109 plot_utils.plot_hist(data, ax, "Foo", "m", 20, "numbers", (0, 4), "default")
Javi Merinoed977c12014-06-25 17:46:17 +0100110
Javi Merino076277d2014-07-02 18:48:18 +0100111class TestPlotUtilsNeedTrace(BaseTestThermal):
Javi Merino6bf48832014-08-11 17:15:35 +0100112 def __init__(self, *args, **kwargs):
113 super(TestPlotUtilsNeedTrace, self).__init__(*args, **kwargs)
Javi Merinod721b272015-04-20 15:37:53 +0100114 self.map_label = {"00000000,00000039": "A53", "00000000,00000006": "A57"}
115 self.actor_order = ["GPU", "A57", "A53"]
Javi Merino6bf48832014-08-11 17:15:35 +0100116
Javi Merino9d9c9b82015-04-29 11:15:11 +0100117 def test_number_freq_plots(self):
118 """Calculate the number of frequency plots correctly"""
119 trace_out = ""
120
Javi Merinoc26a3232015-12-11 18:00:30 +0000121 trace = trappy.FTrace()
122 self.assertEquals(plot_utils.number_freq_plots([trace], self.map_label),
Javi Merino9d9c9b82015-04-29 11:15:11 +0100123 3)
124
125 # Strip out devfreq traces
126 with open("trace.txt") as fin:
127 for line in fin:
128 if ("thermal_power_devfreq_get_power:" not in line) and \
129 ("thermal_power_devfreq_limit:" not in line):
130 trace_out += line
131
132 with open("trace.txt", "w") as fout:
133 fout.write(trace_out)
134
135 # Without devfreq there should only be two plots
Javi Merinoc26a3232015-12-11 18:00:30 +0000136 trace = trappy.FTrace()
137 self.assertEquals(plot_utils.number_freq_plots([trace], self.map_label),
Javi Merino9d9c9b82015-04-29 11:15:11 +0100138 2)
139
Javi Merino2919e8d2014-06-26 15:16:05 +0100140 def test_plot_temperature(self):
141 """Test that plot_utils.plot_temperature() doesn't bomb"""
142
Javi Merinoc26a3232015-12-11 18:00:30 +0000143 trace1 = trappy.FTrace(name="first")
144 trace2 = trappy.FTrace(name="second")
145 traces = [trace1, trace2]
Javi Merino2919e8d2014-06-26 15:16:05 +0100146
Javi Merinoc26a3232015-12-11 18:00:30 +0000147 plot_utils.plot_temperature(traces, ylim="default")
Javi Merino8e8e3212014-06-26 15:24:34 +0100148 matplotlib.pyplot.close('all')
Javi Merino6bf48832014-08-11 17:15:35 +0100149
150 def test_plot_load(self):
151 """Test that plot_utils.plot_load() doesn't bomb"""
152
Javi Merinoc26a3232015-12-11 18:00:30 +0000153 trace1 = trappy.FTrace(name="first")
154 trace2 = trappy.FTrace(name="second")
155 traces = [trace1, trace2]
Javi Merino6bf48832014-08-11 17:15:35 +0100156
Javi Merinoc26a3232015-12-11 18:00:30 +0000157 plot_utils.plot_load(traces, self.map_label, height=5)
Javi Merino6bf48832014-08-11 17:15:35 +0100158 matplotlib.pyplot.close('all')
Javi Merinoaf05f312014-08-11 17:47:59 +0100159
Javi Merinoc26a3232015-12-11 18:00:30 +0000160 def test_plot_load_single_trace(self):
161 """plot_utils.plot_load() can be used with a single trace"""
162 trace = trappy.FTrace()
Javi Merinoaf05f312014-08-11 17:47:59 +0100163
Javi Merinoc26a3232015-12-11 18:00:30 +0000164 plot_utils.plot_load([trace], self.map_label)
Javi Merinoaf05f312014-08-11 17:47:59 +0100165 matplotlib.pyplot.close('all')
Javi Merino0c484262014-08-12 11:55:04 +0100166
167 def test_plot_allfreqs(self):
168 """Test that plot_utils.plot_allfreqs() doesn't bomb"""
169
Javi Merinoc26a3232015-12-11 18:00:30 +0000170 trace1 = trappy.FTrace(name="first")
171 trace2 = trappy.FTrace(name="second")
172 traces = [trace1, trace2]
Javi Merino0c484262014-08-12 11:55:04 +0100173
Javi Merinoc26a3232015-12-11 18:00:30 +0000174 plot_utils.plot_allfreqs(traces, self.map_label, width=20)
Javi Merino0c484262014-08-12 11:55:04 +0100175 matplotlib.pyplot.close('all')
176
Javi Merinoc26a3232015-12-11 18:00:30 +0000177 def test_plot_allfreqs_single_trace(self):
178 """plot_utils.plot_allfreqs() can be used with a single trace"""
179 trace = trappy.FTrace()
Javi Merino114c9cb2014-08-12 14:47:09 +0100180
Javi Merinoc26a3232015-12-11 18:00:30 +0000181 plot_utils.plot_allfreqs([trace], self.map_label)
Javi Merino0c484262014-08-12 11:55:04 +0100182 matplotlib.pyplot.close('all')
Javi Merino38fd12d2014-08-12 15:02:47 +0100183
Javi Merino94d89c12016-01-05 14:47:07 +0000184 def test_plot_allfreqs_one_actor(self):
185 """plot_utils.plot_allfreqs work when there is only one actor"""
186
187 in_data = """ kworker/4:1-397 [004] 720.741349: thermal_power_cpu_get: cpus=00000000,00000006 freq=1400000 raw_cpu_power=189 load={23, 12} power=14
Javi Merino373c30f2016-03-08 13:59:25 +0000188 kworker/4:1-397 [004] 720.741679: thermal_power_cpu_limit: cpus=00000000,00000006 freq=1400000 cdev_state=1 power=14"""
Javi Merino94d89c12016-01-05 14:47:07 +0000189
190 with open("trace.txt", "w") as fout:
191 fout.write(in_data)
192
193 traces = [trappy.FTrace(name="first"), trappy.FTrace(name="second")]
194 map_label = {"00000000,00000006": "A57"}
195
196 plot_utils.plot_allfreqs(traces, map_label)
197 matplotlib.pyplot.close("all")
198
Javi Merino38fd12d2014-08-12 15:02:47 +0100199 def test_plot_controller(self):
200 """plot_utils.plot_controller() doesn't bomb"""
201
Javi Merinoc26a3232015-12-11 18:00:30 +0000202 trace1 = trappy.FTrace(name="first")
203 trace2 = trappy.FTrace(name="second")
204 traces = [trace1, trace2]
Javi Merino38fd12d2014-08-12 15:02:47 +0100205
Javi Merinoc26a3232015-12-11 18:00:30 +0000206 plot_utils.plot_controller(traces, height=5)
Javi Merino38fd12d2014-08-12 15:02:47 +0100207 matplotlib.pyplot.close('all')
Javi Merinof5cd04b2014-08-12 15:26:22 +0100208
209 def test_plot_input_power(self):
210 """plot_utils.plot_input_power() doesn't bomb"""
211
Javi Merinoc26a3232015-12-11 18:00:30 +0000212 trace1 = trappy.FTrace(name="first")
213 trace2 = trappy.FTrace(name="second")
214 traces = [trace1, trace2]
Javi Merinof5cd04b2014-08-12 15:26:22 +0100215
Javi Merinoc26a3232015-12-11 18:00:30 +0000216 plot_utils.plot_input_power(traces, self.actor_order, width=20)
Javi Merinof5cd04b2014-08-12 15:26:22 +0100217 matplotlib.pyplot.close('all')
Javi Merino9fde2152014-08-12 15:34:24 +0100218
219 def test_plot_output_power(self):
220 """plot_utils.plot_output_power() doesn't bomb"""
221
Javi Merinoc26a3232015-12-11 18:00:30 +0000222 trace1 = trappy.FTrace(name="first")
223 trace2 = trappy.FTrace(name="second")
224 traces = [trace1, trace2]
Javi Merino9fde2152014-08-12 15:34:24 +0100225
Javi Merinoc26a3232015-12-11 18:00:30 +0000226 plot_utils.plot_output_power(traces, self.actor_order, width=20)
Javi Merino9fde2152014-08-12 15:34:24 +0100227 matplotlib.pyplot.close('all')
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100228
229 def test_plot_freq_hists(self):
230 """plot_utils.plot_freq_hists() doesn't bomb"""
231
Javi Merinoc26a3232015-12-11 18:00:30 +0000232 trace1 = trappy.FTrace(name="first")
233 trace2 = trappy.FTrace(name="second")
234 traces = [trace1, trace2]
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100235
Javi Merinoc26a3232015-12-11 18:00:30 +0000236 plot_utils.plot_freq_hists(traces, self.map_label)
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100237 matplotlib.pyplot.close('all')
238
Javi Merinoc26a3232015-12-11 18:00:30 +0000239 def test_plot_freq_hists_single_trace(self):
240 """plot_utils.plot_freq_hists() works with a single trace"""
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100241
Javi Merinoc26a3232015-12-11 18:00:30 +0000242 trace = trappy.FTrace()
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100243
Javi Merinoc26a3232015-12-11 18:00:30 +0000244 plot_utils.plot_freq_hists([trace], self.map_label)
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100245 matplotlib.pyplot.close('all')
246
247 def test_plot_temperature_hist(self):
248 """plot_utils.plot_temperature_hist() doesn't bomb"""
249
Javi Merinoc26a3232015-12-11 18:00:30 +0000250 trace1 = trappy.FTrace(name="first")
251 trace2 = trappy.FTrace(name="second")
252 traces = [trace1, trace2]
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100253
Javi Merinoc26a3232015-12-11 18:00:30 +0000254 plot_utils.plot_temperature_hist(traces)
Javi Merinoe5ea60a2014-08-12 16:41:42 +0100255 matplotlib.pyplot.close('all')