1 /*
2 * Copyright (C) 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 #ifndef SRC_TRACE_PROCESSOR_UTIL_WINSCOPE_PROTO_MAPPING_H_
18 #define SRC_TRACE_PROCESSOR_UTIL_WINSCOPE_PROTO_MAPPING_H_
19
20 #include "perfetto/ext/base/status_or.h"
21 #include "src/trace_processor/tables/android_tables_py.h"
22 #include "src/trace_processor/tables/winscope_tables_py.h"
23
24 namespace perfetto::trace_processor {
25 namespace util {
26 namespace winscope_proto_mapping {
GetProtoName(const std::string & table_name)27 inline base::StatusOr<const char* const> GetProtoName(
28 const std::string& table_name) {
29 if (table_name == tables::SurfaceFlingerLayerTable::Name()) {
30 return ".perfetto.protos.LayerProto";
31 }
32 if (table_name == tables::SurfaceFlingerLayersSnapshotTable::Name()) {
33 return ".perfetto.protos.LayersSnapshotProto";
34 }
35 if (table_name == tables::SurfaceFlingerTransactionsTable::Name()) {
36 return ".perfetto.protos.TransactionTraceEntry";
37 }
38 if (table_name == tables::WindowManagerShellTransitionsTable::Name()) {
39 return ".perfetto.protos.ShellTransition";
40 }
41 if (table_name == tables::InputMethodClientsTable::Name()) {
42 return ".perfetto.protos.InputMethodClientsTraceProto";
43 }
44 if (table_name == tables::InputMethodManagerServiceTable::Name()) {
45 return ".perfetto.protos.InputMethodManagerServiceTraceProto";
46 }
47 if (table_name == tables::InputMethodServiceTable::Name()) {
48 return ".perfetto.protos.InputMethodServiceTraceProto";
49 }
50 if (table_name == tables::ViewCaptureTable::Name()) {
51 return ".perfetto.protos.ViewCapture";
52 }
53 if (table_name == tables::WindowManagerTable::Name()) {
54 return ".perfetto.protos.WindowManagerTraceEntry";
55 }
56 if (table_name == tables::AndroidKeyEventsTable::Name()) {
57 return ".perfetto.protos.AndroidKeyEvent";
58 }
59 if (table_name == tables::AndroidMotionEventsTable::Name()) {
60 return ".perfetto.protos.AndroidMotionEvent";
61 }
62 if (table_name == tables::AndroidInputEventDispatchTable::Name()) {
63 return ".perfetto.protos.AndroidWindowInputDispatchEvent";
64 }
65 return base::ErrStatus("%s table does not have proto descriptor.",
66 table_name.c_str());
67 }
68
GetAllowedFields(const std::string & table_name)69 inline std::optional<const std::vector<uint32_t>> GetAllowedFields(
70 const std::string& table_name) {
71 if (table_name == tables::SurfaceFlingerLayersSnapshotTable::Name()) {
72 return std::vector<uint32_t>({1, 2, 4, 5, 6, 7, 8});
73 }
74 return std::nullopt;
75 }
76 } // namespace winscope_proto_mapping
77 } // namespace util
78 } // namespace perfetto::trace_processor
79
80 #endif // SRC_TRACE_PROCESSOR_UTIL_WINSCOPE_PROTO_MAPPING_H_
81