Siarhei Vishniakou | a04181f | 2021-03-26 05:56:49 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2021 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 | |
| 17 | #ifndef _UI_INPUT_INPUTDISPATCHER_LATENCYAGGREGATOR_H |
| 18 | #define _UI_INPUT_INPUTDISPATCHER_LATENCYAGGREGATOR_H |
| 19 | |
| 20 | #include <statslog.h> |
| 21 | #include <utils/Timers.h> |
| 22 | |
| 23 | #include "InputEventTimeline.h" |
| 24 | |
| 25 | namespace android::inputdispatcher { |
| 26 | |
| 27 | enum SketchIndex : size_t { |
| 28 | EVENT_TO_READ = 0, |
| 29 | READ_TO_DELIVER = 1, |
| 30 | DELIVER_TO_CONSUME = 2, |
| 31 | CONSUME_TO_FINISH = 3, |
| 32 | CONSUME_TO_GPU_COMPLETE = 4, |
| 33 | GPU_COMPLETE_TO_PRESENT = 5, |
| 34 | END_TO_END = 6, // EVENT_TO_PRESENT |
| 35 | SIZE = 7, // Must be last |
| 36 | }; |
| 37 | |
| 38 | // Let's create a full timeline here: |
| 39 | // eventTime |
| 40 | // readTime |
| 41 | // <---- after this point, the data becomes per-connection |
| 42 | // deliveryTime // time at which the event was sent to the receiver |
| 43 | // consumeTime // time at which the receiver read the event |
| 44 | // finishTime // time at which the finish event was received |
| 45 | // GraphicsTimeline::GPU_COMPLETED_TIME |
| 46 | // GraphicsTimeline::PRESENT_TIME |
| 47 | |
| 48 | /** |
| 49 | * TODO(b/167947340): Replace this class with a KLL sketch |
| 50 | */ |
| 51 | class Sketch { |
| 52 | public: |
| 53 | void addValue(nsecs_t value); |
| 54 | android::util::BytesField serialize(); |
| 55 | void reset(); |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * Keep sketches of the provided events and report slow events |
| 60 | */ |
| 61 | class LatencyAggregator final : public InputEventTimelineProcessor { |
| 62 | public: |
| 63 | LatencyAggregator(); |
| 64 | /** |
| 65 | * Record a complete event timeline |
| 66 | */ |
| 67 | void processTimeline(const InputEventTimeline& timeline) override; |
| 68 | |
| 69 | std::string dump(const char* prefix); |
| 70 | |
| 71 | ~LatencyAggregator(); |
| 72 | |
| 73 | private: |
| 74 | static AStatsManager_PullAtomCallbackReturn pullAtomCallback(int32_t atom_tag, |
| 75 | AStatsEventList* data, |
| 76 | void* cookie); |
| 77 | AStatsManager_PullAtomCallbackReturn pullData(AStatsEventList* data); |
| 78 | // ---------- Slow event handling ---------- |
| 79 | void processSlowEvent(const InputEventTimeline& timeline); |
| 80 | nsecs_t mLastSlowEventTime = 0; |
| 81 | // How many slow events have been skipped due to rate limiting |
| 82 | size_t mNumSkippedSlowEvents = 0; |
| 83 | // How many events have been received since the last time we reported a slow event |
| 84 | size_t mNumEventsSinceLastSlowEventReport = 0; |
| 85 | |
| 86 | // ---------- Statistics handling ---------- |
| 87 | void processStatistics(const InputEventTimeline& timeline); |
| 88 | // Sketches |
| 89 | std::array<Sketch, SketchIndex::SIZE> mDownSketches; |
| 90 | std::array<Sketch, SketchIndex::SIZE> mMoveSketches; |
| 91 | }; |
| 92 | |
| 93 | } // namespace android::inputdispatcher |
| 94 | |
| 95 | #endif // _UI_INPUT_INPUTDISPATCHER_LATENCYAGGREGATOR_H |