blob: bcd031efa78d75c0d04f553165dad5a1644c6616 [file] [log] [blame]
John Reckba6adf62015-02-19 14:36:50 -08001/*
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"
Jorim Jaggi10f328c2021-01-19 00:08:02 +010020#include "FrameMetricsReporter.h"
John Reck7075c792017-07-05 14:03:43 -070021#include "ProfileData.h"
John Reck34781b22017-07-05 16:39:36 -070022#include "ProfileDataContainer.h"
John Reckba6adf62015-02-19 14:36:50 -080023#include "renderthread/TimeLord.h"
24#include "utils/RingBuffer.h"
25
John Reckedc524c2015-03-18 15:24:33 -070026#include <cutils/compiler.h>
27
John Reckb36016c2015-03-11 08:50:53 -070028#include <array>
John Reckba6adf62015-02-19 14:36:50 -080029#include <memory>
30
31namespace android {
32namespace uirenderer {
33
John Reckdf1742e2017-01-19 15:56:21 -080034enum 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
44struct ProfileDataDescription {
45 JankTrackerType type;
46 std::string name;
47};
48
John Reckba6adf62015-02-19 14:36:50 -080049// TODO: Replace DrawProfiler with this
50class JankTracker {
51public:
Alec Mouri22d753f2019-09-05 17:11:45 -070052 explicit JankTracker(ProfileDataContainer* globalData);
John Reckba6adf62015-02-19 14:36:50 -080053
John Reckdf1742e2017-01-19 15:56:21 -080054 void setDescription(JankTrackerType type, const std::string&& name) {
55 mDescription.type = type;
56 mDescription.name = name;
57 }
58
John Reck34781b22017-07-05 16:39:36 -070059 FrameInfo* startFrame() { return &mFrames.next(); }
Pablo Gamito88660d72021-08-09 14:37:56 +000060 void finishFrame(FrameInfo& frame, std::unique_ptr<FrameMetricsReporter>& reporter,
61 int64_t frameNumber, int32_t surfaceId);
John Reckba6adf62015-02-19 14:36:50 -080062
Jorim Jaggi10f328c2021-01-19 00:08:02 +010063 // Calculates the 'legacy' jank information, i.e. with outdated refresh rate information and
64 // without GPU completion or deadlined information.
65 void calculateLegacyJank(FrameInfo& frame);
Siarhei Vishniakou07d35cb2021-07-03 02:22:12 +000066 void dumpStats(int fd) NO_THREAD_SAFETY_ANALYSIS { dumpData(fd, &mDescription, mData.get()); }
John Reck34781b22017-07-05 16:39:36 -070067 void dumpFrames(int fd);
John Reckba6adf62015-02-19 14:36:50 -080068 void reset();
69
John Reck34781b22017-07-05 16:39:36 -070070 // Exposed for FrameInfoVisualizer
71 // TODO: Figure out a better way to handle this
72 RingBuffer<FrameInfo, 120>& frames() { return mFrames; }
John Reckedc524c2015-03-18 15:24:33 -070073
John Reckba6adf62015-02-19 14:36:50 -080074private:
Jorim Jaggi10f328c2021-01-19 00:08:02 +010075 void recomputeThresholds(int64_t frameInterval);
John Reck1bcacfd2017-11-03 10:12:19 -070076 static void dumpData(int fd, const ProfileDataDescription* description,
77 const ProfileData* data);
John Reckedc524c2015-03-18 15:24:33 -070078
Jorim Jaggi10f328c2021-01-19 00:08:02 +010079 // Last frame budget for which mThresholds were computed.
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;
John Reck2d5b8d72016-07-28 15:36:11 -070085 // The amount of time we will erase from the total duration to account
86 // for SF vsync offsets with HWC2 blocking dequeueBuffers.
87 // (Vsync + mDequeueBlockTolerance) is the point at which we expect
88 // SF to have released the buffer normally, so we will forgive up to that
89 // point in time by comparing to (IssueDrawCommandsStart + DequeueDuration)
90 // This is only used if we are in pipelined mode and are using HWC2,
91 // otherwise it's 0.
Jorim Jaggi10f328c2021-01-19 00:08:02 +010092 nsecs_t mDequeueTimeForgivenessLegacy = 0;
93
94 nsecs_t mNextFrameStartUnstuffed GUARDED_BY(mDataMutex) = -1;
Jorim Jaggi71db8892021-02-03 23:19:29 +010095 ProfileDataContainer mData GUARDED_BY(mDataMutex);
96 ProfileDataContainer* mGlobalData GUARDED_BY(mDataMutex);
John Reckdf1742e2017-01-19 15:56:21 -080097 ProfileDataDescription mDescription;
John Reck34781b22017-07-05 16:39:36 -070098
99 // Ring buffer large enough for 2 seconds worth of frames
100 RingBuffer<FrameInfo, 120> mFrames;
Jorim Jaggi71db8892021-02-03 23:19:29 +0100101
102 // Mutex to protect acccess to mData and mGlobalData obtained from mGlobalData->getDataMutex
103 std::mutex& mDataMutex;
John Reckba6adf62015-02-19 14:36:50 -0800104};
105
106} /* namespace uirenderer */
107} /* namespace android */
108
109#endif /* JANKTRACKER_H_ */