diff options
author | Joel Fernandes <joelaf@google.com> | 2017-05-15 17:50:39 -0700 |
---|---|---|
committer | Joel Fernandes <joelaf@google.com> | 2017-05-15 17:50:39 -0700 |
commit | 232e1a3fdc810f60aedda0e58cd95e47296e0335 (patch) | |
tree | 2b15569a708e12b96f469c316143e55dbdbe9434 /bart/thermal/ThermalAssert.py | |
parent | 9f6e355e4671f4562bf387c16bf9ccb1eddb4437 (diff) | |
parent | 8e32e8eb399356b50b3dc34285843e96fa72496e (diff) | |
download | bart-android-8.1.0_r79.tar.gz |
Merge remote-tracking branch 'goog/mirror-upstream-master' into HEADandroid-wear-8.1.0_r1android-vts-8.1_r9android-vts-8.1_r8android-vts-8.1_r7android-vts-8.1_r6android-vts-8.1_r5android-vts-8.1_r4android-vts-8.1_r3android-vts-8.1_r14android-vts-8.1_r13android-vts-8.1_r12android-vts-8.1_r11android-vts-8.1_r10android-security-8.1.0_r93android-security-8.1.0_r92android-security-8.1.0_r91android-security-8.1.0_r90android-security-8.1.0_r89android-security-8.1.0_r88android-security-8.1.0_r87android-security-8.1.0_r86android-security-8.1.0_r85android-security-8.1.0_r84android-security-8.1.0_r83android-security-8.1.0_r82android-cts-8.1_r9android-cts-8.1_r8android-cts-8.1_r7android-cts-8.1_r6android-cts-8.1_r5android-cts-8.1_r4android-cts-8.1_r3android-cts-8.1_r25android-cts-8.1_r24android-cts-8.1_r23android-cts-8.1_r22android-cts-8.1_r21android-cts-8.1_r20android-cts-8.1_r2android-cts-8.1_r19android-cts-8.1_r18android-cts-8.1_r17android-cts-8.1_r16android-cts-8.1_r15android-cts-8.1_r14android-cts-8.1_r13android-cts-8.1_r12android-cts-8.1_r11android-cts-8.1_r10android-cts-8.1_r1android-8.1.0_r9android-8.1.0_r81android-8.1.0_r80android-8.1.0_r8android-8.1.0_r79android-8.1.0_r78android-8.1.0_r77android-8.1.0_r76android-8.1.0_r75android-8.1.0_r74android-8.1.0_r73android-8.1.0_r72android-8.1.0_r71android-8.1.0_r70android-8.1.0_r7android-8.1.0_r69android-8.1.0_r68android-8.1.0_r67android-8.1.0_r66android-8.1.0_r65android-8.1.0_r64android-8.1.0_r63android-8.1.0_r62android-8.1.0_r61android-8.1.0_r60android-8.1.0_r6android-8.1.0_r53android-8.1.0_r52android-8.1.0_r51android-8.1.0_r50android-8.1.0_r5android-8.1.0_r48android-8.1.0_r47android-8.1.0_r46android-8.1.0_r45android-8.1.0_r43android-8.1.0_r42android-8.1.0_r41android-8.1.0_r40android-8.1.0_r4android-8.1.0_r39android-8.1.0_r38android-8.1.0_r37android-8.1.0_r36android-8.1.0_r35android-8.1.0_r33android-8.1.0_r32android-8.1.0_r31android-8.1.0_r30android-8.1.0_r3android-8.1.0_r29android-8.1.0_r28android-8.1.0_r27android-8.1.0_r26android-8.1.0_r25android-8.1.0_r23android-8.1.0_r22android-8.1.0_r21android-8.1.0_r20android-8.1.0_r2android-8.1.0_r19android-8.1.0_r18android-8.1.0_r17android-8.1.0_r16android-8.1.0_r15android-8.1.0_r14android-8.1.0_r13android-8.1.0_r12android-8.1.0_r11android-8.1.0_r10android-8.1.0_r1android-8.0.0_r34android-8.0.0_r33android-8.0.0_r27android-8.0.0_r26android-8.0.0_r25android-8.0.0_r24android-8.0.0_r23android-8.0.0_r22android-8.0.0_r21security-oc-mr1-releaseoreo-mr1-wear-releaseoreo-mr1-vts-releaseoreo-mr1-security-releaseoreo-mr1-s1-releaseoreo-mr1-releaseoreo-mr1-devoreo-mr1-cuttlefish-testingoreo-mr1-cts-releaseoreo-m8-releaseoreo-m7-releaseoreo-m6-s4-releaseoreo-m6-s3-releaseoreo-m6-s2-releaseoreo-m5-releaseoreo-m4-s9-releaseoreo-m4-s8-releaseoreo-m4-s7-releaseoreo-m4-s6-releaseoreo-m4-s5-releaseoreo-m4-s4-releaseoreo-m4-s3-releaseoreo-m4-s2-releaseoreo-m4-s12-releaseoreo-m4-s11-releaseoreo-m4-s10-releaseoreo-m4-s1-releaseoreo-m3-releaseoreo-m2-s5-releaseoreo-m2-s4-releaseoreo-m2-s3-releaseoreo-m2-s2-releaseoreo-m2-s1-releaseoreo-m2-releaseoreo-dr3-releaseoreo-dr2-releaseoreo-dr1-releaseoreo-dr1-dev
Diffstat (limited to 'bart/thermal/ThermalAssert.py')
-rw-r--r-- | bart/thermal/ThermalAssert.py | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/bart/thermal/ThermalAssert.py b/bart/thermal/ThermalAssert.py new file mode 100644 index 0000000..d0ffa78 --- /dev/null +++ b/bart/thermal/ThermalAssert.py @@ -0,0 +1,135 @@ +# Copyright 2015-2016 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 FTrace object and + provides assertions for thermal behaviours + + :param ftrace: A path to the trace file or a TRAPpy FTrace object + :type ftrace: str, :mod:`trappy.ftrace.FTrace` + """ + + def __init__(self, ftrace, config=None): + + self._ftrace = Utils.init_ftrace(ftrace) + self._analyzer = Analyzer(self._ftrace, config) + + def getThermalResidency(self, temp_range, window, percent=False): + """Return the total time spent in a given temperature range + + :param temp_range: A tuple of (low_temp, high_temp) + which specifies the range of temperature that + one intends to calculate the residency for. + :type temp_range: tuple + + :param window: A (start, end) tuple to limit the scope of the + residency calculation. + :type window: tuple + + :param percent: Returns the residency as a percentage of the total + duration of the trace + :type percent: bool + + .. seealso: + + :mod:`bart.thermal.ThermalAssert.ThermalAssert.assertThermalResidency` + """ + + # 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._ftrace.get_duration() + + return result + + def assertThermalResidency( + self, + expected_value, + operator, + temp_range, + window, + percent=False): + """ + :param expected_value: The expected value of the residency + :type expected_value: double + + :param operator: A binary operator function that returns + a boolean. For example: + :: + + import operator + op = operator.ge + assertThermalResidency(temp_range, expected_value, op) + + Will do the following check: + :: + + getThermalResidency(temp_range) >= expected_value + + A custom function can also be passed: + :: + + THRESHOLD=5 + def between_threshold(a, expected): + return abs(a - expected) <= THRESHOLD + + :param temp_range: A tuple of (low_temp, high_temp) + which specifies the range of temperature that + one intends to calculate the residency for. + :type temp_range: tuple + + :param window: A (start, end) tuple to limit the scope of the + residency calculation. + :type window: tuple + + :param percent: Returns the residency as a percentage of the total + duration of the trace + :type percent: bool + + .. seealso: + + :mod:`bart.thermal.ThermalAssert.ThermalAssert.assertThermalResidency` + """ + + residency = self.getThermalResidency(temp_range, window, percent) + return operator(residency, expected_value) |