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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame^] | 17 | #pragma once |
Siarhei Vishniakou | a04181f | 2021-03-26 05:56:49 +0000 | [diff] [blame] | 18 | |
Siarhei Vishniakou | 99b9d38 | 2021-04-01 08:03:41 +0000 | [diff] [blame] | 19 | #include <kll.h> |
Siarhei Vishniakou | a04181f | 2021-03-26 05:56:49 +0000 | [diff] [blame] | 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 | /** |
Siarhei Vishniakou | a04181f | 2021-03-26 05:56:49 +0000 | [diff] [blame] | 49 | * Keep sketches of the provided events and report slow events |
| 50 | */ |
| 51 | class LatencyAggregator final : public InputEventTimelineProcessor { |
| 52 | public: |
| 53 | LatencyAggregator(); |
| 54 | /** |
| 55 | * Record a complete event timeline |
| 56 | */ |
| 57 | void processTimeline(const InputEventTimeline& timeline) override; |
| 58 | |
| 59 | std::string dump(const char* prefix); |
| 60 | |
| 61 | ~LatencyAggregator(); |
| 62 | |
| 63 | private: |
| 64 | static AStatsManager_PullAtomCallbackReturn pullAtomCallback(int32_t atom_tag, |
| 65 | AStatsEventList* data, |
| 66 | void* cookie); |
| 67 | AStatsManager_PullAtomCallbackReturn pullData(AStatsEventList* data); |
| 68 | // ---------- Slow event handling ---------- |
| 69 | void processSlowEvent(const InputEventTimeline& timeline); |
| 70 | nsecs_t mLastSlowEventTime = 0; |
| 71 | // How many slow events have been skipped due to rate limiting |
| 72 | size_t mNumSkippedSlowEvents = 0; |
| 73 | // How many events have been received since the last time we reported a slow event |
| 74 | size_t mNumEventsSinceLastSlowEventReport = 0; |
| 75 | |
| 76 | // ---------- Statistics handling ---------- |
| 77 | void processStatistics(const InputEventTimeline& timeline); |
| 78 | // Sketches |
Siarhei Vishniakou | 99b9d38 | 2021-04-01 08:03:41 +0000 | [diff] [blame] | 79 | std::array<std::unique_ptr<dist_proc::aggregation::KllQuantile>, SketchIndex::SIZE> |
| 80 | mDownSketches; |
| 81 | std::array<std::unique_ptr<dist_proc::aggregation::KllQuantile>, SketchIndex::SIZE> |
| 82 | mMoveSketches; |
| 83 | // How many events have been processed so far |
| 84 | size_t mNumSketchEventsProcessed = 0; |
Siarhei Vishniakou | a04181f | 2021-03-26 05:56:49 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace android::inputdispatcher |