Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 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 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 19 | #include <atomic> |
| 20 | #include <chrono> |
| 21 | #include <deque> |
| 22 | #include <memory> |
| 23 | #include <mutex> |
| 24 | #include <optional> |
| 25 | #include <string> |
| 26 | |
Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 27 | #include <gui/ISurfaceComposer.h> |
Jorim Jaggi | 5814ab8 | 2020-12-03 20:45:58 +0100 | [diff] [blame] | 28 | #include <gui/JankInfo.h> |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 29 | #include <gui/LayerMetadata.h> |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 30 | #include <perfetto/trace/android/frame_timeline_event.pbzero.h> |
| 31 | #include <perfetto/tracing.h> |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 32 | #include <ui/FenceTime.h> |
| 33 | #include <utils/RefBase.h> |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 34 | #include <utils/String16.h> |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 35 | #include <utils/Timers.h> |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 36 | #include <utils/Vector.h> |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 37 | |
Dominik Laskowski | f6b4ba6 | 2021-11-09 12:46:10 -0800 | [diff] [blame] | 38 | #include <scheduler/Fps.h> |
| 39 | |
| 40 | #include "../TimeStats/TimeStats.h" |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 41 | |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 42 | namespace android::frametimeline { |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 43 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 44 | class FrameTimelineTest; |
| 45 | |
| 46 | using namespace std::chrono_literals; |
| 47 | |
| 48 | // Metadata indicating how the frame was presented w.r.t expected present time. |
| 49 | enum class FramePresentMetadata : int8_t { |
| 50 | // Frame was presented on time |
| 51 | OnTimePresent, |
| 52 | // Frame was presented late |
| 53 | LatePresent, |
| 54 | // Frame was presented early |
| 55 | EarlyPresent, |
| 56 | // Unknown/initial state |
| 57 | UnknownPresent, |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 60 | // Metadata comparing the frame's actual finish time to the expected deadline. |
| 61 | enum class FrameReadyMetadata : int8_t { |
| 62 | // App/SF finished on time. Early finish is treated as on time since the goal of any component |
| 63 | // is to finish before the deadline. |
| 64 | OnTimeFinish, |
| 65 | // App/SF finished work later than expected |
| 66 | LateFinish, |
| 67 | // Unknown/initial state |
| 68 | UnknownFinish, |
| 69 | }; |
| 70 | |
| 71 | // Metadata comparing the frame's actual start time to the expected start time. |
| 72 | enum class FrameStartMetadata : int8_t { |
| 73 | // App/SF started on time |
| 74 | OnTimeStart, |
| 75 | // App/SF started later than expected |
| 76 | LateStart, |
| 77 | // App/SF started earlier than expected |
| 78 | EarlyStart, |
| 79 | // Unknown/initial state |
| 80 | UnknownStart, |
| 81 | }; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * Collection of timestamps that can be used for both predictions and actual times. |
| 85 | */ |
| 86 | struct TimelineItem { |
| 87 | TimelineItem(const nsecs_t startTime = 0, const nsecs_t endTime = 0, |
| 88 | const nsecs_t presentTime = 0) |
| 89 | : startTime(startTime), endTime(endTime), presentTime(presentTime) {} |
| 90 | |
| 91 | nsecs_t startTime; |
| 92 | nsecs_t endTime; |
| 93 | nsecs_t presentTime; |
Ady Abraham | 55fa727 | 2020-09-30 19:19:27 -0700 | [diff] [blame] | 94 | |
| 95 | bool operator==(const TimelineItem& other) const { |
| 96 | return startTime == other.startTime && endTime == other.endTime && |
| 97 | presentTime == other.presentTime; |
| 98 | } |
| 99 | |
| 100 | bool operator!=(const TimelineItem& other) const { return !(*this == other); } |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 103 | struct JankClassificationThresholds { |
| 104 | // The various thresholds for App and SF. If the actual timestamp falls within the threshold |
| 105 | // compared to prediction, we treat it as on time. |
| 106 | nsecs_t presentThreshold = std::chrono::duration_cast<std::chrono::nanoseconds>(2ms).count(); |
Adithya Srinivasan | 54996e2 | 2021-06-25 22:26:45 +0000 | [diff] [blame] | 107 | nsecs_t deadlineThreshold = std::chrono::duration_cast<std::chrono::nanoseconds>(0ms).count(); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 108 | nsecs_t startThreshold = std::chrono::duration_cast<std::chrono::nanoseconds>(2ms).count(); |
| 109 | }; |
| 110 | |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 111 | /* |
| 112 | * TokenManager generates a running number token for a set of predictions made by VsyncPredictor. It |
| 113 | * saves these predictions for a short period of time and returns the predictions for a given token, |
| 114 | * if it hasn't expired. |
| 115 | */ |
| 116 | class TokenManager { |
| 117 | public: |
| 118 | virtual ~TokenManager() = default; |
| 119 | |
| 120 | // Generates a token for the given set of predictions. Stores the predictions for 120ms and |
| 121 | // destroys it later. |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 122 | virtual int64_t generateTokenForPredictions(TimelineItem&& prediction) = 0; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 123 | |
| 124 | // Returns the stored predictions for a given token, if the predictions haven't expired. |
| 125 | virtual std::optional<TimelineItem> getPredictionsForToken(int64_t token) const = 0; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | enum class PredictionState { |
| 129 | Valid, // Predictions obtained successfully from the TokenManager |
| 130 | Expired, // TokenManager no longer has the predictions |
| 131 | None, // Predictions are either not present or didn't come from TokenManager |
| 132 | }; |
| 133 | |
Adithya Srinivasan | 05bd2d1 | 2021-01-11 18:49:58 +0000 | [diff] [blame] | 134 | /* |
| 135 | * Trace cookie is used to send start and end timestamps of <Surface/Display>Frames separately |
| 136 | * without needing to resend all the other information. We send all info to perfetto, along with a |
| 137 | * new cookie, in the start of a frame. For the corresponding end, we just send the same cookie. |
| 138 | * This helps in reducing the amount of data emitted by the producer. |
| 139 | */ |
| 140 | class TraceCookieCounter { |
| 141 | public: |
| 142 | int64_t getCookieForTracing(); |
| 143 | |
| 144 | private: |
| 145 | // Friend class for testing |
| 146 | friend class android::frametimeline::FrameTimelineTest; |
| 147 | |
| 148 | std::atomic<int64_t> mTraceCookie = 0; |
| 149 | }; |
| 150 | |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 151 | class SurfaceFrame { |
| 152 | public: |
| 153 | enum class PresentState { |
| 154 | Presented, // Buffer was latched and presented by SurfaceFlinger |
| 155 | Dropped, // Buffer was dropped by SurfaceFlinger |
| 156 | Unknown, // Initial state, SurfaceFlinger hasn't seen this buffer yet |
| 157 | }; |
| 158 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 159 | // Only FrameTimeline can construct a SurfaceFrame as it provides Predictions(through |
| 160 | // TokenManager), Thresholds and TimeStats pointer. |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 161 | SurfaceFrame(const FrameTimelineInfo& frameTimelineInfo, pid_t ownerPid, uid_t ownerUid, |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 162 | int32_t layerId, std::string layerName, std::string debugName, |
| 163 | PredictionState predictionState, TimelineItem&& predictions, |
| 164 | std::shared_ptr<TimeStats> timeStats, JankClassificationThresholds thresholds, |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 165 | TraceCookieCounter* traceCookieCounter, bool isBuffer, GameMode); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 166 | ~SurfaceFrame() = default; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 167 | |
Sally Qi | 438eb7d | 2023-12-05 18:59:32 -0800 | [diff] [blame] | 168 | bool isSelfJanky() const; |
| 169 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 170 | // Returns std::nullopt if the frame hasn't been classified yet. |
| 171 | // Used by both SF and FrameTimeline. |
| 172 | std::optional<int32_t> getJankType() const; |
Ying Wei | 96eb535 | 2023-11-21 17:37:21 +0000 | [diff] [blame] | 173 | std::optional<JankSeverityType> getJankSeverityType() const; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 174 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 175 | // Functions called by SF |
| 176 | int64_t getToken() const { return mToken; }; |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 177 | int32_t getInputEventId() const { return mInputEventId; }; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 178 | TimelineItem getPredictions() const { return mPredictions; }; |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 179 | // Actual timestamps of the app are set individually at different functions. |
| 180 | // Start time (if the app provides) and Queue time are accessible after queueing the frame, |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 181 | // whereas Acquire Fence time is available only during latch. Drop time is available at the time |
| 182 | // the buffer was dropped. |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 183 | void setActualStartTime(nsecs_t actualStartTime); |
| 184 | void setActualQueueTime(nsecs_t actualQueueTime); |
| 185 | void setAcquireFenceTime(nsecs_t acquireFenceTime); |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 186 | void setDropTime(nsecs_t dropTime); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 187 | void setPresentState(PresentState presentState, nsecs_t lastLatchTime = 0); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 188 | void setRenderRate(Fps renderRate); |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 189 | // Return the render rate if it exists, otherwise returns the DisplayFrame's render rate. |
| 190 | Fps getRenderRate() const; |
Adithya Srinivasan | b6a2fa1 | 2021-03-13 00:23:09 +0000 | [diff] [blame] | 191 | void setGpuComposition(); |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 192 | |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 193 | // When a bufferless SurfaceFrame is promoted to a buffer SurfaceFrame, we also have to update |
| 194 | // isBuffer. |
| 195 | void promoteToBuffer(); |
| 196 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 197 | // Functions called by FrameTimeline |
| 198 | // BaseTime is the smallest timestamp in this SurfaceFrame. |
| 199 | // Used for dumping all timestamps relative to the oldest, making it easy to read. |
| 200 | nsecs_t getBaseTime() const; |
| 201 | // Sets the actual present time, appropriate metadata and classifies the jank. |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 202 | // displayRefreshRate, displayDeadlineDelta, and displayPresentDelta are propagated from the |
| 203 | // display frame. |
| 204 | void onPresent(nsecs_t presentTime, int32_t displayFrameJankType, Fps refreshRate, |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 205 | Fps displayFrameRenderRate, nsecs_t displayDeadlineDelta, |
| 206 | nsecs_t displayPresentDelta); |
Ady Abraham | 14beed7 | 2024-05-15 17:16:45 -0700 | [diff] [blame] | 207 | // Sets the frame as none janky as there was no real display frame. |
| 208 | void onCommitNotComposited(Fps refreshRate, Fps displayFrameRenderRate); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 209 | // All the timestamps are dumped relative to the baseTime |
| 210 | void dump(std::string& result, const std::string& indent, nsecs_t baseTime) const; |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 211 | // Dumps only the layer, token, is buffer, jank metadata, prediction and present states. |
| 212 | std::string miniDump() const; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 213 | // Emits a packet for perfetto tracing. The function body will be executed only if tracing is |
| 214 | // enabled. The displayFrameToken is needed to link the SurfaceFrame to the corresponding |
Ady Abraham | 57f8e18 | 2022-03-08 15:54:33 -0800 | [diff] [blame] | 215 | // DisplayFrame at the trace processor side. monoBootOffset is the difference |
| 216 | // between SYSTEM_TIME_BOOTTIME and SYSTEM_TIME_MONOTONIC. |
| 217 | void trace(int64_t displayFrameToken, nsecs_t monoBootOffset) const; |
Jorim Jaggi | 9c03b50 | 2020-11-24 23:51:31 +0100 | [diff] [blame] | 218 | |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 219 | // Getter functions used only by FrameTimelineTests and SurfaceFrame internally |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 220 | TimelineItem getActuals() const; |
| 221 | pid_t getOwnerPid() const { return mOwnerPid; }; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 222 | int32_t getLayerId() const { return mLayerId; }; |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 223 | PredictionState getPredictionState() const; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 224 | PresentState getPresentState() const; |
| 225 | FrameReadyMetadata getFrameReadyMetadata() const; |
| 226 | FramePresentMetadata getFramePresentMetadata() const; |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 227 | nsecs_t getDropTime() const; |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 228 | bool getIsBuffer() const; |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 229 | |
| 230 | // For prediction expired frames, this delta is subtracted from the actual end time to get a |
| 231 | // start time decent enough to see in traces. |
| 232 | // TODO(b/172587309): Remove this when we have actual start times. |
| 233 | static constexpr nsecs_t kPredictionExpiredStartTimeDelta = |
| 234 | std::chrono::duration_cast<std::chrono::nanoseconds>(2ms).count(); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 235 | |
| 236 | private: |
Ady Abraham | 57f8e18 | 2022-03-08 15:54:33 -0800 | [diff] [blame] | 237 | void tracePredictions(int64_t displayFrameToken, nsecs_t monoBootOffset) const; |
| 238 | void traceActuals(int64_t displayFrameToken, nsecs_t monoBootOffset) const; |
Adithya Srinivasan | 7c4ac7a | 2021-03-08 23:48:03 +0000 | [diff] [blame] | 239 | void classifyJankLocked(int32_t displayFrameJankType, const Fps& refreshRate, |
Ady Abraham | e96e79f | 2024-05-20 18:00:39 +0000 | [diff] [blame] | 240 | Fps displayFrameRenderRate, nsecs_t* outDeadlineDelta) REQUIRES(mMutex); |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 241 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 242 | const int64_t mToken; |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 243 | const int32_t mInputEventId; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 244 | const pid_t mOwnerPid; |
| 245 | const uid_t mOwnerUid; |
| 246 | const std::string mLayerName; |
| 247 | const std::string mDebugName; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 248 | const int32_t mLayerId; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 249 | PresentState mPresentState GUARDED_BY(mMutex); |
| 250 | const PredictionState mPredictionState; |
| 251 | const TimelineItem mPredictions; |
| 252 | TimelineItem mActuals GUARDED_BY(mMutex); |
| 253 | std::shared_ptr<TimeStats> mTimeStats; |
| 254 | const JankClassificationThresholds mJankClassificationThresholds; |
| 255 | nsecs_t mActualQueueTime GUARDED_BY(mMutex) = 0; |
Adithya Srinivasan | 061c14c | 2021-02-11 01:19:47 +0000 | [diff] [blame] | 256 | nsecs_t mDropTime GUARDED_BY(mMutex) = 0; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 257 | mutable std::mutex mMutex; |
| 258 | // Bitmask for the type of jank |
| 259 | int32_t mJankType GUARDED_BY(mMutex) = JankType::None; |
Ying Wei | 96eb535 | 2023-11-21 17:37:21 +0000 | [diff] [blame] | 260 | // Enum for the severity of jank |
| 261 | JankSeverityType mJankSeverityType GUARDED_BY(mMutex) = JankSeverityType::None; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 262 | // Indicates if this frame was composited by the GPU or not |
| 263 | bool mGpuComposition GUARDED_BY(mMutex) = false; |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 264 | // Refresh rate for this frame. |
| 265 | Fps mDisplayFrameRenderRate GUARDED_BY(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 266 | // Rendering rate for this frame. |
| 267 | std::optional<Fps> mRenderRate GUARDED_BY(mMutex); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 268 | // Enum for the type of present |
| 269 | FramePresentMetadata mFramePresentMetadata GUARDED_BY(mMutex) = |
| 270 | FramePresentMetadata::UnknownPresent; |
| 271 | // Enum for the type of finish |
| 272 | FrameReadyMetadata mFrameReadyMetadata GUARDED_BY(mMutex) = FrameReadyMetadata::UnknownFinish; |
| 273 | // Time when the previous buffer from the same layer was latched by SF. This is used in checking |
| 274 | // for BufferStuffing where the current buffer is expected to be ready but the previous buffer |
| 275 | // was latched instead. |
| 276 | nsecs_t mLastLatchTime GUARDED_BY(mMutex) = 0; |
Adithya Srinivasan | 05bd2d1 | 2021-01-11 18:49:58 +0000 | [diff] [blame] | 277 | // TraceCookieCounter is used to obtain the cookie for sendig trace packets to perfetto. Using a |
| 278 | // reference here because the counter is owned by FrameTimeline, which outlives SurfaceFrame. |
| 279 | TraceCookieCounter& mTraceCookieCounter; |
Adithya Srinivasan | 785addd | 2021-03-09 00:38:00 +0000 | [diff] [blame] | 280 | // Tells if the SurfaceFrame is representing a buffer or a transaction without a |
| 281 | // buffer(animations) |
| 282 | bool mIsBuffer; |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 283 | // GameMode from the layer. Used in metrics. |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 284 | GameMode mGameMode = GameMode::Unsupported; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | /* |
| 288 | * Maintains a history of SurfaceFrames grouped together by the vsync time in which they were |
| 289 | * presented |
| 290 | */ |
| 291 | class FrameTimeline { |
| 292 | public: |
| 293 | virtual ~FrameTimeline() = default; |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 294 | virtual TokenManager* getTokenManager() = 0; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 295 | |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 296 | // Initializes the Perfetto DataSource that emits DisplayFrame and SurfaceFrame events. Test |
| 297 | // classes can avoid double registration by mocking this function. |
| 298 | virtual void onBootFinished() = 0; |
| 299 | |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 300 | // Create a new surface frame, set the predictions based on a token and return it to the caller. |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 301 | // Debug name is the human-readable debugging string for dumpsys. |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 302 | virtual std::shared_ptr<SurfaceFrame> createSurfaceFrameForToken( |
| 303 | const FrameTimelineInfo& frameTimelineInfo, pid_t ownerPid, uid_t ownerUid, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 304 | int32_t layerId, std::string layerName, std::string debugName, bool isBuffer, |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 305 | GameMode) = 0; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 306 | |
| 307 | // Adds a new SurfaceFrame to the current DisplayFrame. Frames from multiple layers can be |
| 308 | // composited into one display frame. |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 309 | virtual void addSurfaceFrame(std::shared_ptr<SurfaceFrame> surfaceFrame) = 0; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 310 | |
| 311 | // The first function called by SF for the current DisplayFrame. Fetches SF predictions based on |
| 312 | // the token and sets the actualSfWakeTime for the current DisplayFrame. |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 313 | virtual void setSfWakeUp(int64_t token, nsecs_t wakeupTime, Fps refreshRate, |
| 314 | Fps renderRate) = 0; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 315 | |
Adithya Srinivasan | 36b01af | 2021-04-07 22:29:47 +0000 | [diff] [blame] | 316 | // Sets the sfPresentTime and finalizes the current DisplayFrame. Tracks the |
Adithya Srinivasan | b6a2fa1 | 2021-03-13 00:23:09 +0000 | [diff] [blame] | 317 | // given present fence until it's signaled, and updates the present timestamps of all presented |
Adithya Srinivasan | 36b01af | 2021-04-07 22:29:47 +0000 | [diff] [blame] | 318 | // SurfaceFrames in that vsync. If a gpuFence was also provided, its tracked in the |
| 319 | // corresponding DisplayFrame. |
Adithya Srinivasan | b6a2fa1 | 2021-03-13 00:23:09 +0000 | [diff] [blame] | 320 | virtual void setSfPresent(nsecs_t sfPresentTime, const std::shared_ptr<FenceTime>& presentFence, |
Adithya Srinivasan | 36b01af | 2021-04-07 22:29:47 +0000 | [diff] [blame] | 321 | const std::shared_ptr<FenceTime>& gpuFence) = 0; |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 322 | |
Ady Abraham | 14beed7 | 2024-05-15 17:16:45 -0700 | [diff] [blame] | 323 | // Tells FrameTimeline that a frame was committed but not composited. This is used to flush |
| 324 | // all the associated surface frames. |
| 325 | virtual void onCommitNotComposited() = 0; |
| 326 | |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 327 | // Args: |
| 328 | // -jank : Dumps only the Display Frames that are either janky themselves |
| 329 | // or contain janky Surface Frames. |
| 330 | // -all : Dumps the entire list of DisplayFrames and the SurfaceFrames contained within |
| 331 | virtual void parseArgs(const Vector<String16>& args, std::string& result) = 0; |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 332 | |
| 333 | // Sets the max number of display frames that can be stored. Called by SF backdoor. |
Josh Gao | ade0f67 | 2023-01-17 14:59:04 -0800 | [diff] [blame] | 334 | virtual void setMaxDisplayFrames(uint32_t size) = 0; |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 335 | |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 336 | // Computes the historical fps for the provided set of layer IDs |
| 337 | // The fps is compted from the linear timeline of present timestamps for DisplayFrames |
| 338 | // containing at least one layer ID. |
Josh Gao | ade0f67 | 2023-01-17 14:59:04 -0800 | [diff] [blame] | 339 | virtual float computeFps(const std::unordered_set<int32_t>& layerIds) = 0; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 340 | |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 341 | // Restores the max number of display frames to default. Called by SF backdoor. |
| 342 | virtual void reset() = 0; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | namespace impl { |
| 346 | |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 347 | class TokenManager : public android::frametimeline::TokenManager { |
| 348 | public: |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 349 | TokenManager() : mCurrentToken(FrameTimelineInfo::INVALID_VSYNC_ID + 1) {} |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 350 | ~TokenManager() = default; |
| 351 | |
| 352 | int64_t generateTokenForPredictions(TimelineItem&& predictions) override; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 353 | std::optional<TimelineItem> getPredictionsForToken(int64_t token) const override; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 354 | |
| 355 | private: |
| 356 | // Friend class for testing |
| 357 | friend class android::frametimeline::FrameTimelineTest; |
| 358 | |
| 359 | void flushTokens(nsecs_t flushTime) REQUIRES(mMutex); |
| 360 | |
Adithya Srinivasan | bed4c4f | 2021-05-03 20:24:46 +0000 | [diff] [blame] | 361 | std::map<int64_t, TimelineItem> mPredictions GUARDED_BY(mMutex); |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 362 | int64_t mCurrentToken GUARDED_BY(mMutex); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 363 | mutable std::mutex mMutex; |
Adithya Srinivasan | bed4c4f | 2021-05-03 20:24:46 +0000 | [diff] [blame] | 364 | static constexpr size_t kMaxTokens = 500; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 365 | }; |
| 366 | |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 367 | class FrameTimeline : public android::frametimeline::FrameTimeline { |
| 368 | public: |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 369 | class FrameTimelineDataSource : public perfetto::DataSource<FrameTimelineDataSource> { |
| 370 | void OnSetup(const SetupArgs&) override{}; |
| 371 | void OnStart(const StartArgs&) override{}; |
| 372 | void OnStop(const StopArgs&) override{}; |
| 373 | }; |
| 374 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 375 | /* |
| 376 | * DisplayFrame should be used only internally within FrameTimeline. All members and methods are |
| 377 | * guarded by FrameTimeline's mMutex. |
| 378 | */ |
| 379 | class DisplayFrame { |
| 380 | public: |
Adithya Srinivasan | 05bd2d1 | 2021-01-11 18:49:58 +0000 | [diff] [blame] | 381 | DisplayFrame(std::shared_ptr<TimeStats> timeStats, JankClassificationThresholds thresholds, |
Adithya Srinivasan | 82eef32 | 2021-04-10 00:06:04 +0000 | [diff] [blame] | 382 | TraceCookieCounter* traceCookieCounter); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 383 | virtual ~DisplayFrame() = default; |
| 384 | // Dumpsys interface - dumps only if the DisplayFrame itself is janky or is at least one |
| 385 | // SurfaceFrame is janky. |
| 386 | void dumpJank(std::string& result, nsecs_t baseTime, int displayFrameCount) const; |
| 387 | // Dumpsys interface - dumps all data irrespective of jank |
| 388 | void dumpAll(std::string& result, nsecs_t baseTime) const; |
| 389 | // Emits a packet for perfetto tracing. The function body will be executed only if tracing |
Ady Abraham | 57f8e18 | 2022-03-08 15:54:33 -0800 | [diff] [blame] | 390 | // is enabled. monoBootOffset is the difference between SYSTEM_TIME_BOOTTIME |
| 391 | // and SYSTEM_TIME_MONOTONIC. |
Sally Qi | 438eb7d | 2023-12-05 18:59:32 -0800 | [diff] [blame] | 392 | nsecs_t trace(pid_t surfaceFlingerPid, nsecs_t monoBootOffset, |
| 393 | nsecs_t previousPredictionPresentTime) const; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 394 | // Sets the token, vsyncPeriod, predictions and SF start time. |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 395 | void onSfWakeUp(int64_t token, Fps refreshRate, Fps renderRate, |
| 396 | std::optional<TimelineItem> predictions, nsecs_t wakeUpTime); |
Adithya Srinivasan | 115ac69 | 2021-03-06 01:21:30 +0000 | [diff] [blame] | 397 | // Sets the appropriate metadata and classifies the jank. |
Adithya Srinivasan | 57dc81d | 2021-04-14 17:31:41 +0000 | [diff] [blame] | 398 | void onPresent(nsecs_t signalTime, nsecs_t previousPresentTime); |
Ady Abraham | 14beed7 | 2024-05-15 17:16:45 -0700 | [diff] [blame] | 399 | // Flushes all the surface frames as those were not generating any actual display frames. |
| 400 | void onCommitNotComposited(); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 401 | // Adds the provided SurfaceFrame to the current display frame. |
| 402 | void addSurfaceFrame(std::shared_ptr<SurfaceFrame> surfaceFrame); |
| 403 | |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 404 | void setPredictions(PredictionState predictionState, TimelineItem predictions); |
| 405 | void setActualStartTime(nsecs_t actualStartTime); |
| 406 | void setActualEndTime(nsecs_t actualEndTime); |
Adithya Srinivasan | 36b01af | 2021-04-07 22:29:47 +0000 | [diff] [blame] | 407 | void setGpuFence(const std::shared_ptr<FenceTime>& gpuFence); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 408 | |
| 409 | // BaseTime is the smallest timestamp in a DisplayFrame. |
| 410 | // Used for dumping all timestamps relative to the oldest, making it easy to read. |
| 411 | nsecs_t getBaseTime() const; |
| 412 | |
| 413 | // Functions to be used only in testing. |
| 414 | TimelineItem getActuals() const { return mSurfaceFlingerActuals; }; |
| 415 | TimelineItem getPredictions() const { return mSurfaceFlingerPredictions; }; |
Adithya Srinivasan | 939cd4d | 2021-02-23 06:18:13 +0000 | [diff] [blame] | 416 | FrameStartMetadata getFrameStartMetadata() const { return mFrameStartMetadata; }; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 417 | FramePresentMetadata getFramePresentMetadata() const { return mFramePresentMetadata; }; |
| 418 | FrameReadyMetadata getFrameReadyMetadata() const { return mFrameReadyMetadata; }; |
| 419 | int32_t getJankType() const { return mJankType; } |
Ying Wei | 96eb535 | 2023-11-21 17:37:21 +0000 | [diff] [blame] | 420 | JankSeverityType getJankSeverityType() const { return mJankSeverityType; } |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 421 | const std::vector<std::shared_ptr<SurfaceFrame>>& getSurfaceFrames() const { |
| 422 | return mSurfaceFrames; |
| 423 | } |
| 424 | |
| 425 | private: |
| 426 | void dump(std::string& result, nsecs_t baseTime) const; |
Ady Abraham | 57f8e18 | 2022-03-08 15:54:33 -0800 | [diff] [blame] | 427 | void tracePredictions(pid_t surfaceFlingerPid, nsecs_t monoBootOffset) const; |
| 428 | void traceActuals(pid_t surfaceFlingerPid, nsecs_t monoBootOffset) const; |
Sally Qi | aa10774 | 2023-09-29 14:53:14 -0700 | [diff] [blame] | 429 | void addSkippedFrame(pid_t surfaceFlingerPid, nsecs_t monoBootOffset, |
| 430 | nsecs_t previousActualPresentTime) const; |
Adithya Srinivasan | 57dc81d | 2021-04-14 17:31:41 +0000 | [diff] [blame] | 431 | void classifyJank(nsecs_t& deadlineDelta, nsecs_t& deltaToVsync, |
| 432 | nsecs_t previousPresentTime); |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 433 | |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 434 | int64_t mToken = FrameTimelineInfo::INVALID_VSYNC_ID; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 435 | |
| 436 | /* Usage of TimelineItem w.r.t SurfaceFlinger |
| 437 | * startTime Time when SurfaceFlinger wakes up to handle transactions and buffer updates |
| 438 | * endTime Time when SurfaceFlinger sends a composited frame to Display |
| 439 | * presentTime Time when the composited frame was presented on screen |
| 440 | */ |
| 441 | TimelineItem mSurfaceFlingerPredictions; |
| 442 | TimelineItem mSurfaceFlingerActuals; |
| 443 | std::shared_ptr<TimeStats> mTimeStats; |
| 444 | const JankClassificationThresholds mJankClassificationThresholds; |
| 445 | |
| 446 | // Collection of predictions and actual values sent over by Layers |
| 447 | std::vector<std::shared_ptr<SurfaceFrame>> mSurfaceFrames; |
| 448 | |
| 449 | PredictionState mPredictionState = PredictionState::None; |
| 450 | // Bitmask for the type of jank |
| 451 | int32_t mJankType = JankType::None; |
Ying Wei | 96eb535 | 2023-11-21 17:37:21 +0000 | [diff] [blame] | 452 | // Enum for the severity of jank |
| 453 | JankSeverityType mJankSeverityType = JankSeverityType::None; |
Adithya Srinivasan | 36b01af | 2021-04-07 22:29:47 +0000 | [diff] [blame] | 454 | // A valid gpu fence indicates that the DisplayFrame was composited by the GPU |
| 455 | std::shared_ptr<FenceTime> mGpuFence = FenceTime::NO_FENCE; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 456 | // Enum for the type of present |
| 457 | FramePresentMetadata mFramePresentMetadata = FramePresentMetadata::UnknownPresent; |
| 458 | // Enum for the type of finish |
| 459 | FrameReadyMetadata mFrameReadyMetadata = FrameReadyMetadata::UnknownFinish; |
| 460 | // Enum for the type of start |
| 461 | FrameStartMetadata mFrameStartMetadata = FrameStartMetadata::UnknownStart; |
| 462 | // The refresh rate (vsync period) in nanoseconds as seen by SF during this DisplayFrame's |
| 463 | // timeline |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 464 | Fps mRefreshRate; |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 465 | // The current render rate for this DisplayFrame. |
| 466 | Fps mRenderRate; |
Adithya Srinivasan | 05bd2d1 | 2021-01-11 18:49:58 +0000 | [diff] [blame] | 467 | // TraceCookieCounter is used to obtain the cookie for sendig trace packets to perfetto. |
| 468 | // Using a reference here because the counter is owned by FrameTimeline, which outlives |
| 469 | // DisplayFrame. |
| 470 | TraceCookieCounter& mTraceCookieCounter; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 471 | }; |
| 472 | |
| 473 | FrameTimeline(std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid, |
Ady Abraham | 57f8e18 | 2022-03-08 15:54:33 -0800 | [diff] [blame] | 474 | JankClassificationThresholds thresholds = {}, bool useBootTimeClock = true); |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 475 | ~FrameTimeline() = default; |
| 476 | |
Adithya Srinivasan | 5f683cf | 2020-09-15 14:21:04 -0700 | [diff] [blame] | 477 | frametimeline::TokenManager* getTokenManager() override { return &mTokenManager; } |
Siarhei Vishniakou | fc434ac | 2021-01-13 10:28:00 -1000 | [diff] [blame] | 478 | std::shared_ptr<SurfaceFrame> createSurfaceFrameForToken( |
| 479 | const FrameTimelineInfo& frameTimelineInfo, pid_t ownerPid, uid_t ownerUid, |
Adithya Srinivasan | 58069dc | 2021-06-04 20:37:02 +0000 | [diff] [blame] | 480 | int32_t layerId, std::string layerName, std::string debugName, bool isBuffer, |
Dominik Laskowski | f5d0ea5 | 2021-09-26 17:27:01 -0700 | [diff] [blame] | 481 | GameMode) override; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 482 | void addSurfaceFrame(std::shared_ptr<frametimeline::SurfaceFrame> surfaceFrame) override; |
Pascal Muetschard | ac7bcd9 | 2023-10-03 15:05:36 +0200 | [diff] [blame] | 483 | void setSfWakeUp(int64_t token, nsecs_t wakeupTime, Fps refreshRate, Fps renderRate) override; |
Adithya Srinivasan | b6a2fa1 | 2021-03-13 00:23:09 +0000 | [diff] [blame] | 484 | void setSfPresent(nsecs_t sfPresentTime, const std::shared_ptr<FenceTime>& presentFence, |
Adithya Srinivasan | 36b01af | 2021-04-07 22:29:47 +0000 | [diff] [blame] | 485 | const std::shared_ptr<FenceTime>& gpuFence = FenceTime::NO_FENCE) override; |
Ady Abraham | 14beed7 | 2024-05-15 17:16:45 -0700 | [diff] [blame] | 486 | void onCommitNotComposited() override; |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 487 | void parseArgs(const Vector<String16>& args, std::string& result) override; |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 488 | void setMaxDisplayFrames(uint32_t size) override; |
Alec Mouri | adebf5c | 2021-01-05 12:57:36 -0800 | [diff] [blame] | 489 | float computeFps(const std::unordered_set<int32_t>& layerIds) override; |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 490 | void reset() override; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 491 | |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 492 | // Sets up the perfetto tracing backend and data source. |
| 493 | void onBootFinished() override; |
| 494 | // Registers the data source with the perfetto backend. Called as part of onBootFinished() |
| 495 | // and should not be called manually outside of tests. |
| 496 | void registerDataSource(); |
| 497 | |
| 498 | static constexpr char kFrameTimelineDataSource[] = "android.surfaceflinger.frametimeline"; |
| 499 | |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 500 | private: |
| 501 | // Friend class for testing |
| 502 | friend class android::frametimeline::FrameTimelineTest; |
| 503 | |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 504 | void flushPendingPresentFences() REQUIRES(mMutex); |
Ady Abraham | fcb1686 | 2022-10-10 14:35:21 -0700 | [diff] [blame] | 505 | std::optional<size_t> getFirstSignalFenceIndex() const REQUIRES(mMutex); |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 506 | void finalizeCurrentDisplayFrame() REQUIRES(mMutex); |
Adithya Srinivasan | 8fc601d | 2020-09-25 13:51:09 -0700 | [diff] [blame] | 507 | void dumpAll(std::string& result); |
| 508 | void dumpJank(std::string& result); |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 509 | |
| 510 | // Sliding window of display frames. TODO(b/168072834): compare perf with fixed size array |
| 511 | std::deque<std::shared_ptr<DisplayFrame>> mDisplayFrames GUARDED_BY(mMutex); |
| 512 | std::vector<std::pair<std::shared_ptr<FenceTime>, std::shared_ptr<DisplayFrame>>> |
| 513 | mPendingPresentFences GUARDED_BY(mMutex); |
| 514 | std::shared_ptr<DisplayFrame> mCurrentDisplayFrame GUARDED_BY(mMutex); |
| 515 | TokenManager mTokenManager; |
Adithya Srinivasan | 05bd2d1 | 2021-01-11 18:49:58 +0000 | [diff] [blame] | 516 | TraceCookieCounter mTraceCookieCounter; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 517 | mutable std::mutex mMutex; |
Ady Abraham | 57f8e18 | 2022-03-08 15:54:33 -0800 | [diff] [blame] | 518 | const bool mUseBootTimeClock; |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 519 | uint32_t mMaxDisplayFrames; |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 520 | std::shared_ptr<TimeStats> mTimeStats; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 521 | const pid_t mSurfaceFlingerPid; |
Sally Qi | 438eb7d | 2023-12-05 18:59:32 -0800 | [diff] [blame] | 522 | nsecs_t mPreviousActualPresentTime = 0; |
| 523 | nsecs_t mPreviousPredictionPresentTime = 0; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 524 | const JankClassificationThresholds mJankClassificationThresholds; |
Adithya Srinivasan | 2d73632 | 2020-10-01 16:53:48 -0700 | [diff] [blame] | 525 | static constexpr uint32_t kDefaultMaxDisplayFrames = 64; |
Adithya Srinivasan | 0118967 | 2020-10-20 14:23:05 -0700 | [diff] [blame] | 526 | // The initial container size for the vector<SurfaceFrames> inside display frame. Although |
| 527 | // this number doesn't represent any bounds on the number of surface frames that can go in a |
| 528 | // display frame, this is a good starting size for the vector so that we can avoid the |
| 529 | // internal vector resizing that happens with push_back. |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 530 | static constexpr uint32_t kNumSurfaceFramesInitial = 10; |
Adithya Srinivasan | f279e04 | 2020-08-17 14:56:27 -0700 | [diff] [blame] | 531 | }; |
| 532 | |
| 533 | } // namespace impl |
| 534 | } // namespace android::frametimeline |