| Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright 2018 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 | #pragma once | 
|  | 18 |  | 
|  | 19 | #include <cinttypes> | 
|  | 20 | #include <numeric> | 
|  | 21 | #include <vector> | 
|  | 22 |  | 
|  | 23 | namespace android { | 
|  | 24 | namespace scheduler { | 
|  | 25 | // This number is used to set the size of the arrays in scheduler that hold information | 
|  | 26 | // about layers. | 
|  | 27 | static constexpr size_t ARRAY_SIZE = 30; | 
|  | 28 |  | 
| Ana Krulec | b43429d | 2019-01-09 14:28:51 -0800 | [diff] [blame] | 29 | // This number is used to have a place holder for when the screen is not NORMAL/ON. Currently | 
|  | 30 | // the config is not visible to SF, and is completely maintained by HWC. However, we would | 
|  | 31 | // still like to keep track of time when the device is in this config. | 
|  | 32 | static constexpr int SCREEN_OFF_CONFIG_ID = -1; | 
|  | 33 |  | 
| Ana Krulec | 434c22d | 2018-11-28 13:48:36 +0100 | [diff] [blame] | 34 | // Calculates the statistical mean (average) in the data structure (array, vector). The | 
|  | 35 | // function does not modify the contents of the array. | 
|  | 36 | template <typename T> | 
|  | 37 | auto calculate_mean(const T& v) { | 
|  | 38 | using V = typename T::value_type; | 
|  | 39 | V sum = std::accumulate(v.begin(), v.end(), 0); | 
|  | 40 | return sum / static_cast<V>(v.size()); | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | // Calculates the statistical median in the vector. Return 0 if the vector is empty. The | 
|  | 44 | // function modifies the vector contents. | 
|  | 45 | int64_t calculate_median(std::vector<int64_t>* v); | 
|  | 46 |  | 
|  | 47 | // Calculates the statistical mode in the vector. Return 0 if the vector is empty. | 
|  | 48 | int64_t calculate_mode(const std::vector<int64_t>& v); | 
|  | 49 |  | 
|  | 50 | } // namespace scheduler | 
|  | 51 | } // namespace android |