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