Prabir Pradhan | dae5279 | 2023-12-15 07:36:40 +0000 | [diff] [blame^] | 1 | /* |
| 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 | |
| 24 | namespace 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 | */ |
| 46 | class PerfettoBackend : public InputTracingBackendInterface { |
| 47 | public: |
| 48 | PerfettoBackend(); |
| 49 | ~PerfettoBackend() override = default; |
| 50 | |
| 51 | void traceKeyEvent(const TracedKeyEvent&) const override; |
| 52 | void traceMotionEvent(const TracedMotionEvent&) const override; |
| 53 | void traceWindowDispatch(const WindowDispatchArgs&) const override; |
| 54 | |
| 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 | |
| 62 | private: |
| 63 | static std::once_flag sDataSourceRegistrationFlag; |
| 64 | }; |
| 65 | |
| 66 | } // namespace android::inputdispatcher::trace::impl |