blob: accfc29d8ebbcff1fba91ba9fcfead9c9cc01e58 [file] [log] [blame]
Siarhei Vishniakoua04181f2021-03-26 05:56:49 +00001/*
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 Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Siarhei Vishniakoua04181f2021-03-26 05:56:49 +000018
Siarhei Vishniakou99b9d382021-04-01 08:03:41 +000019#include <kll.h>
Siarhei Vishniakoua04181f2021-03-26 05:56:49 +000020#include <statslog.h>
21#include <utils/Timers.h>
22
23#include "InputEventTimeline.h"
24
25namespace android::inputdispatcher {
26
27enum 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 Vishniakoua04181f2021-03-26 05:56:49 +000049 * Keep sketches of the provided events and report slow events
50 */
51class LatencyAggregator final : public InputEventTimelineProcessor {
52public:
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
63private:
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 Vishniakou99b9d382021-04-01 08:03:41 +000079 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 Vishniakoua04181f2021-03-26 05:56:49 +000085};
86
87} // namespace android::inputdispatcher