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" |
John Reck | 7075c79 | 2017-07-05 14:03:43 -0700 | [diff] [blame] | 20 | #include "ProfileData.h" |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 21 | #include "ProfileDataContainer.h" |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 22 | #include "renderthread/TimeLord.h" |
| 23 | #include "utils/RingBuffer.h" |
| 24 | |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 25 | #include <cutils/compiler.h> |
| 26 | |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 27 | #include <array> |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 28 | #include <memory> |
| 29 | |
| 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 33 | enum class JankTrackerType { |
| 34 | // The default, means there's no description set |
| 35 | Generic, |
| 36 | // The profile data represents a package |
| 37 | Package, |
| 38 | // The profile data is for a specific window |
| 39 | Window, |
| 40 | }; |
| 41 | |
| 42 | // Metadata about the ProfileData being collected |
| 43 | struct ProfileDataDescription { |
| 44 | JankTrackerType type; |
| 45 | std::string name; |
| 46 | }; |
| 47 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 48 | // TODO: Replace DrawProfiler with this |
| 49 | class JankTracker { |
| 50 | public: |
Alec Mouri | 22d753f | 2019-09-05 17:11:45 -0700 | [diff] [blame] | 51 | explicit JankTracker(ProfileDataContainer* globalData); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 52 | |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 53 | void setDescription(JankTrackerType type, const std::string&& name) { |
| 54 | mDescription.type = type; |
| 55 | mDescription.name = name; |
| 56 | } |
| 57 | |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 58 | FrameInfo* startFrame() { return &mFrames.next(); } |
| 59 | void finishFrame(const FrameInfo& frame); |
Stan Iliev | 7203e1f | 2019-07-25 13:12:02 -0400 | [diff] [blame] | 60 | void finishGpuDraw(const FrameInfo& frame); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 61 | |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 62 | void dumpStats(int fd) { dumpData(fd, &mDescription, mData.get()); } |
| 63 | void dumpFrames(int fd); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 64 | void reset(); |
| 65 | |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 66 | // Exposed for FrameInfoVisualizer |
| 67 | // TODO: Figure out a better way to handle this |
| 68 | RingBuffer<FrameInfo, 120>& frames() { return mFrames; } |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 69 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 70 | private: |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 71 | void setFrameInterval(nsecs_t frameIntervalNanos); |
John Reck | e70c575 | 2015-03-06 14:40:50 -0800 | [diff] [blame] | 72 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 73 | static void dumpData(int fd, const ProfileDataDescription* description, |
| 74 | const ProfileData* data); |
John Reck | edc524c | 2015-03-18 15:24:33 -0700 | [diff] [blame] | 75 | |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 76 | std::array<int64_t, NUM_BUCKETS> mThresholds; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 77 | int64_t mFrameInterval; |
Zhiyin Luo (罗植尹) | 7a0d224 | 2020-01-11 17:14:05 +0800 | [diff] [blame] | 78 | nsecs_t mSwapDeadline = -1; |
John Reck | 2d5b8d7 | 2016-07-28 15:36:11 -0700 | [diff] [blame] | 79 | // The amount of time we will erase from the total duration to account |
| 80 | // for SF vsync offsets with HWC2 blocking dequeueBuffers. |
| 81 | // (Vsync + mDequeueBlockTolerance) is the point at which we expect |
| 82 | // SF to have released the buffer normally, so we will forgive up to that |
| 83 | // point in time by comparing to (IssueDrawCommandsStart + DequeueDuration) |
| 84 | // This is only used if we are in pipelined mode and are using HWC2, |
| 85 | // otherwise it's 0. |
| 86 | nsecs_t mDequeueTimeForgiveness = 0; |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 87 | ProfileDataContainer mData; |
| 88 | ProfileDataContainer* mGlobalData; |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 89 | ProfileDataDescription mDescription; |
John Reck | 34781b2 | 2017-07-05 16:39:36 -0700 | [diff] [blame] | 90 | |
| 91 | // Ring buffer large enough for 2 seconds worth of frames |
| 92 | RingBuffer<FrameInfo, 120> mFrames; |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } /* namespace uirenderer */ |
| 96 | } /* namespace android */ |
| 97 | |
| 98 | #endif /* JANKTRACKER_H_ */ |