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 | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 23 | #include <cutils/compiler.h> |
| 24 | |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 25 | #include <array> |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 26 | #include <memory> |
| 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
| 31 | enum JankType { |
| 32 | kMissedVsync = 0, |
| 33 | kHighInputLatency, |
| 34 | kSlowUI, |
| 35 | kSlowSync, |
| 36 | kSlowRT, |
| 37 | |
| 38 | // must be last |
| 39 | NUM_BUCKETS, |
| 40 | }; |
| 41 | |
John Reck | 5ed587f | 2016-03-24 15:57:01 -0700 | [diff] [blame] | 42 | struct SlowFrame { |
| 43 | uint16_t whenHours; // When this occurred in CLOCK_MONOTONIC in hours |
| 44 | uint16_t frametimeMs; // How long the frame took in ms |
| 45 | }; |
| 46 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 47 | // Try to keep as small as possible, should match ASHMEM_SIZE in |
| 48 | // GraphicsStatsService.java |
| 49 | struct ProfileData { |
| 50 | std::array<uint32_t, NUM_BUCKETS> jankTypeCounts; |
| 51 | // See comments on kBucket* constants for what this holds |
John Reck | 379f264 | 2015-04-06 13:29:25 -0700 | [diff] [blame] | 52 | std::array<uint32_t, 55> frameCounts; |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 53 | |
| 54 | uint32_t totalFrameCount; |
| 55 | uint32_t jankFrameCount; |
John Reck | 379f264 | 2015-04-06 13:29:25 -0700 | [diff] [blame] | 56 | nsecs_t statStartTime; |
John Reck | 5ed587f | 2016-03-24 15:57:01 -0700 | [diff] [blame] | 57 | |
| 58 | std::array<SlowFrame, 10> slowestFrames; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | // TODO: Replace DrawProfiler with this |
| 62 | class JankTracker { |
| 63 | public: |
| 64 | JankTracker(nsecs_t frameIntervalNanos); |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 65 | ~JankTracker(); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 66 | |
| 67 | void addFrame(const FrameInfo& frame); |
| 68 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 69 | void dump(int fd) { dumpData(mData, fd); } |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 70 | void reset(); |
| 71 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 72 | void switchStorageToAshmem(int ashmemfd); |
| 73 | |
| 74 | uint32_t findPercentile(int p) { return findPercentile(mData, p); } |
| 75 | |
| 76 | ANDROID_API static void dumpBuffer(const void* buffer, size_t bufsize, int fd); |
| 77 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 78 | private: |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 79 | void freeData(); |
| 80 | void setFrameInterval(nsecs_t frameIntervalNanos); |
John Reck | 5ed587f | 2016-03-24 15:57:01 -0700 | [diff] [blame] | 81 | void updateSlowest(const FrameInfo& frame); |
John Reck | e70c575 | 2015-03-06 14:40:50 -0800 | [diff] [blame] | 82 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 83 | static uint32_t findPercentile(const ProfileData* data, int p); |
| 84 | static void dumpData(const ProfileData* data, int fd); |
| 85 | |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 86 | std::array<int64_t, NUM_BUCKETS> mThresholds; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 87 | int64_t mFrameInterval; |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 88 | ProfileData* mData; |
| 89 | bool mIsMapped = false; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | } /* namespace uirenderer */ |
| 93 | } /* namespace android */ |
| 94 | |
| 95 | #endif /* JANKTRACKER_H_ */ |