Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [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 | |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 19 | #include <cstdint> |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame^] | 20 | #include <deque> |
| 21 | #include <mutex> |
| 22 | #include <optional> |
| 23 | #include <unordered_map> |
| 24 | #include <variant> |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 25 | |
Adithya Srinivasan | f427f76 | 2021-06-15 19:46:26 +0000 | [diff] [blame] | 26 | #include <android/hardware/graphics/composer/2.4/IComposerClient.h> |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 27 | #include <gui/JankInfo.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 28 | #include <timestatsproto/TimeStatsHelper.h> |
| 29 | #include <timestatsproto/TimeStatsProtoHeader.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 30 | #include <ui/FenceTime.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 31 | #include <utils/String16.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 32 | #include <utils/Vector.h> |
| 33 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame^] | 34 | #include <scheduler/Fps.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 35 | |
| 36 | using namespace android::surfaceflinger; |
| 37 | |
| 38 | namespace android { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 39 | |
| 40 | class TimeStats { |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 41 | public: |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 42 | using SetFrameRateVote = TimeStatsHelper::SetFrameRateVote; |
| 43 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 44 | virtual ~TimeStats() = default; |
| 45 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 46 | // Process a pull request from statsd. |
| 47 | virtual bool onPullAtom(const int atomId, std::string* pulledData); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 48 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 49 | virtual void parseArgs(bool asProto, const Vector<String16>& args, std::string& result) = 0; |
| 50 | virtual bool isEnabled() = 0; |
Oliver Nguyen | f3b7c9c | 2019-05-07 13:28:07 -0700 | [diff] [blame] | 51 | virtual std::string miniDump() = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 52 | |
| 53 | virtual void incrementTotalFrames() = 0; |
| 54 | virtual void incrementMissedFrames() = 0; |
| 55 | virtual void incrementClientCompositionFrames() = 0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 56 | virtual void incrementClientCompositionReusedFrames() = 0; |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 57 | // Increments the number of times the display refresh rate changed. |
| 58 | virtual void incrementRefreshRateSwitches() = 0; |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 59 | // Increments the number of changes in composition strategy |
| 60 | // The intention is to reflect the number of changes between hwc and gpu |
| 61 | // composition, where "gpu composition" may also include mixed composition. |
| 62 | virtual void incrementCompositionStrategyChanges() = 0; |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 63 | // Records the most up-to-date count of display event connections. |
| 64 | // The stored count will be the maximum ever recoded. |
| 65 | virtual void recordDisplayEventConnectionCount(int32_t count) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 66 | |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 67 | // Records the start and end times for a frame. |
| 68 | // The start time is the same as the beginning of a SurfaceFlinger |
| 69 | // invalidate message. |
| 70 | // The end time corresponds to when SurfaceFlinger finishes submitting the |
| 71 | // request to HWC to present a frame. |
| 72 | virtual void recordFrameDuration(nsecs_t startTime, nsecs_t endTime) = 0; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 73 | // Records the start time and end times for when RenderEngine begins work. |
| 74 | // The start time corresponds to the beginning of RenderEngine::drawLayers. |
| 75 | // The end time corresponds to when RenderEngine finishes rendering. |
| 76 | virtual void recordRenderEngineDuration(nsecs_t startTime, nsecs_t endTime) = 0; |
| 77 | // Same as above, but passes in a fence representing the end time. |
| 78 | virtual void recordRenderEngineDuration(nsecs_t startTime, |
| 79 | const std::shared_ptr<FenceTime>& readyFence) = 0; |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 80 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 81 | virtual void setPostTime(int32_t layerId, uint64_t frameNumber, const std::string& layerName, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 82 | uid_t uid, nsecs_t postTime, int32_t gameMode) = 0; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 83 | virtual void setLatchTime(int32_t layerId, uint64_t frameNumber, nsecs_t latchTime) = 0; |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 84 | // Reasons why latching a particular buffer may be skipped |
| 85 | enum class LatchSkipReason { |
| 86 | // If the acquire fence did not fire on some devices we skip latching |
| 87 | // the buffer until the fence fires. |
| 88 | LateAcquire, |
| 89 | }; |
| 90 | // Increments the counter of skipped latch buffers. |
| 91 | virtual void incrementLatchSkipped(int32_t layerId, LatchSkipReason reason) = 0; |
| 92 | // Increments the counter of bad desired present times for this layer. |
| 93 | // Bad desired present times are "implausible" and cause SurfaceFlinger to |
| 94 | // latch a buffer immediately to avoid stalling. |
| 95 | virtual void incrementBadDesiredPresent(int32_t layerId) = 0; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 96 | virtual void setDesiredTime(int32_t layerId, uint64_t frameNumber, nsecs_t desiredTime) = 0; |
| 97 | virtual void setAcquireTime(int32_t layerId, uint64_t frameNumber, nsecs_t acquireTime) = 0; |
| 98 | virtual void setAcquireFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 99 | const std::shared_ptr<FenceTime>& acquireFence) = 0; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 100 | // SetPresent{Time, Fence} are not expected to be called in the critical |
| 101 | // rendering path, as they flush prior fences if those fences have fired. |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 102 | virtual void setPresentTime(int32_t layerId, uint64_t frameNumber, nsecs_t presentTime, |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 103 | Fps displayRefreshRate, std::optional<Fps> renderRate, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 104 | SetFrameRateVote frameRateVote, int32_t gameMode) = 0; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 105 | virtual void setPresentFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 106 | const std::shared_ptr<FenceTime>& presentFence, |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 107 | Fps displayRefreshRate, std::optional<Fps> renderRate, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 108 | SetFrameRateVote frameRateVote, int32_t gameMode) = 0; |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 109 | |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 110 | // Increments janky frames, blamed to the provided {refreshRate, renderRate, uid, layerName} |
| 111 | // key, with JankMetadata as supplementary reasons for the jank. Because FrameTimeline is the |
| 112 | // infrastructure responsible for computing jank in the system, this is expected to be called |
| 113 | // from FrameTimeline, rather than directly from SurfaceFlinger or individual layers. If there |
| 114 | // are no jank reasons, then total frames are incremented but jank is not, for accurate |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 115 | // accounting of janky frames. |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 116 | // displayDeadlineDelta, displayPresentJitter, and appDeadlineDelta are also provided in order |
| 117 | // to provide contextual information about a janky frame. These values may only be uploaded if |
| 118 | // there was an associated valid jank reason, and they must be positive. When these frame counts |
| 119 | // are incremented, these are also aggregated into a global reporting packet to help with data |
| 120 | // validation and assessing of overall device health. |
| 121 | struct JankyFramesInfo { |
| 122 | Fps refreshRate; |
| 123 | std::optional<Fps> renderRate; |
| 124 | uid_t uid = 0; |
| 125 | std::string layerName; |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 126 | int32_t gameMode = 0; |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 127 | int32_t reasons = 0; |
| 128 | nsecs_t displayDeadlineDelta = 0; |
| 129 | nsecs_t displayPresentJitter = 0; |
| 130 | nsecs_t appDeadlineDelta = 0; |
| 131 | |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 132 | static bool isOptApproxEqual(std::optional<Fps> lhs, std::optional<Fps> rhs) { |
| 133 | return (!lhs && !rhs) || (lhs && rhs && isApproxEqual(*lhs, *rhs)); |
| 134 | } |
| 135 | |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 136 | bool operator==(const JankyFramesInfo& o) const { |
Dominik Laskowski | 6eab42d | 2021-09-13 14:34:13 -0700 | [diff] [blame] | 137 | return isApproxEqual(refreshRate, o.refreshRate) && |
| 138 | isOptApproxEqual(renderRate, o.renderRate) && uid == o.uid && |
| 139 | layerName == o.layerName && gameMode == o.gameMode && reasons == o.reasons && |
| 140 | displayDeadlineDelta == o.displayDeadlineDelta && |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 141 | displayPresentJitter == o.displayPresentJitter && |
| 142 | appDeadlineDelta == o.appDeadlineDelta; |
| 143 | } |
| 144 | |
| 145 | friend std::ostream& operator<<(std::ostream& os, const JankyFramesInfo& info) { |
| 146 | os << "JankyFramesInfo {"; |
| 147 | os << "\n .refreshRate = " << info.refreshRate; |
| 148 | os << "\n .renderRate = " |
| 149 | << (info.renderRate ? to_string(*info.renderRate) : "nullopt"); |
| 150 | os << "\n .uid = " << info.uid; |
| 151 | os << "\n .layerName = " << info.layerName; |
| 152 | os << "\n .reasons = " << info.reasons; |
| 153 | os << "\n .displayDeadlineDelta = " << info.displayDeadlineDelta; |
| 154 | os << "\n .displayPresentJitter = " << info.displayPresentJitter; |
| 155 | os << "\n .appDeadlineDelta = " << info.appDeadlineDelta; |
| 156 | return os << "\n}"; |
| 157 | } |
| 158 | }; |
| 159 | |
| 160 | virtual void incrementJankyFrames(const JankyFramesInfo& info) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 161 | // Clean up the layer record |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 162 | virtual void onDestroy(int32_t layerId) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 163 | // If SF skips or rejects a buffer, remove the corresponding TimeRecord. |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 164 | virtual void removeTimeRecord(int32_t layerId, uint64_t frameNumber) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 165 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 166 | virtual void setPowerMode( |
| 167 | hardware::graphics::composer::V2_4::IComposerClient::PowerMode powerMode) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 168 | // Source of truth is RefrehRateStats. |
| 169 | virtual void recordRefreshRate(uint32_t fps, nsecs_t duration) = 0; |
| 170 | virtual void setPresentFenceGlobal(const std::shared_ptr<FenceTime>& presentFence) = 0; |
| 171 | }; |
| 172 | |
| 173 | namespace impl { |
| 174 | |
| 175 | class TimeStats : public android::TimeStats { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 176 | using PowerMode = android::hardware::graphics::composer::V2_4::IComposerClient::PowerMode; |
| 177 | |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 178 | struct FrameTime { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 179 | uint64_t frameNumber = 0; |
| 180 | nsecs_t postTime = 0; |
| 181 | nsecs_t latchTime = 0; |
| 182 | nsecs_t acquireTime = 0; |
| 183 | nsecs_t desiredTime = 0; |
| 184 | nsecs_t presentTime = 0; |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | struct TimeRecord { |
| 188 | bool ready = false; |
| 189 | FrameTime frameTime; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 190 | std::shared_ptr<FenceTime> acquireFence; |
| 191 | std::shared_ptr<FenceTime> presentFence; |
| 192 | }; |
| 193 | |
| 194 | struct LayerRecord { |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 195 | uid_t uid; |
Yiwei Zhang | 9689e2f | 2018-05-11 12:33:23 -0700 | [diff] [blame] | 196 | std::string layerName; |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 197 | int32_t gameMode = 0; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 198 | // This is the index in timeRecords, at which the timestamps for that |
| 199 | // specific frame are still not fully received. This is not waiting for |
| 200 | // fences to signal, but rather waiting to receive those fences/timestamps. |
| 201 | int32_t waitData = -1; |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 202 | uint32_t droppedFrames = 0; |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 203 | uint32_t lateAcquireFrames = 0; |
| 204 | uint32_t badDesiredPresentFrames = 0; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 205 | TimeRecord prevTimeRecord; |
Yiwei Zhang | c5f2c45 | 2018-05-08 16:31:56 -0700 | [diff] [blame] | 206 | std::deque<TimeRecord> timeRecords; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 207 | }; |
| 208 | |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 209 | struct PowerTime { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 210 | PowerMode powerMode = PowerMode::OFF; |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 211 | nsecs_t prevTime = 0; |
| 212 | }; |
| 213 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 214 | struct RenderEngineDuration { |
| 215 | nsecs_t startTime; |
| 216 | std::variant<nsecs_t, std::shared_ptr<FenceTime>> endTime; |
| 217 | }; |
| 218 | |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 219 | struct GlobalRecord { |
| 220 | nsecs_t prevPresentTime = 0; |
| 221 | std::deque<std::shared_ptr<FenceTime>> presentFences; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 222 | std::deque<RenderEngineDuration> renderEngineDurations; |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 223 | }; |
| 224 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 225 | public: |
Alec Mouri | b3885ad | 2019-09-06 17:08:55 -0700 | [diff] [blame] | 226 | TimeStats(); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 227 | // For testing only for injecting custom dependencies. |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 228 | TimeStats(std::optional<size_t> maxPulledLayers, |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 229 | std::optional<size_t> maxPulledHistogramBuckets); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 230 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 231 | bool onPullAtom(const int atomId, std::string* pulledData) override; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 232 | void parseArgs(bool asProto, const Vector<String16>& args, std::string& result) override; |
| 233 | bool isEnabled() override; |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 234 | std::string miniDump() override; |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 235 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 236 | void incrementTotalFrames() override; |
| 237 | void incrementMissedFrames() override; |
| 238 | void incrementClientCompositionFrames() override; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 239 | void incrementClientCompositionReusedFrames() override; |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 240 | void incrementRefreshRateSwitches() override; |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 241 | void incrementCompositionStrategyChanges() override; |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 242 | void recordDisplayEventConnectionCount(int32_t count) override; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 243 | |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 244 | void recordFrameDuration(nsecs_t startTime, nsecs_t endTime) override; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 245 | void recordRenderEngineDuration(nsecs_t startTime, nsecs_t endTime) override; |
| 246 | void recordRenderEngineDuration(nsecs_t startTime, |
| 247 | const std::shared_ptr<FenceTime>& readyFence) override; |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 248 | |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 249 | void setPostTime(int32_t layerId, uint64_t frameNumber, const std::string& layerName, uid_t uid, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 250 | nsecs_t postTime, int32_t gameMode) override; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 251 | void setLatchTime(int32_t layerId, uint64_t frameNumber, nsecs_t latchTime) override; |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 252 | void incrementLatchSkipped(int32_t layerId, LatchSkipReason reason) override; |
| 253 | void incrementBadDesiredPresent(int32_t layerId) override; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 254 | void setDesiredTime(int32_t layerId, uint64_t frameNumber, nsecs_t desiredTime) override; |
| 255 | void setAcquireTime(int32_t layerId, uint64_t frameNumber, nsecs_t acquireTime) override; |
| 256 | void setAcquireFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 257 | const std::shared_ptr<FenceTime>& acquireFence) override; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 258 | void setPresentTime(int32_t layerId, uint64_t frameNumber, nsecs_t presentTime, |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 259 | Fps displayRefreshRate, std::optional<Fps> renderRate, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 260 | SetFrameRateVote frameRateVote, int32_t gameMode) override; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 261 | void setPresentFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 262 | const std::shared_ptr<FenceTime>& presentFence, Fps displayRefreshRate, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 263 | std::optional<Fps> renderRate, SetFrameRateVote frameRateVote, |
| 264 | int32_t gameMode) override; |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 265 | |
| 266 | void incrementJankyFrames(const JankyFramesInfo& info) override; |
Yiwei Zhang | af8ee94 | 2018-11-22 00:15:23 -0800 | [diff] [blame] | 267 | // Clean up the layer record |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 268 | void onDestroy(int32_t layerId) override; |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 269 | // If SF skips or rejects a buffer, remove the corresponding TimeRecord. |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 270 | void removeTimeRecord(int32_t layerId, uint64_t frameNumber) override; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 271 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 272 | void setPowerMode( |
| 273 | hardware::graphics::composer::V2_4::IComposerClient::PowerMode powerMode) override; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 274 | // Source of truth is RefrehRateStats. |
| 275 | void recordRefreshRate(uint32_t fps, nsecs_t duration) override; |
| 276 | void setPresentFenceGlobal(const std::shared_ptr<FenceTime>& presentFence) override; |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 277 | |
Yiwei Zhang | af8ee94 | 2018-11-22 00:15:23 -0800 | [diff] [blame] | 278 | static const size_t MAX_NUM_TIME_RECORDS = 64; |
| 279 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 280 | private: |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame] | 281 | bool populateGlobalAtom(std::string* pulledData); |
| 282 | bool populateLayerAtom(std::string* pulledData); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 283 | bool recordReadyLocked(int32_t layerId, TimeRecord* timeRecord); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 284 | void flushAvailableRecordsToStatsLocked(int32_t layerId, Fps displayRefreshRate, |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 285 | std::optional<Fps> renderRate, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 286 | SetFrameRateVote frameRateVote, int32_t gameMode); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 287 | void flushPowerTimeLocked(); |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 288 | void flushAvailableGlobalRecordsToStatsLocked(); |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 289 | bool canAddNewAggregatedStats(uid_t uid, const std::string& layerName, int32_t gameMode); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 290 | |
| 291 | void enable(); |
| 292 | void disable(); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 293 | void clearAll(); |
| 294 | void clearGlobalLocked(); |
| 295 | void clearLayersLocked(); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 296 | void dump(bool asProto, std::optional<uint32_t> maxLayers, std::string& result); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 297 | |
| 298 | std::atomic<bool> mEnabled = false; |
| 299 | std::mutex mMutex; |
Yiwei Zhang | dc22404 | 2018-10-18 15:34:00 -0700 | [diff] [blame] | 300 | TimeStatsHelper::TimeStatsGlobal mTimeStats; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 301 | // Hashmap for LayerRecord with layerId as the hash key |
Yiwei Zhang | 9689e2f | 2018-05-11 12:33:23 -0700 | [diff] [blame] | 302 | std::unordered_map<int32_t, LayerRecord> mTimeStatsTracker; |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 303 | PowerTime mPowerTime; |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 304 | GlobalRecord mGlobalRecord; |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 305 | |
| 306 | static const size_t MAX_NUM_LAYER_RECORDS = 200; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 307 | |
| 308 | static const size_t REFRESH_RATE_BUCKET_WIDTH = 30; |
| 309 | static const size_t RENDER_RATE_BUCKET_WIDTH = REFRESH_RATE_BUCKET_WIDTH; |
Yiwei Zhang | e926ab5 | 2019-08-14 15:16:00 -0700 | [diff] [blame] | 310 | static const size_t MAX_NUM_LAYER_STATS = 200; |
Alec Mouri | 52bf780 | 2021-01-20 08:20:50 -0800 | [diff] [blame] | 311 | static const size_t MAX_NUM_PULLED_LAYERS = MAX_NUM_LAYER_STATS; |
Alec Mouri | 52bf780 | 2021-01-20 08:20:50 -0800 | [diff] [blame] | 312 | size_t mMaxPulledLayers = MAX_NUM_PULLED_LAYERS; |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 313 | size_t mMaxPulledHistogramBuckets = 6; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 316 | } // namespace impl |
| 317 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 318 | } // namespace android |