1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef CHRE_UTIL_SYSTEM_STATS_CONTAINER_H_ 18 #define CHRE_UTIL_SYSTEM_STATS_CONTAINER_H_ 19 20 #include <type_traits> 21 22 #include "chre/util/macros.h" 23 24 namespace chre { 25 26 /** 27 * A Stats tool used to collect and compute metrics of interests 28 */ 29 30 template <typename T> 31 class StatsContainer { 32 static_assert(std::is_arithmetic<T>::value, 33 "Type must support arithmetic operations"); 34 35 public: 36 /** 37 * @brief Construct a new Stats Container object 38 */ StatsContainer()39 StatsContainer() {} 40 41 /** 42 * Add a new value to the metric collection and update max value 43 * 44 * @param value a T instance 45 */ addValue(T value)46 void addValue(T value) { 47 mMax = MAX(value, mMax); 48 } 49 50 /** 51 * @return the max value 52 */ getMax()53 T getMax() const { 54 return mMax; 55 } 56 57 private: 58 //! Max of stats 59 T mMax = 0; 60 }; 61 62 } // namespace chre 63 64 #endif // CHRE_UTIL_SYSTEM_STATS_CONTAINER_H_ 65