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 | */ |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 16 | |
Alec Mouri | 75de8f2 | 2021-01-20 14:53:44 -0800 | [diff] [blame] | 17 | #include <unordered_map> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "TimeStats" |
| 20 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 21 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 22 | #include <android-base/stringprintf.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 23 | #include <log/log.h> |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 24 | #include <timestatsatomsproto/TimeStatsAtomsProtoHeader.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 25 | #include <utils/String8.h> |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 26 | #include <utils/Timers.h> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 27 | #include <utils/Trace.h> |
| 28 | |
| 29 | #include <algorithm> |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 30 | #include <chrono> |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 31 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 32 | #include "TimeStats.h" |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 33 | #include "timestatsproto/TimeStatsHelper.h" |
| 34 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 35 | namespace android { |
| 36 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 37 | namespace impl { |
| 38 | |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 39 | namespace { |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 40 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 41 | FrameTimingHistogram histogramToProto(const std::unordered_map<int32_t, int32_t>& histogram, |
| 42 | size_t maxPulledHistogramBuckets) { |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 43 | auto buckets = std::vector<std::pair<int32_t, int32_t>>(histogram.begin(), histogram.end()); |
| 44 | std::sort(buckets.begin(), buckets.end(), |
| 45 | [](std::pair<int32_t, int32_t>& left, std::pair<int32_t, int32_t>& right) { |
| 46 | return left.second > right.second; |
| 47 | }); |
| 48 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 49 | FrameTimingHistogram histogramProto; |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 50 | int histogramSize = 0; |
| 51 | for (const auto& bucket : buckets) { |
| 52 | if (++histogramSize > maxPulledHistogramBuckets) { |
| 53 | break; |
| 54 | } |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 55 | histogramProto.add_time_millis_buckets((int32_t)bucket.first); |
| 56 | histogramProto.add_frame_counts((int64_t)bucket.second); |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 57 | } |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 58 | return histogramProto; |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 59 | } |
Alec Mouri | 75de8f2 | 2021-01-20 14:53:44 -0800 | [diff] [blame] | 60 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 61 | SurfaceflingerStatsLayerInfo_SetFrameRateVote frameRateVoteToProto( |
| 62 | const TimeStats::SetFrameRateVote& setFrameRateVote) { |
| 63 | using FrameRateCompatibilityEnum = |
| 64 | SurfaceflingerStatsLayerInfo::SetFrameRateVote::FrameRateCompatibility; |
| 65 | using SeamlessnessEnum = SurfaceflingerStatsLayerInfo::SetFrameRateVote::Seamlessness; |
Alec Mouri | 75de8f2 | 2021-01-20 14:53:44 -0800 | [diff] [blame] | 66 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 67 | SurfaceflingerStatsLayerInfo_SetFrameRateVote proto; |
| 68 | proto.set_frame_rate(setFrameRateVote.frameRate); |
| 69 | proto.set_frame_rate_compatibility( |
| 70 | static_cast<FrameRateCompatibilityEnum>(setFrameRateVote.frameRateCompatibility)); |
| 71 | proto.set_seamlessness(static_cast<SeamlessnessEnum>(setFrameRateVote.seamlessness)); |
| 72 | return proto; |
Alec Mouri | 75de8f2 | 2021-01-20 14:53:44 -0800 | [diff] [blame] | 73 | } |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 74 | } // namespace |
| 75 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 76 | bool TimeStats::populateGlobalAtom(std::string* pulledData) { |
Alec Mouri | dfad900 | 2020-02-12 17:49:09 -0800 | [diff] [blame] | 77 | std::lock_guard<std::mutex> lock(mMutex); |
| 78 | |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 79 | if (mTimeStats.statsStartLegacy == 0) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 80 | return false; |
Alec Mouri | dfad900 | 2020-02-12 17:49:09 -0800 | [diff] [blame] | 81 | } |
| 82 | flushPowerTimeLocked(); |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 83 | SurfaceflingerStatsGlobalInfoWrapper atomList; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 84 | for (const auto& globalSlice : mTimeStats.stats) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 85 | SurfaceflingerStatsGlobalInfo* atom = atomList.add_atom(); |
| 86 | atom->set_total_frames(mTimeStats.totalFramesLegacy); |
| 87 | atom->set_missed_frames(mTimeStats.missedFramesLegacy); |
| 88 | atom->set_client_composition_frames(mTimeStats.clientCompositionFramesLegacy); |
| 89 | atom->set_display_on_millis(mTimeStats.displayOnTimeLegacy); |
| 90 | atom->set_animation_millis(mTimeStats.presentToPresentLegacy.totalTime()); |
| 91 | atom->set_event_connection_count(mTimeStats.displayEventConnectionsCountLegacy); |
| 92 | *atom->mutable_frame_duration() = |
| 93 | histogramToProto(mTimeStats.frameDurationLegacy.hist, mMaxPulledHistogramBuckets); |
| 94 | *atom->mutable_render_engine_timing() = |
| 95 | histogramToProto(mTimeStats.renderEngineTimingLegacy.hist, |
| 96 | mMaxPulledHistogramBuckets); |
| 97 | atom->set_total_timeline_frames(globalSlice.second.jankPayload.totalFrames); |
| 98 | atom->set_total_janky_frames(globalSlice.second.jankPayload.totalJankyFrames); |
| 99 | atom->set_total_janky_frames_with_long_cpu(globalSlice.second.jankPayload.totalSFLongCpu); |
| 100 | atom->set_total_janky_frames_with_long_gpu(globalSlice.second.jankPayload.totalSFLongGpu); |
| 101 | atom->set_total_janky_frames_sf_unattributed( |
| 102 | globalSlice.second.jankPayload.totalSFUnattributed); |
| 103 | atom->set_total_janky_frames_app_unattributed( |
| 104 | globalSlice.second.jankPayload.totalAppUnattributed); |
| 105 | atom->set_total_janky_frames_sf_scheduling( |
| 106 | globalSlice.second.jankPayload.totalSFScheduling); |
| 107 | atom->set_total_jank_frames_sf_prediction_error( |
| 108 | globalSlice.second.jankPayload.totalSFPredictionError); |
| 109 | atom->set_total_jank_frames_app_buffer_stuffing( |
| 110 | globalSlice.second.jankPayload.totalAppBufferStuffing); |
| 111 | atom->set_display_refresh_rate_bucket(globalSlice.first.displayRefreshRateBucket); |
| 112 | *atom->mutable_sf_deadline_misses() = |
| 113 | histogramToProto(globalSlice.second.displayDeadlineDeltas.hist, |
| 114 | mMaxPulledHistogramBuckets); |
| 115 | *atom->mutable_sf_prediction_errors() = |
| 116 | histogramToProto(globalSlice.second.displayPresentDeltas.hist, |
| 117 | mMaxPulledHistogramBuckets); |
| 118 | atom->set_render_rate_bucket(globalSlice.first.renderRateBucket); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 121 | // Always clear data. |
Alec Mouri | dfad900 | 2020-02-12 17:49:09 -0800 | [diff] [blame] | 122 | clearGlobalLocked(); |
| 123 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 124 | return atomList.SerializeToString(pulledData); |
Alec Mouri | dfad900 | 2020-02-12 17:49:09 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 127 | bool TimeStats::populateLayerAtom(std::string* pulledData) { |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 128 | std::lock_guard<std::mutex> lock(mMutex); |
| 129 | |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 130 | std::vector<TimeStatsHelper::TimeStatsLayer*> dumpStats; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 131 | uint32_t numLayers = 0; |
| 132 | for (const auto& globalSlice : mTimeStats.stats) { |
| 133 | numLayers += globalSlice.second.stats.size(); |
| 134 | } |
| 135 | |
| 136 | dumpStats.reserve(numLayers); |
| 137 | |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 138 | for (auto& globalSlice : mTimeStats.stats) { |
| 139 | for (auto& layerSlice : globalSlice.second.stats) { |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 140 | dumpStats.push_back(&layerSlice.second); |
| 141 | } |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | std::sort(dumpStats.begin(), dumpStats.end(), |
| 145 | [](TimeStatsHelper::TimeStatsLayer const* l, |
| 146 | TimeStatsHelper::TimeStatsLayer const* r) { |
| 147 | return l->totalFrames > r->totalFrames; |
| 148 | }); |
| 149 | |
| 150 | if (mMaxPulledLayers < dumpStats.size()) { |
| 151 | dumpStats.resize(mMaxPulledLayers); |
| 152 | } |
| 153 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 154 | SurfaceflingerStatsLayerInfoWrapper atomList; |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 155 | for (auto& layer : dumpStats) { |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 156 | SurfaceflingerStatsLayerInfo* atom = atomList.add_atom(); |
| 157 | atom->set_layer_name(layer->layerName); |
| 158 | atom->set_total_frames(layer->totalFrames); |
| 159 | atom->set_dropped_frames(layer->droppedFrames); |
| 160 | const auto& present2PresentHist = layer->deltas.find("present2present"); |
| 161 | if (present2PresentHist != layer->deltas.cend()) { |
| 162 | *atom->mutable_present_to_present() = |
| 163 | histogramToProto(present2PresentHist->second.hist, mMaxPulledHistogramBuckets); |
| 164 | } |
| 165 | const auto& post2presentHist = layer->deltas.find("post2present"); |
| 166 | if (post2presentHist != layer->deltas.cend()) { |
| 167 | *atom->mutable_post_to_present() = |
| 168 | histogramToProto(post2presentHist->second.hist, mMaxPulledHistogramBuckets); |
| 169 | } |
| 170 | const auto& acquire2presentHist = layer->deltas.find("acquire2present"); |
| 171 | if (acquire2presentHist != layer->deltas.cend()) { |
| 172 | *atom->mutable_acquire_to_present() = |
| 173 | histogramToProto(acquire2presentHist->second.hist, mMaxPulledHistogramBuckets); |
| 174 | } |
| 175 | const auto& latch2presentHist = layer->deltas.find("latch2present"); |
| 176 | if (latch2presentHist != layer->deltas.cend()) { |
| 177 | *atom->mutable_latch_to_present() = |
| 178 | histogramToProto(latch2presentHist->second.hist, mMaxPulledHistogramBuckets); |
| 179 | } |
| 180 | const auto& desired2presentHist = layer->deltas.find("desired2present"); |
| 181 | if (desired2presentHist != layer->deltas.cend()) { |
| 182 | *atom->mutable_desired_to_present() = |
| 183 | histogramToProto(desired2presentHist->second.hist, mMaxPulledHistogramBuckets); |
| 184 | } |
| 185 | const auto& post2acquireHist = layer->deltas.find("post2acquire"); |
| 186 | if (post2acquireHist != layer->deltas.cend()) { |
| 187 | *atom->mutable_post_to_acquire() = |
| 188 | histogramToProto(post2acquireHist->second.hist, mMaxPulledHistogramBuckets); |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 191 | atom->set_late_acquire_frames(layer->lateAcquireFrames); |
| 192 | atom->set_bad_desired_present_frames(layer->badDesiredPresentFrames); |
| 193 | atom->set_uid(layer->uid); |
| 194 | atom->set_total_timeline_frames(layer->jankPayload.totalFrames); |
| 195 | atom->set_total_janky_frames(layer->jankPayload.totalJankyFrames); |
| 196 | atom->set_total_janky_frames_with_long_cpu(layer->jankPayload.totalSFLongCpu); |
| 197 | atom->set_total_janky_frames_with_long_gpu(layer->jankPayload.totalSFLongGpu); |
| 198 | atom->set_total_janky_frames_sf_unattributed(layer->jankPayload.totalSFUnattributed); |
| 199 | atom->set_total_janky_frames_app_unattributed(layer->jankPayload.totalAppUnattributed); |
| 200 | atom->set_total_janky_frames_sf_scheduling(layer->jankPayload.totalSFScheduling); |
| 201 | atom->set_total_jank_frames_sf_prediction_error(layer->jankPayload.totalSFPredictionError); |
| 202 | atom->set_total_jank_frames_app_buffer_stuffing(layer->jankPayload.totalAppBufferStuffing); |
| 203 | atom->set_display_refresh_rate_bucket(layer->displayRefreshRateBucket); |
| 204 | atom->set_render_rate_bucket(layer->renderRateBucket); |
| 205 | *atom->mutable_set_frame_rate_vote() = frameRateVoteToProto(layer->setFrameRateVote); |
| 206 | *atom->mutable_app_deadline_misses() = |
| 207 | histogramToProto(layer->deltas["appDeadlineDeltas"].hist, |
| 208 | mMaxPulledHistogramBuckets); |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 209 | } |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 210 | |
| 211 | // Always clear data. |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 212 | clearLayersLocked(); |
| 213 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 214 | return atomList.SerializeToString(pulledData); |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 217 | TimeStats::TimeStats() : TimeStats(std::nullopt, std::nullopt) {} |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 218 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 219 | TimeStats::TimeStats(std::optional<size_t> maxPulledLayers, |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 220 | std::optional<size_t> maxPulledHistogramBuckets) { |
Alec Mouri | 3738434 | 2020-01-02 17:23:37 -0800 | [diff] [blame] | 221 | if (maxPulledLayers) { |
| 222 | mMaxPulledLayers = *maxPulledLayers; |
| 223 | } |
| 224 | |
| 225 | if (maxPulledHistogramBuckets) { |
| 226 | mMaxPulledHistogramBuckets = *maxPulledHistogramBuckets; |
| 227 | } |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 230 | bool TimeStats::onPullAtom(const int atomId, std::string* pulledData) { |
| 231 | bool success = false; |
| 232 | if (atomId == 10062) { // SURFACEFLINGER_STATS_GLOBAL_INFO |
| 233 | success = populateGlobalAtom(pulledData); |
| 234 | } else if (atomId == 10063) { // SURFACEFLINGER_STATS_LAYER_INFO |
| 235 | success = populateLayerAtom(pulledData); |
| 236 | } |
Alec Mouri | 3ecd5cd | 2020-01-29 12:53:07 -0800 | [diff] [blame] | 237 | |
Tej Singh | e275177 | 2021-04-06 22:05:29 -0700 | [diff] [blame^] | 238 | // Enable timestats now. The first full pull for a given build is expected to |
| 239 | // have empty or very little stats, as stats are first enabled after the |
| 240 | // first pull is completed for either the global or layer stats. |
| 241 | enable(); |
| 242 | return success; |
Alec Mouri | b3885ad | 2019-09-06 17:08:55 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 245 | void TimeStats::parseArgs(bool asProto, const Vector<String16>& args, std::string& result) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 246 | ATRACE_CALL(); |
| 247 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 248 | std::unordered_map<std::string, int32_t> argsMap; |
Dominik Laskowski | c286714 | 2019-01-21 11:33:38 -0800 | [diff] [blame] | 249 | for (size_t index = 0; index < args.size(); ++index) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 250 | argsMap[std::string(String8(args[index]).c_str())] = index; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | if (argsMap.count("-disable")) { |
| 254 | disable(); |
| 255 | } |
| 256 | |
| 257 | if (argsMap.count("-dump")) { |
Yiwei Zhang | 8a4015c | 2018-05-08 16:03:47 -0700 | [diff] [blame] | 258 | std::optional<uint32_t> maxLayers = std::nullopt; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 259 | auto iter = argsMap.find("-maxlayers"); |
| 260 | if (iter != argsMap.end() && iter->second + 1 < static_cast<int32_t>(args.size())) { |
Yiwei Zhang | 8a4015c | 2018-05-08 16:03:47 -0700 | [diff] [blame] | 261 | int64_t value = strtol(String8(args[iter->second + 1]).c_str(), nullptr, 10); |
| 262 | value = std::clamp(value, int64_t(0), int64_t(UINT32_MAX)); |
| 263 | maxLayers = static_cast<uint32_t>(value); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Yiwei Zhang | 8a4015c | 2018-05-08 16:03:47 -0700 | [diff] [blame] | 266 | dump(asProto, maxLayers, result); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | if (argsMap.count("-clear")) { |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 270 | clearAll(); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | if (argsMap.count("-enable")) { |
| 274 | enable(); |
| 275 | } |
| 276 | } |
| 277 | |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 278 | std::string TimeStats::miniDump() { |
| 279 | ATRACE_CALL(); |
| 280 | |
| 281 | std::string result = "TimeStats miniDump:\n"; |
| 282 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | e926ab5 | 2019-08-14 15:16:00 -0700 | [diff] [blame] | 283 | android::base::StringAppendF(&result, "Number of layers currently being tracked is %zu\n", |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 284 | mTimeStatsTracker.size()); |
Yiwei Zhang | e926ab5 | 2019-08-14 15:16:00 -0700 | [diff] [blame] | 285 | android::base::StringAppendF(&result, "Number of layers in the stats pool is %zu\n", |
| 286 | mTimeStats.stats.size()); |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 287 | return result; |
| 288 | } |
| 289 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 290 | void TimeStats::incrementTotalFrames() { |
| 291 | if (!mEnabled.load()) return; |
| 292 | |
| 293 | ATRACE_CALL(); |
| 294 | |
| 295 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 296 | mTimeStats.totalFramesLegacy++; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Yiwei Zhang | 621f9d4 | 2018-05-07 10:40:55 -0700 | [diff] [blame] | 299 | void TimeStats::incrementMissedFrames() { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 300 | if (!mEnabled.load()) return; |
| 301 | |
| 302 | ATRACE_CALL(); |
| 303 | |
| 304 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 305 | mTimeStats.missedFramesLegacy++; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void TimeStats::incrementClientCompositionFrames() { |
| 309 | if (!mEnabled.load()) return; |
| 310 | |
| 311 | ATRACE_CALL(); |
| 312 | |
| 313 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 314 | mTimeStats.clientCompositionFramesLegacy++; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 317 | void TimeStats::incrementClientCompositionReusedFrames() { |
| 318 | if (!mEnabled.load()) return; |
| 319 | |
| 320 | ATRACE_CALL(); |
| 321 | |
| 322 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 323 | mTimeStats.clientCompositionReusedFramesLegacy++; |
Vishnu Nair | 9b079a2 | 2020-01-21 14:36:08 -0800 | [diff] [blame] | 324 | } |
| 325 | |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 326 | void TimeStats::incrementRefreshRateSwitches() { |
| 327 | if (!mEnabled.load()) return; |
| 328 | |
| 329 | ATRACE_CALL(); |
| 330 | |
| 331 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 332 | mTimeStats.refreshRateSwitchesLegacy++; |
Alec Mouri | 8de697e | 2020-03-19 10:52:01 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 335 | void TimeStats::incrementCompositionStrategyChanges() { |
| 336 | if (!mEnabled.load()) return; |
| 337 | |
| 338 | ATRACE_CALL(); |
| 339 | |
| 340 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 341 | mTimeStats.compositionStrategyChangesLegacy++; |
Alec Mouri | 8f7a010 | 2020-04-15 12:11:10 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 344 | void TimeStats::recordDisplayEventConnectionCount(int32_t count) { |
| 345 | if (!mEnabled.load()) return; |
| 346 | |
| 347 | ATRACE_CALL(); |
| 348 | |
| 349 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 350 | mTimeStats.displayEventConnectionsCountLegacy = |
| 351 | std::max(mTimeStats.displayEventConnectionsCountLegacy, count); |
Alec Mouri | 717bcb6 | 2020-02-10 17:07:19 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 354 | static int32_t msBetween(nsecs_t start, nsecs_t end) { |
| 355 | int64_t delta = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 356 | std::chrono::nanoseconds(end - start)) |
| 357 | .count(); |
| 358 | delta = std::clamp(delta, int64_t(INT32_MIN), int64_t(INT32_MAX)); |
| 359 | return static_cast<int32_t>(delta); |
| 360 | } |
| 361 | |
| 362 | void TimeStats::recordFrameDuration(nsecs_t startTime, nsecs_t endTime) { |
| 363 | if (!mEnabled.load()) return; |
| 364 | |
| 365 | std::lock_guard<std::mutex> lock(mMutex); |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 366 | if (mPowerTime.powerMode == PowerMode::ON) { |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 367 | mTimeStats.frameDurationLegacy.insert(msBetween(startTime, endTime)); |
Alec Mouri | 9519bf1 | 2019-11-15 16:54:44 -0800 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 371 | void TimeStats::recordRenderEngineDuration(nsecs_t startTime, nsecs_t endTime) { |
| 372 | if (!mEnabled.load()) return; |
| 373 | |
| 374 | std::lock_guard<std::mutex> lock(mMutex); |
| 375 | if (mGlobalRecord.renderEngineDurations.size() == MAX_NUM_TIME_RECORDS) { |
| 376 | ALOGE("RenderEngineTimes are already at its maximum size[%zu]", MAX_NUM_TIME_RECORDS); |
| 377 | mGlobalRecord.renderEngineDurations.pop_front(); |
| 378 | } |
| 379 | mGlobalRecord.renderEngineDurations.push_back({startTime, endTime}); |
| 380 | } |
| 381 | |
| 382 | void TimeStats::recordRenderEngineDuration(nsecs_t startTime, |
| 383 | const std::shared_ptr<FenceTime>& endTime) { |
| 384 | if (!mEnabled.load()) return; |
| 385 | |
| 386 | std::lock_guard<std::mutex> lock(mMutex); |
| 387 | if (mGlobalRecord.renderEngineDurations.size() == MAX_NUM_TIME_RECORDS) { |
| 388 | ALOGE("RenderEngineTimes are already at its maximum size[%zu]", MAX_NUM_TIME_RECORDS); |
| 389 | mGlobalRecord.renderEngineDurations.pop_front(); |
| 390 | } |
| 391 | mGlobalRecord.renderEngineDurations.push_back({startTime, endTime}); |
| 392 | } |
| 393 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 394 | bool TimeStats::recordReadyLocked(int32_t layerId, TimeRecord* timeRecord) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 395 | if (!timeRecord->ready) { |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 396 | ALOGV("[%d]-[%" PRIu64 "]-presentFence is still not received", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 397 | timeRecord->frameTime.frameNumber); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 398 | return false; |
| 399 | } |
| 400 | |
| 401 | if (timeRecord->acquireFence != nullptr) { |
| 402 | if (timeRecord->acquireFence->getSignalTime() == Fence::SIGNAL_TIME_PENDING) { |
| 403 | return false; |
| 404 | } |
| 405 | if (timeRecord->acquireFence->getSignalTime() != Fence::SIGNAL_TIME_INVALID) { |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 406 | timeRecord->frameTime.acquireTime = timeRecord->acquireFence->getSignalTime(); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 407 | timeRecord->acquireFence = nullptr; |
| 408 | } else { |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 409 | ALOGV("[%d]-[%" PRIu64 "]-acquireFence signal time is invalid", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 410 | timeRecord->frameTime.frameNumber); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | if (timeRecord->presentFence != nullptr) { |
| 415 | if (timeRecord->presentFence->getSignalTime() == Fence::SIGNAL_TIME_PENDING) { |
| 416 | return false; |
| 417 | } |
| 418 | if (timeRecord->presentFence->getSignalTime() != Fence::SIGNAL_TIME_INVALID) { |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 419 | timeRecord->frameTime.presentTime = timeRecord->presentFence->getSignalTime(); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 420 | timeRecord->presentFence = nullptr; |
| 421 | } else { |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 422 | ALOGV("[%d]-[%" PRIu64 "]-presentFence signal time invalid", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 423 | timeRecord->frameTime.frameNumber); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
| 427 | return true; |
| 428 | } |
| 429 | |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 430 | static int32_t clampToSmallestBucket(Fps fps, size_t bucketWidth) { |
| 431 | return (fps.getIntValue() / bucketWidth) * bucketWidth; |
| 432 | } |
| 433 | |
| 434 | void TimeStats::flushAvailableRecordsToStatsLocked(int32_t layerId, Fps displayRefreshRate, |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 435 | std::optional<Fps> renderRate, |
| 436 | SetFrameRateVote frameRateVote) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 437 | ATRACE_CALL(); |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 438 | ALOGV("[%d]-flushAvailableRecordsToStatsLocked", layerId); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 439 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 440 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 441 | TimeRecord& prevTimeRecord = layerRecord.prevTimeRecord; |
Yiwei Zhang | c5f2c45 | 2018-05-08 16:31:56 -0700 | [diff] [blame] | 442 | std::deque<TimeRecord>& timeRecords = layerRecord.timeRecords; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 443 | const int32_t refreshRateBucket = |
| 444 | clampToSmallestBucket(displayRefreshRate, REFRESH_RATE_BUCKET_WIDTH); |
| 445 | const int32_t renderRateBucket = |
| 446 | clampToSmallestBucket(renderRate ? *renderRate : displayRefreshRate, |
| 447 | RENDER_RATE_BUCKET_WIDTH); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 448 | while (!timeRecords.empty()) { |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 449 | if (!recordReadyLocked(layerId, &timeRecords[0])) break; |
| 450 | ALOGV("[%d]-[%" PRIu64 "]-presentFenceTime[%" PRId64 "]", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 451 | timeRecords[0].frameTime.frameNumber, timeRecords[0].frameTime.presentTime); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 452 | |
| 453 | if (prevTimeRecord.ready) { |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 454 | uid_t uid = layerRecord.uid; |
Yiwei Zhang | eafa5cc | 2019-07-26 15:06:25 -0700 | [diff] [blame] | 455 | const std::string& layerName = layerRecord.layerName; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 456 | TimeStatsHelper::TimelineStatsKey timelineKey = {refreshRateBucket, renderRateBucket}; |
| 457 | if (!mTimeStats.stats.count(timelineKey)) { |
| 458 | mTimeStats.stats[timelineKey].key = timelineKey; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 459 | } |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 460 | |
| 461 | TimeStatsHelper::TimelineStats& displayStats = mTimeStats.stats[timelineKey]; |
| 462 | |
| 463 | TimeStatsHelper::LayerStatsKey layerKey = {uid, layerName}; |
| 464 | if (!displayStats.stats.count(layerKey)) { |
| 465 | displayStats.stats[layerKey].displayRefreshRateBucket = refreshRateBucket; |
| 466 | displayStats.stats[layerKey].renderRateBucket = renderRateBucket; |
| 467 | displayStats.stats[layerKey].uid = uid; |
| 468 | displayStats.stats[layerKey].layerName = layerName; |
| 469 | } |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 470 | if (frameRateVote.frameRate > 0.0f) { |
| 471 | displayStats.stats[layerKey].setFrameRateVote = frameRateVote; |
| 472 | } |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 473 | TimeStatsHelper::TimeStatsLayer& timeStatsLayer = displayStats.stats[layerKey]; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 474 | timeStatsLayer.totalFrames++; |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 475 | timeStatsLayer.droppedFrames += layerRecord.droppedFrames; |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 476 | timeStatsLayer.lateAcquireFrames += layerRecord.lateAcquireFrames; |
| 477 | timeStatsLayer.badDesiredPresentFrames += layerRecord.badDesiredPresentFrames; |
| 478 | |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 479 | layerRecord.droppedFrames = 0; |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 480 | layerRecord.lateAcquireFrames = 0; |
| 481 | layerRecord.badDesiredPresentFrames = 0; |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 482 | |
| 483 | const int32_t postToAcquireMs = msBetween(timeRecords[0].frameTime.postTime, |
| 484 | timeRecords[0].frameTime.acquireTime); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 485 | ALOGV("[%d]-[%" PRIu64 "]-post2acquire[%d]", layerId, |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 486 | timeRecords[0].frameTime.frameNumber, postToAcquireMs); |
| 487 | timeStatsLayer.deltas["post2acquire"].insert(postToAcquireMs); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 488 | |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 489 | const int32_t postToPresentMs = msBetween(timeRecords[0].frameTime.postTime, |
| 490 | timeRecords[0].frameTime.presentTime); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 491 | ALOGV("[%d]-[%" PRIu64 "]-post2present[%d]", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 492 | timeRecords[0].frameTime.frameNumber, postToPresentMs); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 493 | timeStatsLayer.deltas["post2present"].insert(postToPresentMs); |
| 494 | |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 495 | const int32_t acquireToPresentMs = msBetween(timeRecords[0].frameTime.acquireTime, |
| 496 | timeRecords[0].frameTime.presentTime); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 497 | ALOGV("[%d]-[%" PRIu64 "]-acquire2present[%d]", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 498 | timeRecords[0].frameTime.frameNumber, acquireToPresentMs); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 499 | timeStatsLayer.deltas["acquire2present"].insert(acquireToPresentMs); |
| 500 | |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 501 | const int32_t latchToPresentMs = msBetween(timeRecords[0].frameTime.latchTime, |
| 502 | timeRecords[0].frameTime.presentTime); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 503 | ALOGV("[%d]-[%" PRIu64 "]-latch2present[%d]", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 504 | timeRecords[0].frameTime.frameNumber, latchToPresentMs); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 505 | timeStatsLayer.deltas["latch2present"].insert(latchToPresentMs); |
| 506 | |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 507 | const int32_t desiredToPresentMs = msBetween(timeRecords[0].frameTime.desiredTime, |
| 508 | timeRecords[0].frameTime.presentTime); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 509 | ALOGV("[%d]-[%" PRIu64 "]-desired2present[%d]", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 510 | timeRecords[0].frameTime.frameNumber, desiredToPresentMs); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 511 | timeStatsLayer.deltas["desired2present"].insert(desiredToPresentMs); |
| 512 | |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 513 | const int32_t presentToPresentMs = msBetween(prevTimeRecord.frameTime.presentTime, |
| 514 | timeRecords[0].frameTime.presentTime); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 515 | ALOGV("[%d]-[%" PRIu64 "]-present2present[%d]", layerId, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 516 | timeRecords[0].frameTime.frameNumber, presentToPresentMs); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 517 | timeStatsLayer.deltas["present2present"].insert(presentToPresentMs); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 518 | } |
| 519 | prevTimeRecord = timeRecords[0]; |
Yiwei Zhang | c5f2c45 | 2018-05-08 16:31:56 -0700 | [diff] [blame] | 520 | timeRecords.pop_front(); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 521 | layerRecord.waitData--; |
| 522 | } |
| 523 | } |
| 524 | |
Yiwei Zhang | 8bec7e8 | 2019-10-07 18:08:26 -0700 | [diff] [blame] | 525 | static constexpr const char* kPopupWindowPrefix = "PopupWindow"; |
| 526 | static const size_t kMinLenLayerName = std::strlen(kPopupWindowPrefix); |
Yiwei Zhang | bd40832 | 2018-10-15 18:31:53 -0700 | [diff] [blame] | 527 | |
Yiwei Zhang | 8bec7e8 | 2019-10-07 18:08:26 -0700 | [diff] [blame] | 528 | // Avoid tracking the "PopupWindow:<random hash>#<number>" layers |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 529 | static bool layerNameIsValid(const std::string& layerName) { |
Yiwei Zhang | 8bec7e8 | 2019-10-07 18:08:26 -0700 | [diff] [blame] | 530 | return layerName.length() >= kMinLenLayerName && |
| 531 | layerName.compare(0, kMinLenLayerName, kPopupWindowPrefix) != 0; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 534 | bool TimeStats::canAddNewAggregatedStats(uid_t uid, const std::string& layerName) { |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 535 | uint32_t layerRecords = 0; |
| 536 | for (const auto& record : mTimeStats.stats) { |
| 537 | if (record.second.stats.count({uid, layerName}) > 0) { |
| 538 | return true; |
| 539 | } |
| 540 | |
| 541 | layerRecords += record.second.stats.size(); |
| 542 | } |
| 543 | |
| 544 | return mTimeStats.stats.size() < MAX_NUM_LAYER_STATS; |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 547 | void TimeStats::setPostTime(int32_t layerId, uint64_t frameNumber, const std::string& layerName, |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 548 | uid_t uid, nsecs_t postTime) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 549 | if (!mEnabled.load()) return; |
| 550 | |
| 551 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 552 | ALOGV("[%d]-[%" PRIu64 "]-[%s]-PostTime[%" PRId64 "]", layerId, frameNumber, layerName.c_str(), |
Yiwei Zhang | 8e8fe52 | 2018-11-02 18:34:07 -0700 | [diff] [blame] | 553 | postTime); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 554 | |
| 555 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 556 | if (!canAddNewAggregatedStats(uid, layerName)) { |
Yiwei Zhang | e926ab5 | 2019-08-14 15:16:00 -0700 | [diff] [blame] | 557 | return; |
| 558 | } |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 559 | if (!mTimeStatsTracker.count(layerId) && mTimeStatsTracker.size() < MAX_NUM_LAYER_RECORDS && |
Yiwei Zhang | 7eb58b7 | 2019-04-22 19:00:02 -0700 | [diff] [blame] | 560 | layerNameIsValid(layerName)) { |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 561 | mTimeStatsTracker[layerId].uid = uid; |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 562 | mTimeStatsTracker[layerId].layerName = layerName; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 563 | } |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 564 | if (!mTimeStatsTracker.count(layerId)) return; |
| 565 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 566 | if (layerRecord.timeRecords.size() == MAX_NUM_TIME_RECORDS) { |
Yiwei Zhang | af8ee94 | 2018-11-22 00:15:23 -0800 | [diff] [blame] | 567 | ALOGE("[%d]-[%s]-timeRecords is at its maximum size[%zu]. Ignore this when unittesting.", |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 568 | layerId, layerRecord.layerName.c_str(), MAX_NUM_TIME_RECORDS); |
| 569 | mTimeStatsTracker.erase(layerId); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 570 | return; |
| 571 | } |
| 572 | // For most media content, the acquireFence is invalid because the buffer is |
| 573 | // ready at the queueBuffer stage. In this case, acquireTime should be given |
| 574 | // a default value as postTime. |
| 575 | TimeRecord timeRecord = { |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 576 | .frameTime = |
| 577 | { |
| 578 | .frameNumber = frameNumber, |
| 579 | .postTime = postTime, |
Yiwei Zhang | af8ee94 | 2018-11-22 00:15:23 -0800 | [diff] [blame] | 580 | .latchTime = postTime, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 581 | .acquireTime = postTime, |
Yiwei Zhang | af8ee94 | 2018-11-22 00:15:23 -0800 | [diff] [blame] | 582 | .desiredTime = postTime, |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 583 | }, |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 584 | }; |
| 585 | layerRecord.timeRecords.push_back(timeRecord); |
| 586 | if (layerRecord.waitData < 0 || |
| 587 | layerRecord.waitData >= static_cast<int32_t>(layerRecord.timeRecords.size())) |
| 588 | layerRecord.waitData = layerRecord.timeRecords.size() - 1; |
| 589 | } |
| 590 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 591 | void TimeStats::setLatchTime(int32_t layerId, uint64_t frameNumber, nsecs_t latchTime) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 592 | if (!mEnabled.load()) return; |
| 593 | |
| 594 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 595 | ALOGV("[%d]-[%" PRIu64 "]-LatchTime[%" PRId64 "]", layerId, frameNumber, latchTime); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 596 | |
| 597 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 598 | if (!mTimeStatsTracker.count(layerId)) return; |
| 599 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | cb7dd00 | 2019-04-16 11:03:01 -0700 | [diff] [blame] | 600 | if (layerRecord.waitData < 0 || |
| 601 | layerRecord.waitData >= static_cast<int32_t>(layerRecord.timeRecords.size())) |
| 602 | return; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 603 | TimeRecord& timeRecord = layerRecord.timeRecords[layerRecord.waitData]; |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 604 | if (timeRecord.frameTime.frameNumber == frameNumber) { |
| 605 | timeRecord.frameTime.latchTime = latchTime; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
Alec Mouri | 91f6df3 | 2020-01-30 08:48:58 -0800 | [diff] [blame] | 609 | void TimeStats::incrementLatchSkipped(int32_t layerId, LatchSkipReason reason) { |
| 610 | if (!mEnabled.load()) return; |
| 611 | |
| 612 | ATRACE_CALL(); |
| 613 | ALOGV("[%d]-LatchSkipped-Reason[%d]", layerId, |
| 614 | static_cast<std::underlying_type<LatchSkipReason>::type>(reason)); |
| 615 | |
| 616 | std::lock_guard<std::mutex> lock(mMutex); |
| 617 | if (!mTimeStatsTracker.count(layerId)) return; |
| 618 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
| 619 | |
| 620 | switch (reason) { |
| 621 | case LatchSkipReason::LateAcquire: |
| 622 | layerRecord.lateAcquireFrames++; |
| 623 | break; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | void TimeStats::incrementBadDesiredPresent(int32_t layerId) { |
| 628 | if (!mEnabled.load()) return; |
| 629 | |
| 630 | ATRACE_CALL(); |
| 631 | ALOGV("[%d]-BadDesiredPresent", layerId); |
| 632 | |
| 633 | std::lock_guard<std::mutex> lock(mMutex); |
| 634 | if (!mTimeStatsTracker.count(layerId)) return; |
| 635 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
| 636 | layerRecord.badDesiredPresentFrames++; |
| 637 | } |
| 638 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 639 | void TimeStats::setDesiredTime(int32_t layerId, uint64_t frameNumber, nsecs_t desiredTime) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 640 | if (!mEnabled.load()) return; |
| 641 | |
| 642 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 643 | ALOGV("[%d]-[%" PRIu64 "]-DesiredTime[%" PRId64 "]", layerId, frameNumber, desiredTime); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 644 | |
| 645 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 646 | if (!mTimeStatsTracker.count(layerId)) return; |
| 647 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | cb7dd00 | 2019-04-16 11:03:01 -0700 | [diff] [blame] | 648 | if (layerRecord.waitData < 0 || |
| 649 | layerRecord.waitData >= static_cast<int32_t>(layerRecord.timeRecords.size())) |
| 650 | return; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 651 | TimeRecord& timeRecord = layerRecord.timeRecords[layerRecord.waitData]; |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 652 | if (timeRecord.frameTime.frameNumber == frameNumber) { |
| 653 | timeRecord.frameTime.desiredTime = desiredTime; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 657 | void TimeStats::setAcquireTime(int32_t layerId, uint64_t frameNumber, nsecs_t acquireTime) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 658 | if (!mEnabled.load()) return; |
| 659 | |
| 660 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 661 | ALOGV("[%d]-[%" PRIu64 "]-AcquireTime[%" PRId64 "]", layerId, frameNumber, acquireTime); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 662 | |
| 663 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 664 | if (!mTimeStatsTracker.count(layerId)) return; |
| 665 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | cb7dd00 | 2019-04-16 11:03:01 -0700 | [diff] [blame] | 666 | if (layerRecord.waitData < 0 || |
| 667 | layerRecord.waitData >= static_cast<int32_t>(layerRecord.timeRecords.size())) |
| 668 | return; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 669 | TimeRecord& timeRecord = layerRecord.timeRecords[layerRecord.waitData]; |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 670 | if (timeRecord.frameTime.frameNumber == frameNumber) { |
| 671 | timeRecord.frameTime.acquireTime = acquireTime; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 675 | void TimeStats::setAcquireFence(int32_t layerId, uint64_t frameNumber, |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 676 | const std::shared_ptr<FenceTime>& acquireFence) { |
| 677 | if (!mEnabled.load()) return; |
| 678 | |
| 679 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 680 | ALOGV("[%d]-[%" PRIu64 "]-AcquireFenceTime[%" PRId64 "]", layerId, frameNumber, |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 681 | acquireFence->getSignalTime()); |
| 682 | |
| 683 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 684 | if (!mTimeStatsTracker.count(layerId)) return; |
| 685 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | cb7dd00 | 2019-04-16 11:03:01 -0700 | [diff] [blame] | 686 | if (layerRecord.waitData < 0 || |
| 687 | layerRecord.waitData >= static_cast<int32_t>(layerRecord.timeRecords.size())) |
| 688 | return; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 689 | TimeRecord& timeRecord = layerRecord.timeRecords[layerRecord.waitData]; |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 690 | if (timeRecord.frameTime.frameNumber == frameNumber) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 691 | timeRecord.acquireFence = acquireFence; |
| 692 | } |
| 693 | } |
| 694 | |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 695 | void TimeStats::setPresentTime(int32_t layerId, uint64_t frameNumber, nsecs_t presentTime, |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 696 | Fps displayRefreshRate, std::optional<Fps> renderRate, |
| 697 | SetFrameRateVote frameRateVote) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 698 | if (!mEnabled.load()) return; |
| 699 | |
| 700 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 701 | ALOGV("[%d]-[%" PRIu64 "]-PresentTime[%" PRId64 "]", layerId, frameNumber, presentTime); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 702 | |
| 703 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 704 | if (!mTimeStatsTracker.count(layerId)) return; |
| 705 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | cb7dd00 | 2019-04-16 11:03:01 -0700 | [diff] [blame] | 706 | if (layerRecord.waitData < 0 || |
| 707 | layerRecord.waitData >= static_cast<int32_t>(layerRecord.timeRecords.size())) |
| 708 | return; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 709 | TimeRecord& timeRecord = layerRecord.timeRecords[layerRecord.waitData]; |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 710 | if (timeRecord.frameTime.frameNumber == frameNumber) { |
| 711 | timeRecord.frameTime.presentTime = presentTime; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 712 | timeRecord.ready = true; |
| 713 | layerRecord.waitData++; |
| 714 | } |
| 715 | |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 716 | flushAvailableRecordsToStatsLocked(layerId, displayRefreshRate, renderRate, frameRateVote); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 717 | } |
| 718 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 719 | void TimeStats::setPresentFence(int32_t layerId, uint64_t frameNumber, |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 720 | const std::shared_ptr<FenceTime>& presentFence, |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 721 | Fps displayRefreshRate, std::optional<Fps> renderRate, |
| 722 | SetFrameRateVote frameRateVote) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 723 | if (!mEnabled.load()) return; |
| 724 | |
| 725 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 726 | ALOGV("[%d]-[%" PRIu64 "]-PresentFenceTime[%" PRId64 "]", layerId, frameNumber, |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 727 | presentFence->getSignalTime()); |
| 728 | |
| 729 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 730 | if (!mTimeStatsTracker.count(layerId)) return; |
| 731 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | cb7dd00 | 2019-04-16 11:03:01 -0700 | [diff] [blame] | 732 | if (layerRecord.waitData < 0 || |
| 733 | layerRecord.waitData >= static_cast<int32_t>(layerRecord.timeRecords.size())) |
| 734 | return; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 735 | TimeRecord& timeRecord = layerRecord.timeRecords[layerRecord.waitData]; |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 736 | if (timeRecord.frameTime.frameNumber == frameNumber) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 737 | timeRecord.presentFence = presentFence; |
| 738 | timeRecord.ready = true; |
| 739 | layerRecord.waitData++; |
| 740 | } |
| 741 | |
Ady Abraham | 8b9e612 | 2021-01-26 19:11:45 -0800 | [diff] [blame] | 742 | flushAvailableRecordsToStatsLocked(layerId, displayRefreshRate, renderRate, frameRateVote); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Adithya Srinivasan | ead1716 | 2021-02-18 02:17:37 +0000 | [diff] [blame] | 745 | static const constexpr int32_t kValidJankyReason = JankType::DisplayHAL | |
| 746 | JankType::SurfaceFlingerCpuDeadlineMissed | JankType::SurfaceFlingerGpuDeadlineMissed | |
| 747 | JankType::AppDeadlineMissed | JankType::PredictionError | |
| 748 | JankType::SurfaceFlingerScheduling | JankType::BufferStuffing; |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 749 | |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 750 | template <class T> |
| 751 | static void updateJankPayload(T& t, int32_t reasons) { |
| 752 | t.jankPayload.totalFrames++; |
| 753 | |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 754 | if (reasons & kValidJankyReason) { |
| 755 | t.jankPayload.totalJankyFrames++; |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 756 | if ((reasons & JankType::SurfaceFlingerCpuDeadlineMissed) != 0) { |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 757 | t.jankPayload.totalSFLongCpu++; |
| 758 | } |
Jorim Jaggi | 5814ab8 | 2020-12-03 20:45:58 +0100 | [diff] [blame] | 759 | if ((reasons & JankType::SurfaceFlingerGpuDeadlineMissed) != 0) { |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 760 | t.jankPayload.totalSFLongGpu++; |
| 761 | } |
Adithya Srinivasan | 9b2ca3e | 2020-11-10 10:14:17 -0800 | [diff] [blame] | 762 | if ((reasons & JankType::DisplayHAL) != 0) { |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 763 | t.jankPayload.totalSFUnattributed++; |
| 764 | } |
Jorim Jaggi | 5814ab8 | 2020-12-03 20:45:58 +0100 | [diff] [blame] | 765 | if ((reasons & JankType::AppDeadlineMissed) != 0) { |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 766 | t.jankPayload.totalAppUnattributed++; |
| 767 | } |
Adithya Srinivasan | ead1716 | 2021-02-18 02:17:37 +0000 | [diff] [blame] | 768 | if ((reasons & JankType::PredictionError) != 0) { |
| 769 | t.jankPayload.totalSFPredictionError++; |
| 770 | } |
| 771 | if ((reasons & JankType::SurfaceFlingerScheduling) != 0) { |
| 772 | t.jankPayload.totalSFScheduling++; |
| 773 | } |
| 774 | if ((reasons & JankType::BufferStuffing) != 0) { |
| 775 | t.jankPayload.totalAppBufferStuffing++; |
| 776 | } |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 780 | void TimeStats::incrementJankyFrames(const JankyFramesInfo& info) { |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 781 | if (!mEnabled.load()) return; |
| 782 | |
| 783 | ATRACE_CALL(); |
| 784 | std::lock_guard<std::mutex> lock(mMutex); |
| 785 | |
Alec Mouri | 542de11 | 2020-11-13 12:07:32 -0800 | [diff] [blame] | 786 | // Only update layer stats if we're already tracking the layer in TimeStats. |
| 787 | // Otherwise, continue tracking the statistic but use a default layer name instead. |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 788 | // As an implementation detail, we do this because this method is expected to be |
Alec Mouri | 542de11 | 2020-11-13 12:07:32 -0800 | [diff] [blame] | 789 | // called from FrameTimeline, whose jank classification includes transaction jank |
| 790 | // that occurs without a buffer. But, in general those layer names are not suitable as |
| 791 | // aggregation keys: e.g., it's normal and expected for Window Manager to include the hash code |
| 792 | // for an animation leash. So while we can show that jank in dumpsys, aggregating based on the |
| 793 | // layer blows up the stats size, so as a workaround drop those stats. This assumes that |
| 794 | // TimeStats will flush the first present fence for a layer *before* FrameTimeline does so that |
| 795 | // the first jank record is not dropped. |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 796 | |
Alec Mouri | 542de11 | 2020-11-13 12:07:32 -0800 | [diff] [blame] | 797 | static const std::string kDefaultLayerName = "none"; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 798 | |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 799 | const int32_t refreshRateBucket = |
| 800 | clampToSmallestBucket(info.refreshRate, REFRESH_RATE_BUCKET_WIDTH); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 801 | const int32_t renderRateBucket = |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 802 | clampToSmallestBucket(info.renderRate ? *info.renderRate : info.refreshRate, |
| 803 | RENDER_RATE_BUCKET_WIDTH); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 804 | const TimeStatsHelper::TimelineStatsKey timelineKey = {refreshRateBucket, renderRateBucket}; |
| 805 | |
| 806 | if (!mTimeStats.stats.count(timelineKey)) { |
| 807 | mTimeStats.stats[timelineKey].key = timelineKey; |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 808 | } |
| 809 | |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 810 | TimeStatsHelper::TimelineStats& timelineStats = mTimeStats.stats[timelineKey]; |
| 811 | |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 812 | updateJankPayload<TimeStatsHelper::TimelineStats>(timelineStats, info.reasons); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 813 | |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 814 | TimeStatsHelper::LayerStatsKey layerKey = {info.uid, info.layerName}; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 815 | if (!timelineStats.stats.count(layerKey)) { |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 816 | layerKey = {info.uid, kDefaultLayerName}; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 817 | timelineStats.stats[layerKey].displayRefreshRateBucket = refreshRateBucket; |
| 818 | timelineStats.stats[layerKey].renderRateBucket = renderRateBucket; |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 819 | timelineStats.stats[layerKey].uid = info.uid; |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 820 | timelineStats.stats[layerKey].layerName = kDefaultLayerName; |
| 821 | } |
| 822 | |
| 823 | TimeStatsHelper::TimeStatsLayer& timeStatsLayer = timelineStats.stats[layerKey]; |
Alec Mouri | 363faf0 | 2021-01-29 16:34:55 -0800 | [diff] [blame] | 824 | updateJankPayload<TimeStatsHelper::TimeStatsLayer>(timeStatsLayer, info.reasons); |
| 825 | |
| 826 | if (info.reasons & kValidJankyReason) { |
| 827 | // TimeStats Histograms only retain positive values, so we don't need to check if these |
| 828 | // deadlines were really missed if we know that the frame had jank, since deadlines |
| 829 | // that were met will be dropped. |
| 830 | timelineStats.displayDeadlineDeltas.insert(static_cast<int32_t>(info.displayDeadlineDelta)); |
| 831 | timelineStats.displayPresentDeltas.insert(static_cast<int32_t>(info.displayPresentJitter)); |
| 832 | timeStatsLayer.deltas["appDeadlineDeltas"].insert( |
| 833 | static_cast<int32_t>(info.appDeadlineDelta)); |
| 834 | } |
Alec Mouri | 9a29e67 | 2020-09-14 12:39:14 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 837 | void TimeStats::onDestroy(int32_t layerId) { |
Yiwei Zhang | dc22404 | 2018-10-18 15:34:00 -0700 | [diff] [blame] | 838 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 839 | ALOGV("[%d]-onDestroy", layerId); |
Mikael Pessa | 90092f4 | 2019-08-26 17:22:04 -0700 | [diff] [blame] | 840 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 841 | mTimeStatsTracker.erase(layerId); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 844 | void TimeStats::removeTimeRecord(int32_t layerId, uint64_t frameNumber) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 845 | if (!mEnabled.load()) return; |
| 846 | |
| 847 | ATRACE_CALL(); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 848 | ALOGV("[%d]-[%" PRIu64 "]-removeTimeRecord", layerId, frameNumber); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 849 | |
| 850 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 1a88c40 | 2019-11-18 10:43:58 -0800 | [diff] [blame] | 851 | if (!mTimeStatsTracker.count(layerId)) return; |
| 852 | LayerRecord& layerRecord = mTimeStatsTracker[layerId]; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 853 | size_t removeAt = 0; |
| 854 | for (const TimeRecord& record : layerRecord.timeRecords) { |
Yiwei Zhang | cf50ab9 | 2018-06-14 10:50:12 -0700 | [diff] [blame] | 855 | if (record.frameTime.frameNumber == frameNumber) break; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 856 | removeAt++; |
| 857 | } |
| 858 | if (removeAt == layerRecord.timeRecords.size()) return; |
| 859 | layerRecord.timeRecords.erase(layerRecord.timeRecords.begin() + removeAt); |
| 860 | if (layerRecord.waitData > static_cast<int32_t>(removeAt)) { |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 861 | layerRecord.waitData--; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 862 | } |
Yiwei Zhang | eaeea06 | 2018-06-28 14:46:51 -0700 | [diff] [blame] | 863 | layerRecord.droppedFrames++; |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 866 | void TimeStats::flushPowerTimeLocked() { |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 867 | if (!mEnabled.load()) return; |
| 868 | |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 869 | nsecs_t curTime = systemTime(); |
| 870 | // elapsedTime is in milliseconds. |
| 871 | int64_t elapsedTime = (curTime - mPowerTime.prevTime) / 1000000; |
| 872 | |
| 873 | switch (mPowerTime.powerMode) { |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 874 | case PowerMode::ON: |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 875 | mTimeStats.displayOnTimeLegacy += elapsedTime; |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 876 | break; |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 877 | case PowerMode::OFF: |
| 878 | case PowerMode::DOZE: |
| 879 | case PowerMode::DOZE_SUSPEND: |
| 880 | case PowerMode::ON_SUSPEND: |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 881 | default: |
| 882 | break; |
| 883 | } |
| 884 | |
| 885 | mPowerTime.prevTime = curTime; |
| 886 | } |
| 887 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 888 | void TimeStats::setPowerMode(PowerMode powerMode) { |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 889 | if (!mEnabled.load()) { |
| 890 | std::lock_guard<std::mutex> lock(mMutex); |
| 891 | mPowerTime.powerMode = powerMode; |
| 892 | return; |
| 893 | } |
| 894 | |
| 895 | std::lock_guard<std::mutex> lock(mMutex); |
| 896 | if (powerMode == mPowerTime.powerMode) return; |
| 897 | |
| 898 | flushPowerTimeLocked(); |
| 899 | mPowerTime.powerMode = powerMode; |
| 900 | } |
| 901 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 902 | void TimeStats::recordRefreshRate(uint32_t fps, nsecs_t duration) { |
| 903 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 904 | if (mTimeStats.refreshRateStatsLegacy.count(fps)) { |
| 905 | mTimeStats.refreshRateStatsLegacy[fps] += duration; |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 906 | } else { |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 907 | mTimeStats.refreshRateStatsLegacy.insert({fps, duration}); |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 911 | void TimeStats::flushAvailableGlobalRecordsToStatsLocked() { |
| 912 | ATRACE_CALL(); |
| 913 | |
| 914 | while (!mGlobalRecord.presentFences.empty()) { |
| 915 | const nsecs_t curPresentTime = mGlobalRecord.presentFences.front()->getSignalTime(); |
| 916 | if (curPresentTime == Fence::SIGNAL_TIME_PENDING) break; |
| 917 | |
| 918 | if (curPresentTime == Fence::SIGNAL_TIME_INVALID) { |
| 919 | ALOGE("GlobalPresentFence is invalid!"); |
| 920 | mGlobalRecord.prevPresentTime = 0; |
| 921 | mGlobalRecord.presentFences.pop_front(); |
| 922 | continue; |
| 923 | } |
| 924 | |
| 925 | ALOGV("GlobalPresentFenceTime[%" PRId64 "]", |
| 926 | mGlobalRecord.presentFences.front()->getSignalTime()); |
| 927 | |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 928 | if (mGlobalRecord.prevPresentTime != 0) { |
| 929 | const int32_t presentToPresentMs = |
| 930 | msBetween(mGlobalRecord.prevPresentTime, curPresentTime); |
| 931 | ALOGV("Global present2present[%d] prev[%" PRId64 "] curr[%" PRId64 "]", |
| 932 | presentToPresentMs, mGlobalRecord.prevPresentTime, curPresentTime); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 933 | mTimeStats.presentToPresentLegacy.insert(presentToPresentMs); |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 934 | } |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 935 | |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 936 | mGlobalRecord.prevPresentTime = curPresentTime; |
| 937 | mGlobalRecord.presentFences.pop_front(); |
| 938 | } |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 939 | while (!mGlobalRecord.renderEngineDurations.empty()) { |
| 940 | const auto duration = mGlobalRecord.renderEngineDurations.front(); |
| 941 | const auto& endTime = duration.endTime; |
| 942 | |
| 943 | nsecs_t endNs = -1; |
| 944 | |
| 945 | if (auto val = std::get_if<nsecs_t>(&endTime)) { |
| 946 | endNs = *val; |
| 947 | } else { |
| 948 | endNs = std::get<std::shared_ptr<FenceTime>>(endTime)->getSignalTime(); |
| 949 | } |
| 950 | |
| 951 | if (endNs == Fence::SIGNAL_TIME_PENDING) break; |
| 952 | |
| 953 | if (endNs < 0) { |
| 954 | ALOGE("RenderEngineTiming is invalid!"); |
| 955 | mGlobalRecord.renderEngineDurations.pop_front(); |
| 956 | continue; |
| 957 | } |
| 958 | |
| 959 | const int32_t renderEngineMs = msBetween(duration.startTime, endNs); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 960 | mTimeStats.renderEngineTimingLegacy.insert(renderEngineMs); |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 961 | |
| 962 | mGlobalRecord.renderEngineDurations.pop_front(); |
| 963 | } |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | void TimeStats::setPresentFenceGlobal(const std::shared_ptr<FenceTime>& presentFence) { |
| 967 | if (!mEnabled.load()) return; |
| 968 | |
| 969 | ATRACE_CALL(); |
| 970 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 971 | if (presentFence == nullptr || !presentFence->isValid()) { |
| 972 | mGlobalRecord.prevPresentTime = 0; |
| 973 | return; |
| 974 | } |
| 975 | |
Peiyong Lin | 65248e0 | 2020-04-18 21:15:07 -0700 | [diff] [blame] | 976 | if (mPowerTime.powerMode != PowerMode::ON) { |
| 977 | // Try flushing the last present fence on PowerMode::ON. |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 978 | flushAvailableGlobalRecordsToStatsLocked(); |
| 979 | mGlobalRecord.presentFences.clear(); |
Yiwei Zhang | ce6ebc0 | 2018-10-20 12:42:38 -0700 | [diff] [blame] | 980 | mGlobalRecord.prevPresentTime = 0; |
| 981 | return; |
| 982 | } |
| 983 | |
| 984 | if (mGlobalRecord.presentFences.size() == MAX_NUM_TIME_RECORDS) { |
| 985 | // The front presentFence must be trapped in pending status in this |
| 986 | // case. Try dequeuing the front one to recover. |
| 987 | ALOGE("GlobalPresentFences is already at its maximum size[%zu]", MAX_NUM_TIME_RECORDS); |
| 988 | mGlobalRecord.prevPresentTime = 0; |
| 989 | mGlobalRecord.presentFences.pop_front(); |
| 990 | } |
| 991 | |
| 992 | mGlobalRecord.presentFences.emplace_back(presentFence); |
| 993 | flushAvailableGlobalRecordsToStatsLocked(); |
| 994 | } |
| 995 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 996 | void TimeStats::enable() { |
| 997 | if (mEnabled.load()) return; |
| 998 | |
| 999 | ATRACE_CALL(); |
| 1000 | |
| 1001 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1002 | mEnabled.store(true); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1003 | mTimeStats.statsStartLegacy = static_cast<int64_t>(std::time(0)); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 1004 | mPowerTime.prevTime = systemTime(); |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 1005 | ALOGD("Enabled"); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | void TimeStats::disable() { |
| 1009 | if (!mEnabled.load()) return; |
| 1010 | |
| 1011 | ATRACE_CALL(); |
| 1012 | |
| 1013 | std::lock_guard<std::mutex> lock(mMutex); |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 1014 | flushPowerTimeLocked(); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1015 | mEnabled.store(false); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1016 | mTimeStats.statsEndLegacy = static_cast<int64_t>(std::time(0)); |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 1017 | ALOGD("Disabled"); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 1020 | void TimeStats::clearAll() { |
| 1021 | std::lock_guard<std::mutex> lock(mMutex); |
| 1022 | clearGlobalLocked(); |
| 1023 | clearLayersLocked(); |
| 1024 | } |
| 1025 | |
| 1026 | void TimeStats::clearGlobalLocked() { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1027 | ATRACE_CALL(); |
| 1028 | |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1029 | mTimeStats.statsStartLegacy = (mEnabled.load() ? static_cast<int64_t>(std::time(0)) : 0); |
| 1030 | mTimeStats.statsEndLegacy = 0; |
| 1031 | mTimeStats.totalFramesLegacy = 0; |
| 1032 | mTimeStats.missedFramesLegacy = 0; |
| 1033 | mTimeStats.clientCompositionFramesLegacy = 0; |
| 1034 | mTimeStats.clientCompositionReusedFramesLegacy = 0; |
| 1035 | mTimeStats.refreshRateSwitchesLegacy = 0; |
| 1036 | mTimeStats.compositionStrategyChangesLegacy = 0; |
| 1037 | mTimeStats.displayEventConnectionsCountLegacy = 0; |
| 1038 | mTimeStats.displayOnTimeLegacy = 0; |
| 1039 | mTimeStats.presentToPresentLegacy.hist.clear(); |
| 1040 | mTimeStats.frameDurationLegacy.hist.clear(); |
| 1041 | mTimeStats.renderEngineTimingLegacy.hist.clear(); |
| 1042 | mTimeStats.refreshRateStatsLegacy.clear(); |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 1043 | mPowerTime.prevTime = systemTime(); |
Alec Mouri | 56e6385 | 2021-03-09 18:17:25 -0800 | [diff] [blame] | 1044 | for (auto& globalRecord : mTimeStats.stats) { |
| 1045 | globalRecord.second.clearGlobals(); |
| 1046 | } |
Yiwei Zhang | e5c49d5 | 2018-10-29 00:15:31 -0700 | [diff] [blame] | 1047 | mGlobalRecord.prevPresentTime = 0; |
| 1048 | mGlobalRecord.presentFences.clear(); |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 1049 | ALOGD("Cleared global stats"); |
| 1050 | } |
| 1051 | |
| 1052 | void TimeStats::clearLayersLocked() { |
| 1053 | ATRACE_CALL(); |
| 1054 | |
| 1055 | mTimeStatsTracker.clear(); |
Alec Mouri | 56e6385 | 2021-03-09 18:17:25 -0800 | [diff] [blame] | 1056 | |
| 1057 | for (auto& globalRecord : mTimeStats.stats) { |
| 1058 | globalRecord.second.stats.clear(); |
| 1059 | } |
Alec Mouri | 8e2f31b | 2020-01-16 22:04:35 +0000 | [diff] [blame] | 1060 | ALOGD("Cleared layer stats"); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | bool TimeStats::isEnabled() { |
| 1064 | return mEnabled.load(); |
| 1065 | } |
| 1066 | |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1067 | void TimeStats::dump(bool asProto, std::optional<uint32_t> maxLayers, std::string& result) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1068 | ATRACE_CALL(); |
| 1069 | |
| 1070 | std::lock_guard<std::mutex> lock(mMutex); |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1071 | if (mTimeStats.statsStartLegacy == 0) { |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1072 | return; |
| 1073 | } |
| 1074 | |
Alec Mouri | 7d436ec | 2021-01-27 20:40:50 -0800 | [diff] [blame] | 1075 | mTimeStats.statsEndLegacy = static_cast<int64_t>(std::time(0)); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1076 | |
Yiwei Zhang | 3a226d2 | 2018-10-16 09:23:03 -0700 | [diff] [blame] | 1077 | flushPowerTimeLocked(); |
| 1078 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1079 | if (asProto) { |
Yiwei Zhang | 8a4015c | 2018-05-08 16:03:47 -0700 | [diff] [blame] | 1080 | ALOGD("Dumping TimeStats as proto"); |
Yiwei Zhang | dc22404 | 2018-10-18 15:34:00 -0700 | [diff] [blame] | 1081 | SFTimeStatsGlobalProto timeStatsProto = mTimeStats.toProto(maxLayers); |
Dominik Laskowski | 4647011 | 2019-08-02 13:13:11 -0700 | [diff] [blame] | 1082 | result.append(timeStatsProto.SerializeAsString()); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1083 | } else { |
Yiwei Zhang | 8a4015c | 2018-05-08 16:03:47 -0700 | [diff] [blame] | 1084 | ALOGD("Dumping TimeStats as text"); |
Yiwei Zhang | 5434a78 | 2018-12-05 18:06:32 -0800 | [diff] [blame] | 1085 | result.append(mTimeStats.toString(maxLayers)); |
Yiwei Zhang | 8a4015c | 2018-05-08 16:03:47 -0700 | [diff] [blame] | 1086 | result.append("\n"); |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1087 | } |
| 1088 | } |
| 1089 | |
Alec Mouri | fb571ea | 2019-01-24 18:42:10 -0800 | [diff] [blame] | 1090 | } // namespace impl |
| 1091 | |
Yiwei Zhang | 0102ad2 | 2018-05-02 17:37:17 -0700 | [diff] [blame] | 1092 | } // namespace android |