| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2015 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 |  */ | 
| Mark Salyzyn | 96bf598 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 16 |  | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 17 | #include "JankTracker.h" | 
 | 18 |  | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 19 | #include <errno.h> | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 20 | #include <inttypes.h> | 
| Mark Salyzyn | 96bf598 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 21 | #include <sys/mman.h> | 
| Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 22 |  | 
 | 23 | #include <algorithm> | 
| John Reck | 5ed587f | 2016-03-24 15:57:01 -0700 | [diff] [blame] | 24 | #include <cmath> | 
| Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 25 | #include <cstdio> | 
 | 26 | #include <limits> | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 27 |  | 
| Mark Salyzyn | 52eb4e0 | 2016-09-28 16:15:30 -0700 | [diff] [blame] | 28 | #include <cutils/ashmem.h> | 
 | 29 | #include <log/log.h> | 
 | 30 |  | 
 | 31 | #include "Properties.h" | 
 | 32 | #include "utils/TimeUtils.h" | 
 | 33 |  | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 34 | namespace android { | 
 | 35 | namespace uirenderer { | 
 | 36 |  | 
 | 37 | static const char* JANK_TYPE_NAMES[] = { | 
 | 38 |         "Missed Vsync", | 
 | 39 |         "High input latency", | 
 | 40 |         "Slow UI thread", | 
 | 41 |         "Slow bitmap uploads", | 
| John Reck | be3fba0 | 2015-07-06 13:49:58 -0700 | [diff] [blame] | 42 |         "Slow issue draw commands", | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 43 | }; | 
 | 44 |  | 
 | 45 | struct Comparison { | 
| John Reck | c87be99 | 2015-02-20 10:57:22 -0800 | [diff] [blame] | 46 |     FrameInfoIndex start; | 
 | 47 |     FrameInfoIndex end; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 48 | }; | 
 | 49 |  | 
 | 50 | static const Comparison COMPARISONS[] = { | 
| Chris Craik | 1b54fb2 | 2015-06-02 17:40:58 -0700 | [diff] [blame] | 51 |         {FrameInfoIndex::IntendedVsync, FrameInfoIndex::Vsync}, | 
 | 52 |         {FrameInfoIndex::OldestInputEvent, FrameInfoIndex::Vsync}, | 
 | 53 |         {FrameInfoIndex::Vsync, FrameInfoIndex::SyncStart}, | 
 | 54 |         {FrameInfoIndex::SyncStart, FrameInfoIndex::IssueDrawCommandsStart}, | 
 | 55 |         {FrameInfoIndex::IssueDrawCommandsStart, FrameInfoIndex::FrameCompleted}, | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 56 | }; | 
 | 57 |  | 
 | 58 | // If the event exceeds 10 seconds throw it away, this isn't a jank event | 
 | 59 | // it's an ANR and will be handled as such | 
 | 60 | static const int64_t IGNORE_EXCEEDING = seconds_to_nanoseconds(10); | 
 | 61 |  | 
 | 62 | /* | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 63 |  * We don't track direct-drawing via Surface:lockHardwareCanvas() | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 64 |  * for now | 
 | 65 |  * | 
 | 66 |  * TODO: kSurfaceCanvas can negatively impact other drawing by using up | 
 | 67 |  * time on the RenderThread, figure out how to attribute that as a jank-causer | 
 | 68 |  */ | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 69 | static const int64_t EXEMPT_FRAMES_FLAGS = FrameInfoFlags::SurfaceCanvas; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 70 |  | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 71 | // The bucketing algorithm controls so to speak | 
 | 72 | // If a frame is <= to this it goes in bucket 0 | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 73 | static const uint32_t kBucketMinThreshold = 5; | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 74 | // If a frame is > this, start counting in increments of 2ms | 
 | 75 | static const uint32_t kBucket2msIntervals = 32; | 
 | 76 | // If a frame is > this, start counting in increments of 4ms | 
 | 77 | static const uint32_t kBucket4msIntervals = 48; | 
 | 78 |  | 
| John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 79 | // For testing purposes to try and eliminate test infra overhead we will | 
 | 80 | // consider any unknown delay of frame start as part of the test infrastructure | 
 | 81 | // and filter it out of the frame profile data | 
 | 82 | static FrameInfoIndex sFrameStart = FrameInfoIndex::IntendedVsync; | 
 | 83 |  | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 84 | // The interval of the slow frame histogram | 
 | 85 | static const uint32_t kSlowFrameBucketIntervalMs = 50; | 
 | 86 | // The start point of the slow frame bucket in ms | 
 | 87 | static const uint32_t kSlowFrameBucketStartMs = 150; | 
 | 88 |  | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 89 | // This will be called every frame, performance sensitive | 
 | 90 | // Uses bit twiddling to avoid branching while achieving the packing desired | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 91 | static uint32_t frameCountIndexForFrameTime(nsecs_t frameTime) { | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 92 |     uint32_t index = static_cast<uint32_t>(ns2ms(frameTime)); | 
 | 93 |     // If index > kBucketMinThreshold mask will be 0xFFFFFFFF as a result | 
 | 94 |     // of negating 1 (twos compliment, yaay) else mask will be 0 | 
 | 95 |     uint32_t mask = -(index > kBucketMinThreshold); | 
 | 96 |     // If index > threshold, this will essentially perform: | 
 | 97 |     // amountAboveThreshold = index - threshold; | 
 | 98 |     // index = threshold + (amountAboveThreshold / 2) | 
 | 99 |     // However if index is <= this will do nothing. It will underflow, do | 
 | 100 |     // a right shift by 0 (no-op), then overflow back to the original value | 
 | 101 |     index = ((index - kBucket4msIntervals) >> (index > kBucket4msIntervals)) | 
 | 102 |             + kBucket4msIntervals; | 
 | 103 |     index = ((index - kBucket2msIntervals) >> (index > kBucket2msIntervals)) | 
 | 104 |             + kBucket2msIntervals; | 
 | 105 |     // If index was < minThreshold at the start of all this it's going to | 
 | 106 |     // be a pretty garbage value right now. However, mask is 0 so we'll end | 
 | 107 |     // up with the desired result of 0. | 
 | 108 |     index = (index - kBucketMinThreshold) & mask; | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 109 |     return index; | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 110 | } | 
 | 111 |  | 
 | 112 | // Only called when dumping stats, less performance sensitive | 
 | 113 | static uint32_t frameTimeForFrameCountIndex(uint32_t index) { | 
 | 114 |     index = index + kBucketMinThreshold; | 
 | 115 |     if (index > kBucket2msIntervals) { | 
 | 116 |         index += (index - kBucket2msIntervals); | 
 | 117 |     } | 
 | 118 |     if (index > kBucket4msIntervals) { | 
 | 119 |         // This works because it was already doubled by the above if | 
 | 120 |         // 1 is added to shift slightly more towards the middle of the bucket | 
 | 121 |         index += (index - kBucket4msIntervals) + 1; | 
 | 122 |     } | 
 | 123 |     return index; | 
 | 124 | } | 
 | 125 |  | 
| John Reck | 2d5b8d7 | 2016-07-28 15:36:11 -0700 | [diff] [blame] | 126 | JankTracker::JankTracker(const DisplayInfo& displayInfo) { | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 127 |     // By default this will use malloc memory. It may be moved later to ashmem | 
 | 128 |     // if there is shared space for it and a request comes in to do that. | 
 | 129 |     mData = new ProfileData; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 130 |     reset(); | 
| John Reck | 2d5b8d7 | 2016-07-28 15:36:11 -0700 | [diff] [blame] | 131 |     nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1_s / displayInfo.fps); | 
 | 132 | #if USE_HWC2 | 
 | 133 |     nsecs_t sfOffset = frameIntervalNanos - (displayInfo.presentationDeadline - 1_ms); | 
 | 134 |     nsecs_t offsetDelta = sfOffset - displayInfo.appVsyncOffset; | 
 | 135 |     // There are two different offset cases. If the offsetDelta is positive | 
 | 136 |     // and small, then the intention is to give apps extra time by leveraging | 
 | 137 |     // pipelining between the UI & RT threads. If the offsetDelta is large or | 
 | 138 |     // negative, the intention is to subtract time from the total duration | 
 | 139 |     // in which case we can't afford to wait for dequeueBuffer blockage. | 
 | 140 |     if (offsetDelta <= 4_ms && offsetDelta >= 0) { | 
 | 141 |         // SF will begin composition at VSYNC-app + offsetDelta. If we are triple | 
 | 142 |         // buffered, this is the expected time at which dequeueBuffer will | 
 | 143 |         // return due to the staggering of VSYNC-app & VSYNC-sf. | 
 | 144 |         mDequeueTimeForgiveness = offsetDelta + 4_ms; | 
 | 145 |     } | 
 | 146 | #endif | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 147 |     setFrameInterval(frameIntervalNanos); | 
 | 148 | } | 
 | 149 |  | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 150 | JankTracker::~JankTracker() { | 
 | 151 |     freeData(); | 
 | 152 | } | 
 | 153 |  | 
 | 154 | void JankTracker::freeData() { | 
 | 155 |     if (mIsMapped) { | 
 | 156 |         munmap(mData, sizeof(ProfileData)); | 
 | 157 |     } else { | 
 | 158 |         delete mData; | 
 | 159 |     } | 
 | 160 |     mIsMapped = false; | 
 | 161 |     mData = nullptr; | 
 | 162 | } | 
 | 163 |  | 
 | 164 | void JankTracker::switchStorageToAshmem(int ashmemfd) { | 
 | 165 |     int regionSize = ashmem_get_size_region(ashmemfd); | 
 | 166 |     if (regionSize < static_cast<int>(sizeof(ProfileData))) { | 
 | 167 |         ALOGW("Ashmem region is too small! Received %d, required %u", | 
| John Reck | 98fa0a3 | 2015-03-31 12:03:51 -0700 | [diff] [blame] | 168 |                 regionSize, static_cast<unsigned int>(sizeof(ProfileData))); | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 169 |         return; | 
 | 170 |     } | 
 | 171 |     ProfileData* newData = reinterpret_cast<ProfileData*>( | 
 | 172 |             mmap(NULL, sizeof(ProfileData), PROT_READ | PROT_WRITE, | 
 | 173 |             MAP_SHARED, ashmemfd, 0)); | 
 | 174 |     if (newData == MAP_FAILED) { | 
 | 175 |         int err = errno; | 
 | 176 |         ALOGW("Failed to move profile data to ashmem fd %d, error = %d", | 
 | 177 |                 ashmemfd, err); | 
 | 178 |         return; | 
 | 179 |     } | 
 | 180 |  | 
 | 181 |     // The new buffer may have historical data that we want to build on top of | 
 | 182 |     // But let's make sure we don't overflow Just In Case | 
 | 183 |     uint32_t divider = 0; | 
 | 184 |     if (newData->totalFrameCount > (1 << 24)) { | 
 | 185 |         divider = 4; | 
 | 186 |     } | 
 | 187 |     for (size_t i = 0; i < mData->jankTypeCounts.size(); i++) { | 
 | 188 |         newData->jankTypeCounts[i] >>= divider; | 
 | 189 |         newData->jankTypeCounts[i] += mData->jankTypeCounts[i]; | 
 | 190 |     } | 
 | 191 |     for (size_t i = 0; i < mData->frameCounts.size(); i++) { | 
 | 192 |         newData->frameCounts[i] >>= divider; | 
 | 193 |         newData->frameCounts[i] += mData->frameCounts[i]; | 
 | 194 |     } | 
 | 195 |     newData->jankFrameCount >>= divider; | 
 | 196 |     newData->jankFrameCount += mData->jankFrameCount; | 
 | 197 |     newData->totalFrameCount >>= divider; | 
 | 198 |     newData->totalFrameCount += mData->totalFrameCount; | 
| John Reck | 379f264 | 2015-04-06 13:29:25 -0700 | [diff] [blame] | 199 |     if (newData->statStartTime > mData->statStartTime | 
 | 200 |             || newData->statStartTime == 0) { | 
 | 201 |         newData->statStartTime = mData->statStartTime; | 
 | 202 |     } | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 203 |  | 
 | 204 |     freeData(); | 
 | 205 |     mData = newData; | 
 | 206 |     mIsMapped = true; | 
 | 207 | } | 
 | 208 |  | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 209 | void JankTracker::setFrameInterval(nsecs_t frameInterval) { | 
 | 210 |     mFrameInterval = frameInterval; | 
 | 211 |     mThresholds[kMissedVsync] = 1; | 
 | 212 |     /* | 
 | 213 |      * Due to interpolation and sample rate differences between the touch | 
 | 214 |      * panel and the display (example, 85hz touch panel driving a 60hz display) | 
 | 215 |      * we call high latency 1.5 * frameinterval | 
 | 216 |      * | 
 | 217 |      * NOTE: Be careful when tuning this! A theoretical 1,000hz touch panel | 
 | 218 |      * on a 60hz display will show kOldestInputEvent - kIntendedVsync of being 15ms | 
 | 219 |      * Thus this must always be larger than frameInterval, or it will fail | 
 | 220 |      */ | 
 | 221 |     mThresholds[kHighInputLatency] = static_cast<int64_t>(1.5 * frameInterval); | 
 | 222 |  | 
 | 223 |     // Note that these do not add up to 1. This is intentional. It's to deal | 
 | 224 |     // with variance in values, and should be sort of an upper-bound on what | 
 | 225 |     // is reasonable to expect. | 
 | 226 |     mThresholds[kSlowUI] = static_cast<int64_t>(.5 * frameInterval); | 
 | 227 |     mThresholds[kSlowSync] = static_cast<int64_t>(.2 * frameInterval); | 
 | 228 |     mThresholds[kSlowRT] = static_cast<int64_t>(.75 * frameInterval); | 
 | 229 |  | 
 | 230 | } | 
 | 231 |  | 
 | 232 | void JankTracker::addFrame(const FrameInfo& frame) { | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 233 |     mData->totalFrameCount++; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 234 |     // Fast-path for jank-free frames | 
| John Reck | 126720a | 2016-04-15 15:16:38 -0700 | [diff] [blame] | 235 |     int64_t totalDuration = frame.duration(sFrameStart, FrameInfoIndex::FrameCompleted); | 
| John Reck | 2d5b8d7 | 2016-07-28 15:36:11 -0700 | [diff] [blame] | 236 |     if (mDequeueTimeForgiveness | 
 | 237 |             && frame[FrameInfoIndex::DequeueBufferDuration] > 500_us) { | 
 | 238 |         nsecs_t expectedDequeueDuration = | 
 | 239 |                 mDequeueTimeForgiveness + frame[FrameInfoIndex::Vsync] | 
 | 240 |                 - frame[FrameInfoIndex::IssueDrawCommandsStart]; | 
 | 241 |         if (expectedDequeueDuration > 0) { | 
 | 242 |             // Forgive only up to the expected amount, but not more than | 
 | 243 |             // the actual time spent blocked. | 
 | 244 |             nsecs_t forgiveAmount = std::min(expectedDequeueDuration, | 
 | 245 |                     frame[FrameInfoIndex::DequeueBufferDuration]); | 
 | 246 |             totalDuration -= forgiveAmount; | 
 | 247 |         } | 
 | 248 |     } | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 249 |     uint32_t framebucket = frameCountIndexForFrameTime(totalDuration); | 
| John Reck | e70c575 | 2015-03-06 14:40:50 -0800 | [diff] [blame] | 250 |     // Keep the fast path as fast as possible. | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 251 |     if (CC_LIKELY(totalDuration < mFrameInterval)) { | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 252 |         mData->frameCounts[framebucket]++; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 253 |         return; | 
 | 254 |     } | 
 | 255 |  | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 256 |     // Only things like Surface.lockHardwareCanvas() are exempt from tracking | 
