blob: d4553758a48ae1ef3d0c80c325da4e042bd56b72 [file] [log] [blame]
Prabir Pradhandae52792023-12-15 07:36:40 +00001/*
2 * Copyright 2024 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#pragma once
18
19#include "InputTracingBackendInterface.h"
20
21#include <perfetto/tracing.h>
22#include <mutex>
23
24namespace android::inputdispatcher::trace::impl {
25
26/**
27 * The tracing backend that writes events into ongoing Perfetto traces.
28 *
29 * Example shell command to take an input trace from Perfetto:
30 *
31 * adb shell perfetto \
32 * -c - --txt \
33 * -o /data/misc/perfetto-traces/trace.input-trace \
34 * <<END
35 * buffers: {
36 * size_kb: 5000
37 * fill_policy: RING_BUFFER
38 * }
39 * data_sources: {
40 * config {
41 * name: "android.input.inputevent"
42 * }
43 * }
44 * END
45 */
46class PerfettoBackend : public InputTracingBackendInterface {
47public:
48 PerfettoBackend();
49 ~PerfettoBackend() override = default;
50
Prabir Pradhan8c3b1432024-02-09 23:34:16 +000051 void traceKeyEvent(const TracedKeyEvent&, const TracedEventArgs&) override;
52 void traceMotionEvent(const TracedMotionEvent&, const TracedEventArgs&) override;
53 void traceWindowDispatch(const WindowDispatchArgs&, const TracedEventArgs&) override;
Prabir Pradhandae52792023-12-15 07:36:40 +000054
55 class InputEventDataSource : public perfetto::DataSource<InputEventDataSource> {
56 public:
57 void OnSetup(const SetupArgs&) override {}
58 void OnStart(const StartArgs&) override;
59 void OnStop(const StopArgs&) override;
60 };
61
62private:
63 static std::once_flag sDataSourceRegistrationFlag;
64};
65
66} // namespace android::inputdispatcher::trace::impl