blob: 2c567b361a15cc1c015767b063c1c9c9dc06af50 [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"
John Reck7075c792017-07-05 14:03:43 -070020#include "ProfileData.h"
John Reckba6adf62015-02-19 14:36:50 -080021#include "renderthread/TimeLord.h"
22#include "utils/RingBuffer.h"
23
John Reckedc524c2015-03-18 15:24:33 -070024#include <cutils/compiler.h>
John Reck2d5b8d72016-07-28 15:36:11 -070025#include <ui/DisplayInfo.h>
John Reckedc524c2015-03-18 15:24:33 -070026
John Reckb36016c2015-03-11 08:50:53 -070027#include <array>
John Reckba6adf62015-02-19 14:36:50 -080028#include <memory>
29
30namespace android {
31namespace uirenderer {
32
John Reckdf1742e2017-01-19 15:56:21 -080033enum 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
43struct ProfileDataDescription {
44 JankTrackerType type;
45 std::string name;
46};
47
John Reckba6adf62015-02-19 14:36:50 -080048// TODO: Replace DrawProfiler with this
49class JankTracker {
50public:
John Reckfb5c6752016-07-29 10:08:16 -070051 explicit JankTracker(const DisplayInfo& displayInfo);
John Reckedc524c2015-03-18 15:24:33 -070052 ~JankTracker();
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 Reckba6adf62015-02-19 14:36:50 -080059 void addFrame(const FrameInfo& frame);
60
John Reckdf1742e2017-01-19 15:56:21 -080061 void dump(int fd) { dumpData(fd, &mDescription, mData); }
John Reckba6adf62015-02-19 14:36:50 -080062 void reset();
63
John Reckdf1742e2017-01-19 15:56:21 -080064 void rotateStorage();
John Reckedc524c2015-03-18 15:24:33 -070065 void switchStorageToAshmem(int ashmemfd);
66
John Reck7075c792017-07-05 14:03:43 -070067 uint32_t findPercentile(int p) { return mData->findPercentile(p); }
John Reckedc524c2015-03-18 15:24:33 -070068
John Reckba6adf62015-02-19 14:36:50 -080069private:
John Reckedc524c2015-03-18 15:24:33 -070070 void freeData();
71 void setFrameInterval(nsecs_t frameIntervalNanos);
John Recke70c5752015-03-06 14:40:50 -080072
John Reckdf1742e2017-01-19 15:56:21 -080073 static void dumpData(int fd, const ProfileDataDescription* description, const ProfileData* data);
John Reckedc524c2015-03-18 15:24:33 -070074
John Reckb36016c2015-03-11 08:50:53 -070075 std::array<int64_t, NUM_BUCKETS> mThresholds;
John Reckba6adf62015-02-19 14:36:50 -080076 int64_t mFrameInterval;
John Reck2d5b8d72016-07-28 15:36:11 -070077 // The amount of time we will erase from the total duration to account
78 // for SF vsync offsets with HWC2 blocking dequeueBuffers.
79 // (Vsync + mDequeueBlockTolerance) is the point at which we expect
80 // SF to have released the buffer normally, so we will forgive up to that
81 // point in time by comparing to (IssueDrawCommandsStart + DequeueDuration)
82 // This is only used if we are in pipelined mode and are using HWC2,
83 // otherwise it's 0.
84 nsecs_t mDequeueTimeForgiveness = 0;
John Reckedc524c2015-03-18 15:24:33 -070085 ProfileData* mData;
86 bool mIsMapped = false;
John Reckdf1742e2017-01-19 15:56:21 -080087 ProfileDataDescription mDescription;
John Reckba6adf62015-02-19 14:36:50 -080088};
89
90} /* namespace uirenderer */
91} /* namespace android */
92
93#endif /* JANKTRACKER_H_ */