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 | */ |
| 16 | #ifndef JANKTRACKER_H_ |
| 17 | #define JANKTRACKER_H_ |
| 18 | |
| 19 | #include "FrameInfo.h" |
| 20 | #include "renderthread/TimeLord.h" |
| 21 | #include "utils/RingBuffer.h" |
| 22 | |
| 23 | #include <memory> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | enum JankType { |
| 29 | kMissedVsync = 0, |
| 30 | kHighInputLatency, |
| 31 | kSlowUI, |
| 32 | kSlowSync, |
| 33 | kSlowRT, |
| 34 | |
| 35 | // must be last |
| 36 | NUM_BUCKETS, |
| 37 | }; |
| 38 | |
| 39 | struct JankBucket { |
| 40 | // Number of frames that hit this bucket |
| 41 | uint32_t count; |
| 42 | }; |
| 43 | |
| 44 | // TODO: Replace DrawProfiler with this |
| 45 | class JankTracker { |
| 46 | public: |
| 47 | JankTracker(nsecs_t frameIntervalNanos); |
| 48 | |
| 49 | void setFrameInterval(nsecs_t frameIntervalNanos); |
| 50 | |
| 51 | void addFrame(const FrameInfo& frame); |
| 52 | |
| 53 | void dump(int fd); |
| 54 | void reset(); |
| 55 | |
| 56 | private: |
John Reck | e70c575 | 2015-03-06 14:40:50 -0800 | [diff] [blame^] | 57 | uint32_t findPercentile(int p); |
| 58 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 59 | JankBucket mBuckets[NUM_BUCKETS]; |
| 60 | int64_t mThresholds[NUM_BUCKETS]; |
John Reck | e70c575 | 2015-03-06 14:40:50 -0800 | [diff] [blame^] | 61 | uint32_t mFrameCounts[128]; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 62 | |
| 63 | int64_t mFrameInterval; |
| 64 | uint32_t mTotalFrameCount; |
| 65 | uint32_t mJankFrameCount; |
| 66 | }; |
| 67 | |
| 68 | } /* namespace uirenderer */ |
| 69 | } /* namespace android */ |
| 70 | |
| 71 | #endif /* JANKTRACKER_H_ */ |