| Chris Craik | 1b54fb2 | 2015-06-02 17:40:58 -0700 | [diff] [blame] | 257 |     if (frame[FrameInfoIndex::Flags] & EXEMPT_FRAMES_FLAGS) { | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 258 |         return; | 
 | 259 |     } | 
 | 260 |  | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 261 |     if (framebucket <= mData->frameCounts.size()) { | 
 | 262 |         mData->frameCounts[framebucket]++; | 
 | 263 |     } else { | 
 | 264 |         framebucket = (ns2ms(totalDuration) - kSlowFrameBucketStartMs) | 
 | 265 |                 / kSlowFrameBucketIntervalMs; | 
 | 266 |         framebucket = std::min(framebucket, | 
 | 267 |                 static_cast<uint32_t>(mData->slowFrameCounts.size() - 1)); | 
 | 268 |         framebucket = std::max(framebucket, 0u); | 
 | 269 |         mData->slowFrameCounts[framebucket]++; | 
 | 270 |     } | 
 | 271 |  | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 272 |     mData->jankFrameCount++; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 273 |  | 
 | 274 |     for (int i = 0; i < NUM_BUCKETS; i++) { | 
| John Reck | be3fba0 | 2015-07-06 13:49:58 -0700 | [diff] [blame] | 275 |         int64_t delta = frame.duration(COMPARISONS[i].start, COMPARISONS[i].end); | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 276 |         if (delta >= mThresholds[i] && delta < IGNORE_EXCEEDING) { | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 277 |             mData->jankTypeCounts[i]++; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 278 |         } | 
 | 279 |     } | 
 | 280 | } | 
 | 281 |  | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 282 | void JankTracker::dumpBuffer(const void* buffer, size_t bufsize, int fd) { | 
 | 283 |     if (bufsize < sizeof(ProfileData)) { | 
 | 284 |         return; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 285 |     } | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 286 |     const ProfileData* data = reinterpret_cast<const ProfileData*>(buffer); | 
 | 287 |     dumpData(data, fd); | 
 | 288 | } | 
 | 289 |  | 
 | 290 | void JankTracker::dumpData(const ProfileData* data, int fd) { | 
| John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 291 |     if (sFrameStart != FrameInfoIndex::IntendedVsync) { | 
 | 292 |         dprintf(fd, "\nNote: Data has been filtered!"); | 
 | 293 |     } | 
| Ying Wang | 05f5674 | 2015-04-07 18:03:31 -0700 | [diff] [blame] | 294 |     dprintf(fd, "\nStats since: %" PRIu64 "ns", data->statStartTime); | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 295 |     dprintf(fd, "\nTotal frames rendered: %u", data->totalFrameCount); | 
 | 296 |     dprintf(fd, "\nJanky frames: %u (%.2f%%)", data->jankFrameCount, | 
 | 297 |             (float) data->jankFrameCount / (float) data->totalFrameCount * 100.0f); | 
| John Reck | 682573c | 2015-10-30 10:37:35 -0700 | [diff] [blame] | 298 |     dprintf(fd, "\n50th percentile: %ums", findPercentile(data, 50)); | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 299 |     dprintf(fd, "\n90th percentile: %ums", findPercentile(data, 90)); | 
 | 300 |     dprintf(fd, "\n95th percentile: %ums", findPercentile(data, 95)); | 
 | 301 |     dprintf(fd, "\n99th percentile: %ums", findPercentile(data, 99)); | 
 | 302 |     for (int i = 0; i < NUM_BUCKETS; i++) { | 
 | 303 |         dprintf(fd, "\nNumber %s: %u", JANK_TYPE_NAMES[i], data->jankTypeCounts[i]); | 
 | 304 |     } | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 305 |     dprintf(fd, "\nHISTOGRAM:"); | 
 | 306 |     for (size_t i = 0; i < data->frameCounts.size(); i++) { | 
 | 307 |         dprintf(fd, " %ums=%u", frameTimeForFrameCountIndex(i), | 
 | 308 |                 data->frameCounts[i]); | 
 | 309 |     } | 
 | 310 |     for (size_t i = 0; i < data->slowFrameCounts.size(); i++) { | 
 | 311 |         dprintf(fd, " %zums=%u", (i * kSlowFrameBucketIntervalMs) + kSlowFrameBucketStartMs, | 
 | 312 |                 data->slowFrameCounts[i]); | 
 | 313 |     } | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 314 |     dprintf(fd, "\n"); | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 315 | } | 
 | 316 |  | 
 | 317 | void JankTracker::reset() { | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 318 |     mData->jankTypeCounts.fill(0); | 
 | 319 |     mData->frameCounts.fill(0); | 
| John Reck | 8f55d00 | 2016-04-12 13:10:19 -0700 | [diff] [blame] | 320 |     mData->slowFrameCounts.fill(0); | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 321 |     mData->totalFrameCount = 0; | 
 | 322 |     mData->jankFrameCount = 0; | 
| John Reck | 379f264 | 2015-04-06 13:29:25 -0700 | [diff] [blame] | 323 |     mData->statStartTime = systemTime(CLOCK_MONOTONIC); | 
| John Reck | c7cd9cf | 2016-03-28 10:38:19 -0700 | [diff] [blame] | 324 |     sFrameStart = Properties::filterOutTestOverhead | 
 | 325 |             ? FrameInfoIndex::HandleInputStart | 
 | 326 |             : FrameInfoIndex::IntendedVsync; | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 327 | } | 
 | 328 |  | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 329 | uint32_t JankTracker::findPercentile(const ProfileData* data, int percentile) { | 
 | 330 |     int pos = percentile * data->totalFrameCount / 100; | 
 | 331 |     int remaining = data->totalFrameCount - pos; | 
| John Reck | 6601080 | 2016-03-30 14:19:44 -0700 | [diff] [blame] | 332 |     for (int i = data->slowFrameCounts.size() - 1; i >= 0; i--) { | 
 | 333 |         remaining -= data->slowFrameCounts[i]; | 
 | 334 |         if (remaining <= 0) { | 
 | 335 |             return (i * kSlowFrameBucketIntervalMs) + kSlowFrameBucketStartMs; | 
 | 336 |         } | 
 | 337 |     } | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 338 |     for (int i = data->frameCounts.size() - 1; i >= 0; i--) { | 
 | 339 |         remaining -= data->frameCounts[i]; | 
| John Reck | e70c575 | 2015-03-06 14:40:50 -0800 | [diff] [blame] | 340 |         if (remaining <= 0) { | 
| John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 341 |             return frameTimeForFrameCountIndex(i); | 
| John Reck | e70c575 | 2015-03-06 14:40:50 -0800 | [diff] [blame] | 342 |         } | 
 | 343 |     } | 
 | 344 |     return 0; | 
 | 345 | } | 
 | 346 |  | 
| John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 347 | } /* namespace uirenderer */ | 
 | 348 | } /* namespace android */ |