blob: 8b482d5a804d53c28398ab15a7f17736939eb2e2 [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"
20#include "renderthread/TimeLord.h"
21#include "utils/RingBuffer.h"
22
John Reckedc524c2015-03-18 15:24:33 -070023#include <cutils/compiler.h>
John Reck2d5b8d72016-07-28 15:36:11 -070024#include <ui/DisplayInfo.h>
John Reckedc524c2015-03-18 15:24:33 -070025
John Reckb36016c2015-03-11 08:50:53 -070026#include <array>
John Reckba6adf62015-02-19 14:36:50 -080027#include <memory>
28
29namespace android {
30namespace uirenderer {
31
32enum JankType {
33 kMissedVsync = 0,
34 kHighInputLatency,
35 kSlowUI,
36 kSlowSync,
37 kSlowRT,
38
39 // must be last
40 NUM_BUCKETS,
41};
42
John Reckedc524c2015-03-18 15:24:33 -070043// Try to keep as small as possible, should match ASHMEM_SIZE in
44// GraphicsStatsService.java
45struct ProfileData {
46 std::array<uint32_t, NUM_BUCKETS> jankTypeCounts;
47 // See comments on kBucket* constants for what this holds
John Reck66010802016-03-30 14:19:44 -070048 std::array<uint32_t, 57> frameCounts;
49 // Holds a histogram of frame times in 50ms increments from 150ms to 5s
50 std::array<uint16_t, 97> slowFrameCounts;
John Reckedc524c2015-03-18 15:24:33 -070051
52 uint32_t totalFrameCount;
53 uint32_t jankFrameCount;
John Reck379f2642015-04-06 13:29:25 -070054 nsecs_t statStartTime;
John Reckba6adf62015-02-19 14:36:50 -080055};
56
57// TODO: Replace DrawProfiler with this
58class JankTracker {
59public:
John Reckfb5c6752016-07-29 10:08:16 -070060 explicit JankTracker(const DisplayInfo& displayInfo);
John Reckedc524c2015-03-18 15:24:33 -070061 ~JankTracker();
John Reckba6adf62015-02-19 14:36:50 -080062
63 void addFrame(const FrameInfo& frame);
64
John Reckedc524c2015-03-18 15:24:33 -070065 void dump(int fd) { dumpData(mData, fd); }
John Reckba6adf62015-02-19 14:36:50 -080066 void reset();
67
John Reckedc524c2015-03-18 15:24:33 -070068 void switchStorageToAshmem(int ashmemfd);
69
70 uint32_t findPercentile(int p) { return findPercentile(mData, p); }
71
72 ANDROID_API static void dumpBuffer(const void* buffer, size_t bufsize, int fd);
73
John Reckba6adf62015-02-19 14:36:50 -080074private:
John Reckedc524c2015-03-18 15:24:33 -070075 void freeData();
76 void setFrameInterval(nsecs_t frameIntervalNanos);
John Recke70c5752015-03-06 14:40:50 -080077
John Reckedc524c2015-03-18 15:24:33 -070078 static uint32_t findPercentile(const ProfileData* data, int p);
79 static void dumpData(const ProfileData* data, int fd);
80
John Reckb36016c2015-03-11 08:50:53 -070081 std::array<int64_t, NUM_BUCKETS> mThresholds;
John Reckba6adf62015-02-19 14:36:50 -080082 int64_t mFrameInterval;
John Reck2d5b8d72016-07-28 15:36:11 -070083 // The amount of time we will erase from the total duration to account
84 // for SF vsync offsets with HWC2 blocking dequeueBuffers.
85 // (Vsync + mDequeueBlockTolerance) is the point at which we expect
86 // SF to have released the buffer normally, so we will forgive up to that
87 // point in time by comparing to (IssueDrawCommandsStart + DequeueDuration)
88 // This is only used if we are in pipelined mode and are using HWC2,
89 // otherwise it's 0.
90 nsecs_t mDequeueTimeForgiveness = 0;
John Reckedc524c2015-03-18 15:24:33 -070091 ProfileData* mData;
92 bool mIsMapped = false;
John Reckba6adf62015-02-19 14:36:50 -080093};
94
95} /* namespace uirenderer */
96} /* namespace android */
97
98#endif /* JANKTRACKER_H_ */