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 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame^] | 19 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 20 | #pragma clang diagnostic push |
| 21 | #pragma clang diagnostic ignored "-Wconversion" |
| 22 | |
| 23 | #include <android/hardware/graphics/composer/2.4/IComposerClient.h> |
| 24 | |
| 25 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 26 | #pragma clang diagnostic pop // ignored "-Wconversion" |
| 27 | |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 28 | #include <stats_event.h> |
| 29 | #include <stats_pull_atom_callback.h> |
| 30 | #include <statslog.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 31 | #include <timestatsproto/TimeStatsHelper.h> |
| 32 | #include <timestatsproto/TimeStatsProtoHeader.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 33 | #include <ui/FenceTime.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 34 | #include <utils/String16.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 35 | #include <utils/Vector.h> |
| 36 | |
Yiwei Zhang | c5f2c45 | 2018-05-08 16:31:56 -0700 | [diff] [blame] | 37 | #include <deque> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 38 | #include <mutex> |
Yiwei Zhang | 8a4015c | 2018-05-08 16:03:47 -0700 | [diff] [blame] | 39 | #include <optional> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 40 | #include <unordered_map> |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 41 | #include <variant> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 42 | |
| 43 | using namespace android::surfaceflinger; |
| 44 | |
| 45 | namespace android { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 46 | |
| 47 | class TimeStats { |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 48 | public: |
| 49 | virtual ~TimeStats() = default; |
| 50 | |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 51 | // Called once boot has been finished to perform additional capabilities, |
| 52 | // e.g. registration to statsd. |
| 53 | virtual void onBootFinished() = 0; |
| 54 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 55 | virtual void parseArgs(bool asProto, const Vector<String16>& args, std::string& result) = 0; |
| 56 | virtual bool isEnabled() = 0; |
Oliver Nguyen | f3b7c9c | 2019-05-07 13:28:07 -0700 | [diff] [blame] | 57 | virtual std::string miniDump() = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 58 | |
| 59 | virtual void incrementTotalFrames() = 0; |
| 60 | virtual void incrementMissedFrames() = 0; |
| 61 | virtual void incrementClientCompositionFrames() = 0; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 62 | virtual void incrementClientCompositionReusedFrames() = 0; |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 63 | // Increments the number of times the display refresh rate changed. |
| 64 | virtual void incrementRefreshRateSwitches() = 0; |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 65 | // Increments the number of changes in composition strategy |
| 66 | // The intention is to reflect the number of changes between hwc and gpu |
| 67 | // composition, where "gpu composition" may also include mixed composition. |
| 68 | virtual void incrementCompositionStrategyChanges() = 0; |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 69 | // Records the most up-to-date count of display event connections. |
| 70 | // The stored count will be the maximum ever recoded. |
| 71 | virtual void recordDisplayEventConnectionCount(int32_t count) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 72 | |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 73 | // Records the start and end times for a frame. |
| 74 | // The start time is the same as the beginning of a SurfaceFlinger |
| 75 | // invalidate message. |
| 76 | // The end time corresponds to when SurfaceFlinger finishes submitting the |
| 77 | // request to HWC to present a frame. |
| 78 | virtual void recordFrameDuration(nsecs_t startTime, nsecs_t endTime) = 0; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 79 | // Records the start time and end times for when RenderEngine begins work. |
| 80 | // The start time corresponds to the beginning of RenderEngine::drawLayers. |
| 81 | // The end time corresponds to when RenderEngine finishes rendering. |
| 82 | virtual void recordRenderEngineDuration(nsecs_t startTime, nsecs_t endTime) = 0; |
| 83 | // Same as above, but passes in a fence representing the end time. |
| 84 | virtual void recordRenderEngineDuration(nsecs_t startTime, |
| 85 | const std::shared_ptr<FenceTime>& readyFence) = 0; |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 86 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 87 | virtual void setPostTime(int32_t layerId, uint64_t frameNumber, const std::string& layerName, |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 88 | nsecs_t postTime) = 0; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 89 | 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] | 90 | // Reasons why latching a particular buffer may be skipped |
| 91 | enum class LatchSkipReason { |
| 92 | // If the acquire fence did not fire on some devices we skip latching |
| 93 | // the buffer until the fence fires. |
| 94 | LateAcquire, |
| 95 | }; |
| 96 | // Increments the counter of skipped latch buffers. |
| 97 | virtual void incrementLatchSkipped(int32_t layerId, LatchSkipReason reason) = 0; |
| 98 | // Increments the counter of bad desired present times for this layer. |
| 99 | // Bad desired present times are "implausible" and cause SurfaceFlinger to |
| 100 | // latch a buffer immediately to avoid stalling. |
| 101 | virtual void incrementBadDesiredPresent(int32_t layerId) = 0; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 102 | virtual void setDesiredTime(int32_t layerId, uint64_t frameNumber, nsecs_t desiredTime) = 0; |
| 103 | virtual void setAcquireTime(int32_t layerId, uint64_t frameNumber, nsecs_t acquireTime) = 0; |
| 104 | virtual void setAcquireFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 105 | const std::shared_ptr<FenceTime>& acquireFence) = 0; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 106 | // SetPresent{Time, Fence} are not expected to be called in the critical |
| 107 | // rendering path, as they flush prior fences if those fences have fired. |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 108 | virtual void setPresentTime(int32_t layerId, uint64_t frameNumber, nsecs_t presentTime) = 0; |
| 109 | virtual void setPresentFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 110 | const std::shared_ptr<FenceTime>& presentFence) = 0; |
| 111 | // Clean up the layer record |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 112 | virtual void onDestroy(int32_t layerId) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 113 | // If SF skips or rejects a buffer, remove the corresponding TimeRecord. |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 114 | virtual void removeTimeRecord(int32_t layerId, uint64_t frameNumber) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 115 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame^] | 116 | virtual void setPowerMode( |
| 117 | hardware::graphics::composer::V2_4::IComposerClient::PowerMode powerMode) = 0; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 118 | // Source of truth is RefrehRateStats. |
| 119 | virtual void recordRefreshRate(uint32_t fps, nsecs_t duration) = 0; |
| 120 | virtual void setPresentFenceGlobal(const std::shared_ptr<FenceTime>& presentFence) = 0; |
| 121 | }; |
| 122 | |
| 123 | namespace impl { |
| 124 | |
| 125 | class TimeStats : public android::TimeStats { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame^] | 126 | using PowerMode = android::hardware::graphics::composer::V2_4::IComposerClient::PowerMode; |
| 127 | |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 128 | struct FrameTime { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 129 | uint64_t frameNumber = 0; |
| 130 | nsecs_t postTime = 0; |
| 131 | nsecs_t latchTime = 0; |
| 132 | nsecs_t acquireTime = 0; |
| 133 | nsecs_t desiredTime = 0; |
| 134 | nsecs_t presentTime = 0; |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | struct TimeRecord { |
| 138 | bool ready = false; |
| 139 | FrameTime frameTime; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 140 | std::shared_ptr<FenceTime> acquireFence; |
| 141 | std::shared_ptr<FenceTime> presentFence; |
| 142 | }; |
| 143 | |
| 144 | struct LayerRecord { |
Yiwei Zhang | 9689e2f | 2018-05-11 12:33:23 -0700 | [diff] [blame] | 145 | std::string layerName; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 146 | // This is the index in timeRecords, at which the timestamps for that |
| 147 | // specific frame are still not fully received. This is not waiting for |
| 148 | // fences to signal, but rather waiting to receive those fences/timestamps. |
| 149 | int32_t waitData = -1; |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 150 | uint32_t droppedFrames = 0; |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 151 | uint32_t lateAcquireFrames = 0; |
| 152 | uint32_t badDesiredPresentFrames = 0; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 153 | TimeRecord prevTimeRecord; |
Yiwei Zhang | c5f2c45 | 2018-05-08 16:31:56 -0700 | [diff] [blame] | 154 | std::deque<TimeRecord> timeRecords; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 157 | struct PowerTime { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame^] | 158 | PowerMode powerMode = PowerMode::OFF; |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 159 | nsecs_t prevTime = 0; |
| 160 | }; |
| 161 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 162 | struct RenderEngineDuration { |
| 163 | nsecs_t startTime; |
| 164 | std::variant<nsecs_t, std::shared_ptr<FenceTime>> endTime; |
| 165 | }; |
| 166 | |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 167 | struct GlobalRecord { |
| 168 | nsecs_t prevPresentTime = 0; |
| 169 | std::deque<std::shared_ptr<FenceTime>> presentFences; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 170 | std::deque<RenderEngineDuration> renderEngineDurations; |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 173 | public: |
Alec Mouri | b3885ad | 2019-09-06 17:08:55 -0700 | [diff] [blame] | 174 | TimeStats(); |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 175 | |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 176 | // Delegate to the statsd service and associated APIs. |
| 177 | // Production code may use this class directly, whereas unit test may define |
| 178 | // a subclass for ease of testing. |
| 179 | class StatsEventDelegate { |
| 180 | public: |
| 181 | virtual ~StatsEventDelegate() = default; |
Tej Singh | 2a457b6 | 2020-01-31 16:16:10 -0800 | [diff] [blame] | 182 | virtual AStatsEvent* addStatsEventToPullData(AStatsEventList* data) { |
| 183 | return AStatsEventList_addStatsEvent(data); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 184 | } |
Tej Singh | 38a4b21 | 2020-03-13 19:04:51 -0700 | [diff] [blame] | 185 | virtual void setStatsPullAtomCallback(int32_t atom_tag, |
| 186 | AStatsManager_PullAtomMetadata* metadata, |
| 187 | AStatsManager_PullAtomCallback callback, |
| 188 | void* cookie) { |
| 189 | return AStatsManager_setPullAtomCallback(atom_tag, metadata, callback, cookie); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Tej Singh | 38a4b21 | 2020-03-13 19:04:51 -0700 | [diff] [blame] | 192 | virtual void clearStatsPullAtomCallback(int32_t atom_tag) { |
| 193 | return AStatsManager_clearPullAtomCallback(atom_tag); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Tej Singh | 2a457b6 | 2020-01-31 16:16:10 -0800 | [diff] [blame] | 196 | virtual void statsEventSetAtomId(AStatsEvent* event, uint32_t atom_id) { |
| 197 | return AStatsEvent_setAtomId(event, atom_id); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 200 | virtual void statsEventWriteInt32(AStatsEvent* event, int32_t field) { |
| 201 | return AStatsEvent_writeInt32(event, field); |
| 202 | } |
| 203 | |
Tej Singh | 2a457b6 | 2020-01-31 16:16:10 -0800 | [diff] [blame] | 204 | virtual void statsEventWriteInt64(AStatsEvent* event, int64_t field) { |
| 205 | return AStatsEvent_writeInt64(event, field); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Tej Singh | 2a457b6 | 2020-01-31 16:16:10 -0800 | [diff] [blame] | 208 | virtual void statsEventWriteString8(AStatsEvent* event, const char* field) { |
| 209 | return AStatsEvent_writeString(event, field); |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Tej Singh | 2a457b6 | 2020-01-31 16:16:10 -0800 | [diff] [blame] | 212 | virtual void statsEventWriteByteArray(AStatsEvent* event, const uint8_t* buf, |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 213 | size_t numBytes) { |
Tej Singh | 2a457b6 | 2020-01-31 16:16:10 -0800 | [diff] [blame] | 214 | return AStatsEvent_writeByteArray(event, buf, numBytes); |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Tej Singh | 2a457b6 | 2020-01-31 16:16:10 -0800 | [diff] [blame] | 217 | virtual void statsEventBuild(AStatsEvent* event) { return AStatsEvent_build(event); } |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 218 | }; |
| 219 | // For testing only for injecting custom dependencies. |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 220 | TimeStats(std::unique_ptr<StatsEventDelegate> statsDelegate, |
| 221 | std::optional<size_t> maxPulledLayers, |
| 222 | std::optional<size_t> maxPulledHistogramBuckets); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 223 | |
Alec Mouri | 3ecd5cd | 2020-01-29 12:53:07 -0800 | [diff] [blame] | 224 | ~TimeStats() override; |
| 225 | |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 226 | void onBootFinished() override; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 227 | void parseArgs(bool asProto, const Vector<String16>& args, std::string& result) override; |
| 228 | bool isEnabled() override; |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 229 | std::string miniDump() override; |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 230 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 231 | void incrementTotalFrames() override; |
| 232 | void incrementMissedFrames() override; |
| 233 | void incrementClientCompositionFrames() override; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 234 | void incrementClientCompositionReusedFrames() override; |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 235 | void incrementRefreshRateSwitches() override; |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 236 | void incrementCompositionStrategyChanges() override; |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 237 | void recordDisplayEventConnectionCount(int32_t count) override; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 238 | |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 239 | void recordFrameDuration(nsecs_t startTime, nsecs_t endTime) override; |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 240 | void recordRenderEngineDuration(nsecs_t startTime, nsecs_t endTime) override; |
| 241 | void recordRenderEngineDuration(nsecs_t startTime, |
| 242 | const std::shared_ptr<FenceTime>& readyFence) override; |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 243 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 244 | void setPostTime(int32_t layerId, uint64_t frameNumber, const std::string& layerName, |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 245 | nsecs_t postTime) override; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 246 | void setLatchTime(int32_t layerId, uint64_t frameNumber, nsecs_t latchTime) override; |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 247 | void incrementLatchSkipped(int32_t layerId, LatchSkipReason reason) override; |
| 248 | void incrementBadDesiredPresent(int32_t layerId) override; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 249 | void setDesiredTime(int32_t layerId, uint64_t frameNumber, nsecs_t desiredTime) override; |
| 250 | void setAcquireTime(int32_t layerId, uint64_t frameNumber, nsecs_t acquireTime) override; |
| 251 | void setAcquireFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 252 | const std::shared_ptr<FenceTime>& acquireFence) override; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 253 | void setPresentTime(int32_t layerId, uint64_t frameNumber, nsecs_t presentTime) override; |
| 254 | void setPresentFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 255 | const std::shared_ptr<FenceTime>& presentFence) override; |
Yiwei Zhang | af8ee94 | 2018-11-22 00:15:23 -0800 | [diff] [blame] | 256 | // Clean up the layer record |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 257 | void onDestroy(int32_t layerId) override; |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 258 | // If SF skips or rejects a buffer, remove the corresponding TimeRecord. |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 259 | void removeTimeRecord(int32_t layerId, uint64_t frameNumber) override; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 260 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame^] | 261 | void setPowerMode( |
| 262 | hardware::graphics::composer::V2_4::IComposerClient::PowerMode powerMode) override; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 263 | // Source of truth is RefrehRateStats. |
| 264 | void recordRefreshRate(uint32_t fps, nsecs_t duration) override; |
| 265 | void setPresentFenceGlobal(const std::shared_ptr<FenceTime>& presentFence) override; |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 266 | |
Yiwei Zhang | af8ee94 | 2018-11-22 00:15:23 -0800 | [diff] [blame] | 267 | static const size_t MAX_NUM_TIME_RECORDS = 64; |
| 268 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 269 | private: |
Tej Singh | 2a457b6 | 2020-01-31 16:16:10 -0800 | [diff] [blame] | 270 | static AStatsManager_PullAtomCallbackReturn pullAtomCallback(int32_t atom_tag, |
| 271 | AStatsEventList* data, |
| 272 | void* cookie); |
| 273 | AStatsManager_PullAtomCallbackReturn populateGlobalAtom(AStatsEventList* data); |
| 274 | AStatsManager_PullAtomCallbackReturn populateLayerAtom(AStatsEventList* data); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 275 | bool recordReadyLocked(int32_t layerId, TimeRecord* timeRecord); |
| 276 | void flushAvailableRecordsToStatsLocked(int32_t layerId); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 277 | void flushPowerTimeLocked(); |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 278 | void flushAvailableGlobalRecordsToStatsLocked(); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 279 | |
| 280 | void enable(); |
| 281 | void disable(); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 282 | void clearAll(); |
| 283 | void clearGlobalLocked(); |
| 284 | void clearLayersLocked(); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 285 | void dump(bool asProto, std::optional<uint32_t> maxLayers, std::string& result); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 286 | |
| 287 | std::atomic<bool> mEnabled = false; |
| 288 | std::mutex mMutex; |
Yiwei Zhang | dc22404 | 2018-10-18 15:34:00 -0700 | [diff] [blame] | 289 | TimeStatsHelper::TimeStatsGlobal mTimeStats; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 290 | // Hashmap for LayerRecord with layerId as the hash key |
Yiwei Zhang | 9689e2f | 2018-05-11 12:33:23 -0700 | [diff] [blame] | 291 | std::unordered_map<int32_t, LayerRecord> mTimeStatsTracker; |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 292 | PowerTime mPowerTime; |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 293 | GlobalRecord mGlobalRecord; |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 294 | |
| 295 | static const size_t MAX_NUM_LAYER_RECORDS = 200; |
Yiwei Zhang | e926ab5 | 2019-08-14 15:16:00 -0700 | [diff] [blame] | 296 | static const size_t MAX_NUM_LAYER_STATS = 200; |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 297 | std::unique_ptr<StatsEventDelegate> mStatsDelegate = std::make_unique<StatsEventDelegate>(); |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 298 | size_t mMaxPulledLayers = 8; |
| 299 | size_t mMaxPulledHistogramBuckets = 6; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 300 | }; |
| 301 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 302 | } // namespace impl |
| 303 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 304 | } // namespace android |