blob: 84b8c3f3f1553056c07d0e187f88476022941de8 [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>
24
John Reckb36016c2015-03-11 08:50:53 -070025#include <array>
John Reckba6adf62015-02-19 14:36:50 -080026#include <memory>
27
28namespace android {
29namespace uirenderer {
30
31enum JankType {
32 kMissedVsync = 0,
33 kHighInputLatency,
34 kSlowUI,
35 kSlowSync,
36 kSlowRT,
37
38 // must be last
39 NUM_BUCKETS,
40};
41
John Reckedc524c2015-03-18 15:24:33 -070042// Try to keep as small as possible, should match ASHMEM_SIZE in
43// GraphicsStatsService.java
44struct ProfileData {
45 std::array<uint32_t, NUM_BUCKETS> jankTypeCounts;
46 // See comments on kBucket* constants for what this holds
John Reck66010802016-03-30 14:19:44 -070047 std::array<uint32_t, 57> frameCounts;
48 // Holds a histogram of frame times in 50ms increments from 150ms to 5s
49 std::array<uint16_t, 97> slowFrameCounts;
John Reckedc524c2015-03-18 15:24:33 -070050
51 uint32_t totalFrameCount;
52 uint32_t jankFrameCount;
John Reck379f2642015-04-06 13:29:25 -070053 nsecs_t statStartTime;
John Reckba6adf62015-02-19 14:36:50 -080054};
55
56// TODO: Replace DrawProfiler with this
57class JankTracker {
58public:
59 JankTracker(nsecs_t frameIntervalNanos);
John Reckedc524c2015-03-18 15:24:33 -070060 ~JankTracker();
John Reckba6adf62015-02-19 14:36:50 -080061
62 void addFrame(const FrameInfo& frame);
63
John Reckedc524c2015-03-18 15:24:33 -070064 void dump(int fd) { dumpData(mData, fd); }
John Reckba6adf62015-02-19 14:36:50 -080065 void reset();
66
John Reckedc524c2015-03-18 15:24:33 -070067 void switchStorageToAshmem(int ashmemfd);
68
69 uint32_t findPercentile(int p) { return findPercentile(mData, p); }
70
71 ANDROID_API static void dumpBuffer(const void* buffer, size_t bufsize, int fd);
72
John Reckba6adf62015-02-19 14:36:50 -080073private:
John Reckedc524c2015-03-18 15:24:33 -070074 void freeData();
75 void setFrameInterval(nsecs_t frameIntervalNanos);
John Recke70c5752015-03-06 14:40:50 -080076
John Reckedc524c2015-03-18 15:24:33 -070077 static uint32_t findPercentile(const ProfileData* data, int p);
78 static void dumpData(const ProfileData* data, int fd);
79
John Reckb36016c2015-03-11 08:50:53 -070080 std::array<int64_t, NUM_BUCKETS> mThresholds;
John Reckba6adf62015-02-19 14:36:50 -080081 int64_t mFrameInterval;
John Reckedc524c2015-03-18 15:24:33 -070082 ProfileData* mData;
83 bool mIsMapped = false;
John Reckba6adf62015-02-19 14:36:50 -080084};
85
86} /* namespace uirenderer */
87} /* namespace android */
88
89#endif /* JANKTRACKER_H_ */