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 <cstdint>
21 #include <optional>
22 #include <string>
23 #include <vector>
24
25 #include "perfetto/base/status.h"
26 #include "perfetto/ext/base/status_or.h"
27 #include "src/trace_processor/db/table.h"
28 #include "src/trace_processor/storage/trace_storage.h"
29 #include "src/trace_processor/tables/android_tables_py.h"
30 #include "src/trace_processor/tables/winscope_tables_py.h"
31
32 namespace perfetto::trace_processor::util::winscope_proto_mapping {
33
GetProtoName(const std::string & table_name)34 inline base::StatusOr<const char* const> GetProtoName(
35 const std::string& table_name) {
36 if (table_name == tables::SurfaceFlingerLayerTable::Name()) {
37 return ".perfetto.protos.LayerProto";
38 }
39 if (table_name == tables::SurfaceFlingerLayersSnapshotTable::Name()) {
40 return ".perfetto.protos.LayersSnapshotProto";
41 }
42 if (table_name == tables::SurfaceFlingerTransactionsTable::Name()) {
43 return ".perfetto.protos.TransactionTraceEntry";
44 }
45 if (table_name == tables::WindowManagerShellTransitionProtosTable::Name()) {
46 return ".perfetto.protos.ShellTransition";
47 }
48 if (table_name == tables::InputMethodClientsTable::Name()) {
49 return ".perfetto.protos.InputMethodClientsTraceProto";
50 }
51 if (table_name == tables::InputMethodManagerServiceTable::Name()) {
52 return ".perfetto.protos.InputMethodManagerServiceTraceProto";
53 }
54 if (table_name == tables::InputMethodServiceTable::Name()) {
55 return ".perfetto.protos.InputMethodServiceTraceProto";
56 }
57 if (table_name == tables::ViewCaptureTable::Name()) {
58 return ".perfetto.protos.ViewCapture";
59 }
60 if (table_name == tables::ViewCaptureViewTable::Name()) {
61 return ".perfetto.protos.ViewCapture.View";
62 }
63 if (table_name == tables::WindowManagerTable::Name()) {
64 return ".perfetto.protos.WindowManagerTraceEntry";
65 }
66 if (table_name == tables::AndroidKeyEventsTable::Name()) {
67 return ".perfetto.protos.AndroidKeyEvent";
68 }
69 if (table_name == tables::AndroidMotionEventsTable::Name()) {
70 return ".perfetto.protos.AndroidMotionEvent";
71 }
72 if (table_name == tables::AndroidInputEventDispatchTable::Name()) {
73 return ".perfetto.protos.AndroidWindowInputDispatchEvent";
74 }
75 return base::ErrStatus("%s table does not have proto descriptor.",
76 table_name.c_str());
77 }
78
GetAllowedFields(const std::string & table_name)79 inline std::optional<const std::vector<uint32_t>> GetAllowedFields(
80 const std::string& table_name) {
81 if (table_name == tables::SurfaceFlingerLayersSnapshotTable::Name()) {
82 return std::vector<uint32_t>({1, 2, 4, 5, 6, 7, 8});
83 }
84 if (table_name == tables::ViewCaptureTable::Name()) {
85 return std::vector<uint32_t>({1, 2});
86 }
87 return std::nullopt;
88 }
89
GetGroupIdColName(const std::string & table_name)90 inline std::optional<const std::string> GetGroupIdColName(
91 const std::string& table_name) {
92 if (table_name == tables::WindowManagerShellTransitionProtosTable::Name()) {
93 return "transition_id";
94 }
95 return std::nullopt;
96 }
97
GetInternedDataTable(const std::string & table_name,TraceStorage * storage)98 inline std::optional<const Table*> GetInternedDataTable(
99 const std::string& table_name,
100 TraceStorage* storage) {
101 if (table_name == tables::ViewCaptureTable::Name() ||
102 table_name == tables::ViewCaptureViewTable::Name()) {
103 return storage->mutable_viewcapture_interned_data_table();
104 }
105 return std::nullopt;
106 }
107
108 } // namespace perfetto::trace_processor::util::winscope_proto_mapping
109
110 #endif // SRC_TRACE_PROCESSOR_UTIL_WINSCOPE_PROTO_MAPPING_H_
111