blob: bd862669011ac986ee5ce7ef220fa1c19abd32b5 [file] [log] [blame]
Atif Niyaz83846822019-07-18 15:17:40 -07001/*
2 * Copyright (C) 2019 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 _UI_INPUT_STATISTICS_H
18#define _UI_INPUT_STATISTICS_H
19
20#include <android-base/chrono_utils.h>
21
22#include <stddef.h>
23
24namespace android {
25
26class LatencyStatistics {
27private:
28 /* Minimum sample recorded */
29 float mMin;
30 /* Maximum sample recorded */
31 float mMax;
32 /* Sum of all samples recorded */
33 float mSum;
34 /* Sum of all the squares of samples recorded */
35 float mSum2;
36 /* Count of all samples recorded */
37 size_t mCount;
38 /* The last time statistics were reported */
39 std::chrono::steady_clock::time_point mLastReportTime;
40 /* Statistics Report Frequency */
41 const std::chrono::seconds mReportPeriod;
42
43public:
44 LatencyStatistics(std::chrono::seconds period);
45
46 void addValue(float);
47 void reset();
48 bool shouldReport();
49
50 float getMean();
51 float getMin();
52 float getMax();
53 float getStDev();
54 size_t getCount();
55};
56
57} // namespace android
58
59#endif // _UI_INPUT_STATISTICS_H