| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 36 |
Generic, |
| 37 |
|
| 38 |
Package, |
| 39 |
|
| 40 |
Window, |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
struct ProfileDataDescription { |
| 45 |
JankTrackerType type; |
| 46 |
std::string name; |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
class JankTracker { |
| 51 |
public: |
| 52 |
explicit JankTracker(ProfileDataContainer* globalData); |
| 53 |
|
| 54 |
void setDescription(JankTrackerType type, const std::string&& name) { |
| 55 |
mDescription.type = type; |
| 56 |
mDescription.name = name; |
| 57 |
} |
| 58 |
|
| 59 |
FrameInfo* startFrame() { return &mFrames.next(); } |
| 60 |
void finishFrame(FrameInfo& frame, std::unique_ptr<FrameMetricsReporter>& reporter, |
| 61 |
int64_t frameNumber, int32_t surfaceId); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
void calculateLegacyJank(FrameInfo& frame); |
| 66 |
void dumpStats(int fd) NO_THREAD_SAFETY_ANALYSIS { dumpData(fd, &mDescription, mData.get()); } |
| 67 |
void dumpFrames(int fd); |
| 68 |
void reset(); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
RingBuffer<FrameInfo, 120>& frames() { return mFrames; } |
| 73 |
|
| 74 |
private: |
| 75 |
void recomputeThresholds(int64_t frameInterval); |
| 76 |
static void dumpData(int fd, const ProfileDataDescription* description, |
| 77 |
const ProfileData* data); |
| 78 |
|
| 79 |
|
| 80 |
int64_t mThresholdsFrameBudget GUARDED_BY(mDataMutex); |
| 81 |
std::array<int64_t, NUM_BUCKETS> mThresholds GUARDED_BY(mDataMutex); |
| 82 |
|
| 83 |
int64_t mFrameIntervalLegacy; |
| 84 |
nsecs_t mSwapDeadlineLegacy = -1; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
nsecs_t mDequeueTimeForgivenessLegacy = 0; |
| 93 |
|
| 94 |
nsecs_t mNextFrameStartUnstuffed GUARDED_BY(mDataMutex) = -1; |
| 95 |
ProfileDataContainer mData GUARDED_BY(mDataMutex); |
| 96 |
ProfileDataContainer* mGlobalData GUARDED_BY(mDataMutex); |
| 97 |
ProfileDataDescription mDescription; |
| 98 |
|
| 99 |
|
| 100 |
RingBuffer<FrameInfo, 120> mFrames; |
| 101 |
|
| 102 |
|
| 103 |
std::mutex& mDataMutex; |
| 104 |
}; |
| 105 |
|
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
#endif |