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 "FrameMetricsReporter.h" 21 #include "ProfileData.h" 22 #include "ProfileDataContainer.h" 23 #include "renderthread/TimeLord.h" 24 #include "utils/RingBuffer.h" 25 26 #include <cutils/compiler.h> 27 28 #include <array> 29 #include <memory> 30 31 namespace android { 32 namespace uirenderer { 33 34 enum class JankTrackerType { 35 // The default, means there's no description set 36 Generic, 37 // The profile data represents a package 38 Package, 39 // The profile data is for a specific window 40 Window, 41 }; 42 43 // Metadata about the ProfileData being collected 44 struct ProfileDataDescription { 45 JankTrackerType type; 46 std::string name; 47 }; 48 49 // TODO: Replace DrawProfiler with this 50 class JankTracker { 51 public: 52 explicit JankTracker(ProfileDataContainer* globalData); 53 setDescription(JankTrackerType type,const std::string && name)54 void setDescription(JankTrackerType type, const std::string&& name) { 55 mDescription.type = type; 56 mDescription.name = name; 57 } 58 startFrame()59 FrameInfo* startFrame() { return &mFrames.next(); } 60 void finishFrame(FrameInfo& frame, std::unique_ptr<FrameMetricsReporter>& reporter); 61 62 // Calculates the 'legacy' jank information, i.e. with outdated refresh rate information and 63 // without GPU completion or deadlined information. 64 void calculateLegacyJank(FrameInfo& frame); dumpStats(int fd)65 void dumpStats(int fd) NO_THREAD_SAFETY_ANALYSIS { dumpData(fd, &mDescription, mData.get()); } 66 void dumpFrames(int fd); 67 void reset(); 68 69 // Exposed for FrameInfoVisualizer 70 // TODO: Figure out a better way to handle this frames()71 RingBuffer<FrameInfo, 120>& frames() { return mFrames; } 72 73 private: 74 void recomputeThresholds(int64_t frameInterval); 75 static void dumpData(int fd, const ProfileDataDescription* description, 76 const ProfileData* data); 77 78 // Last frame budget for which mThresholds were computed. 79 int64_t mThresholdsFrameBudget GUARDED_BY(mDataMutex); 80 std::array<int64_t, NUM_BUCKETS> mThresholds GUARDED_BY(mDataMutex); 81 82 int64_t mFrameIntervalLegacy; 83 nsecs_t mSwapDeadlineLegacy = -1; 84 // The amount of time we will erase from the total duration to account 85 // for SF vsync offsets with HWC2 blocking dequeueBuffers. 86 // (Vsync + mDequeueBlockTolerance) is the point at which we expect 87 // SF to have released the buffer normally, so we will forgive up to that 88 // point in time by comparing to (IssueDrawCommandsStart + DequeueDuration) 89 // This is only used if we are in pipelined mode and are using HWC2, 90 // otherwise it's 0. 91 nsecs_t mDequeueTimeForgivenessLegacy = 0; 92 93 nsecs_t mNextFrameStartUnstuffed GUARDED_BY(mDataMutex) = -1; 94 ProfileDataContainer mData GUARDED_BY(mDataMutex); 95 ProfileDataContainer* mGlobalData GUARDED_BY(mDataMutex); 96 ProfileDataDescription mDescription; 97 98 // Ring buffer large enough for 2 seconds worth of frames 99 RingBuffer<FrameInfo, 120> mFrames; 100 101 // Mutex to protect acccess to mData and mGlobalData obtained from mGlobalData->getDataMutex 102 std::mutex& mDataMutex; 103 }; 104 105 } /* namespace uirenderer */ 106 } /* namespace android */ 107 108 #endif /* JANKTRACKER_H_ */ 109