blob: ae339ecf746ce3ac1c4acb5654ebf2ec1c98babf [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 Reckb36016c2015-03-11 08:50:53 -070023#include <array>
John Reckba6adf62015-02-19 14:36:50 -080024#include <memory>
25
26namespace android {
27namespace uirenderer {
28
29enum JankType {
30 kMissedVsync = 0,
31 kHighInputLatency,
32 kSlowUI,
33 kSlowSync,
34 kSlowRT,
35
36 // must be last
37 NUM_BUCKETS,
38};
39
40struct JankBucket {
41 // Number of frames that hit this bucket
42 uint32_t count;
43};
44
45// TODO: Replace DrawProfiler with this
46class JankTracker {
47public:
48 JankTracker(nsecs_t frameIntervalNanos);
49
50 void setFrameInterval(nsecs_t frameIntervalNanos);
51
52 void addFrame(const FrameInfo& frame);
53
54 void dump(int fd);
55 void reset();
56
57private:
John Recke70c5752015-03-06 14:40:50 -080058 uint32_t findPercentile(int p);
59
John Reckb36016c2015-03-11 08:50:53 -070060 std::array<JankBucket, NUM_BUCKETS> mBuckets;
61 std::array<int64_t, NUM_BUCKETS> mThresholds;
62 std::array<uint32_t, 128> mFrameCounts;
John Reckba6adf62015-02-19 14:36:50 -080063
64 int64_t mFrameInterval;
65 uint32_t mTotalFrameCount;
66 uint32_t mJankFrameCount;
67};
68
69} /* namespace uirenderer */
70} /* namespace android */
71
72#endif /* JANKTRACKER_H_ */