diff options
author | Kapileshwar Singh <kapileshwar.singh@arm.com> | 2015-08-20 19:26:08 -0700 |
---|---|---|
committer | Kapileshwar Singh <kapileshwar.singh@arm.com> | 2015-08-21 09:48:07 -0700 |
commit | 51c415b181172e7b4e6654f3a107e0d4793f1df4 (patch) | |
tree | 60942c1fafceecc08fdf671ced1a4352bf464471 /bart/thermal/ThermalAssert.py | |
parent | c5a7c3661de1399be2d3f8e6895643dfa03eba78 (diff) | |
download | bart-51c415b181172e7b4e6654f3a107e0d4793f1df4.tar.gz |
thermal: Introduce ThermalAssert
Introducing thermal specific assertions with
assertThermalResidency
Signed-off-by: Kapileshwar Singh <kapileshwar.singh@arm.com>
Diffstat (limited to 'bart/thermal/ThermalAssert.py')
-rw-r--r-- | bart/thermal/ThermalAssert.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/bart/thermal/ThermalAssert.py b/bart/thermal/ThermalAssert.py new file mode 100644 index 0000000..684405c --- /dev/null +++ b/bart/thermal/ThermalAssert.py @@ -0,0 +1,94 @@ +# Copyright 2015-2015 ARM Limited +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""A thermal specific library to assert certain thermal +behaviours +""" + +from bart.common import Utils +from bart.common.Analyzer import Analyzer +import numpy as np + + +# pylint: disable=invalid-name +# pylint: disable=too-many-arguments +class ThermalAssert(object): + + """A class that accepts a TRAPpy Run object and + provides assertions for thermal behaviours""" + + def __init__(self, run, config=None): + + self._run = Utils.init_run(run) + self._analyzer = Analyzer(self._run, config) + + def getThermalResidency(self, temp_range, window, percent=False): + """Returns the total time spent in a given temperature range + Args: + temp_range (tuple): A tuple of (low_temp, high_temp) + which the specifies the range of temperature that + one intends to calculate the residency for. + window (tuple): A (start, end) tuple to limit the scope of the + residency calculation. + percent: Returns the residency as a percentage of the total + duration of the trace + """ + + # Get a pivoted thermal temperature data using the grammar + data = self._analyzer.getStatement("trappy.thermal.Thermal:temp") + + result = {} + for pivot, data_frame in data.groupby(axis=1, level=0): + + series = data_frame[pivot] + series = Utils.select_window(series, window) + mask = (series >= temp_range[0]) & (series <= temp_range[1]) + index = series.index.values + # pylint fails to recognize numpy members. + # pylint: disable=no-member + shift_index = np.roll(index, 1) + # pylint: enable=no-member + shift_index[0] = 0 + + result[pivot] = sum((index - shift_index)[mask.values]) + + if percent: + result[pivot] = ( + result[pivot] * 100.0) / self._run.get_duration() + + return result + + def assertThermalResidency( + self, + expected_value, + operator, + temp_range, + window, + percent=False): + """ + Args: + expected_value (double): The expected value of the residency + operator (function): A binary operator function that returns + a boolean + temp_range (tuple): A tuple of (low_temp, high_temp) + which the specifies the range of temperature that + one intends to calculate the residency for. + window (tuple): A (start, end) tuple to limit the scope of the + residency calculation. + percent: Returns the residency as a percentage of the total + duration of the trace + """ + + residency = self.getThermalResidency(temp_range, window, percent) + return operator(residency, expected_value) |