• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 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 <aidl/android/hardware/power/WorkDuration.h>
20 
21 #include <deque>
22 #include <optional>
23 #include <vector>
24 
25 namespace aidl {
26 namespace google {
27 namespace hardware {
28 namespace power {
29 namespace impl {
30 namespace pixel {
31 
32 using aidl::android::hardware::power::WorkDuration;
33 
34 class SessionRecords {
35   public:
36     struct CycleRecord {
37         int32_t startIntervalUs{0};
38         int32_t totalDurationUs{0};
39         bool isMissedCycle{false};
40     };
41 
42   public:
43     SessionRecords(const int32_t maxNumOfRecords, const double jankCheckTimeFactor);
44     ~SessionRecords() = default;
45 
46     void addReportedDurations(const std::vector<WorkDuration> &actualDurationsNs,
47                               int64_t targetDurationNs);
48     std::optional<int32_t> getMaxDuration();
49     std::optional<int32_t> getAvgDuration();
50     int32_t getNumOfRecords();
51     int32_t getNumOfMissedCycles();
52     bool isLowFrameRate(int32_t fpsLowRateThreshold);
53 
54   private:
55     const int32_t kMaxNumOfRecords;
56     const double kJankCheckTimeFactor;
57     std::vector<CycleRecord> mRecords;
58     // A descending order queue to store the records' indexes.
59     // It is for detecting the maximum duration.
60     std::deque<int32_t> mRecordsIndQueue;
61     int32_t mAvgDurationUs{0};
62     int64_t mLastStartTimeNs{0};
63     int32_t mLatestRecordIndex{-1};
64     int32_t mNumOfMissedCycles{0};
65     int32_t mNumOfFrames{0};
66     int64_t mSumOfDurationsUs{0};
67 };
68 
69 }  // namespace pixel
70 }  // namespace impl
71 }  // namespace power
72 }  // namespace hardware
73 }  // namespace google
74 }  // namespace aidl
75