1 /*
2 * Copyright (C) 2018 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 #include "src/traced/probes/ftrace/event_info_constants.h"
18
19 #include "protos/perfetto/trace/ftrace/ftrace_event.pbzero.h"
20
21 namespace perfetto {
22 using protozero::proto_utils::ProtoSchemaType;
23
24 namespace {
StaticField(const char * ftrace_name,uint32_t proto_field_id,ProtoSchemaType proto_field_type)25 Field StaticField(const char* ftrace_name,
26 uint32_t proto_field_id,
27 ProtoSchemaType proto_field_type) {
28 Field field{};
29 field.ftrace_name = ftrace_name;
30 field.proto_field_id = proto_field_id;
31 field.proto_field_type = proto_field_type;
32 return field;
33 }
34 } // namespace
35
GetStaticCommonFieldsInfo()36 std::vector<Field> GetStaticCommonFieldsInfo() {
37 using protos::pbzero::FtraceEvent;
38 std::vector<Field> fields;
39 fields.push_back(StaticField("common_pid", FtraceEvent::kPidFieldNumber,
40 ProtoSchemaType::kInt32));
41 // note: we won't be serialising the flags, this is only for the
42 // proto_translation_table to be aware of the field.
43 fields.push_back(StaticField("common_flags",
44 FtraceEvent::kCommonFlagsFieldNumber,
45 ProtoSchemaType::kUint32));
46 return fields;
47 }
48
SetTranslationStrategy(FtraceFieldType ftrace,ProtoSchemaType proto,TranslationStrategy * out)49 bool SetTranslationStrategy(FtraceFieldType ftrace,
50 ProtoSchemaType proto,
51 TranslationStrategy* out) {
52 if (ftrace == kFtraceCommonPid32 && proto == ProtoSchemaType::kInt32) {
53 *out = kCommonPid32ToInt32;
54 } else if (ftrace == kFtraceCommonPid32 && proto == ProtoSchemaType::kInt64) {
55 *out = kCommonPid32ToInt64;
56 } else if (ftrace == kFtraceInode32 && proto == ProtoSchemaType::kUint64) {
57 *out = kInode32ToUint64;
58 } else if (ftrace == kFtraceInode64 && proto == ProtoSchemaType::kUint64) {
59 *out = kInode64ToUint64;
60 } else if (ftrace == kFtracePid32 && proto == ProtoSchemaType::kInt32) {
61 *out = kPid32ToInt32;
62 } else if (ftrace == kFtracePid32 && proto == ProtoSchemaType::kInt64) {
63 *out = kPid32ToInt64;
64 } else if (ftrace == kFtraceDevId32 && proto == ProtoSchemaType::kUint64) {
65 *out = kDevId32ToUint64;
66 } else if (ftrace == kFtraceDevId64 && proto == ProtoSchemaType::kUint64) {
67 *out = kDevId64ToUint64;
68 } else if (ftrace == kFtraceUint8 && proto == ProtoSchemaType::kUint32) {
69 *out = kUint8ToUint32;
70 } else if (ftrace == kFtraceUint8 && proto == ProtoSchemaType::kUint64) {
71 *out = kUint8ToUint64;
72 } else if (ftrace == kFtraceUint16 && proto == ProtoSchemaType::kUint32) {
73 *out = kUint16ToUint32;
74 } else if (ftrace == kFtraceUint16 && proto == ProtoSchemaType::kUint64) {
75 *out = kUint16ToUint64;
76 } else if (ftrace == kFtraceUint32 && proto == ProtoSchemaType::kUint32) {
77 *out = kUint32ToUint32;
78 } else if (ftrace == kFtraceUint32 && proto == ProtoSchemaType::kUint64) {
79 *out = kUint32ToUint64;
80 } else if (ftrace == kFtraceUint64 && proto == ProtoSchemaType::kUint64) {
81 *out = kUint64ToUint64;
82 } else if (ftrace == kFtraceInt8 && proto == ProtoSchemaType::kInt32) {
83 *out = kInt8ToInt32;
84 } else if (ftrace == kFtraceInt8 && proto == ProtoSchemaType::kInt64) {
85 *out = kInt8ToInt64;
86 } else if (ftrace == kFtraceInt16 && proto == ProtoSchemaType::kInt32) {
87 *out = kInt16ToInt32;
88 } else if (ftrace == kFtraceInt16 && proto == ProtoSchemaType::kInt64) {
89 *out = kInt16ToInt64;
90 } else if (ftrace == kFtraceInt32 && proto == ProtoSchemaType::kInt32) {
91 *out = kInt32ToInt32;
92 } else if (ftrace == kFtraceInt32 && proto == ProtoSchemaType::kInt64) {
93 *out = kInt32ToInt64;
94 } else if (ftrace == kFtraceInt64 && proto == ProtoSchemaType::kInt64) {
95 *out = kInt64ToInt64;
96 } else if (ftrace == kFtraceFixedCString &&
97 proto == ProtoSchemaType::kString) {
98 *out = kFixedCStringToString;
99 } else if (ftrace == kFtraceCString && proto == ProtoSchemaType::kString) {
100 *out = kCStringToString;
101 } else if (ftrace == kFtraceStringPtr && proto == ProtoSchemaType::kString) {
102 *out = kStringPtrToString;
103 } else if (ftrace == kFtraceBool && proto == ProtoSchemaType::kUint32) {
104 *out = kBoolToUint32;
105 } else if (ftrace == kFtraceBool && proto == ProtoSchemaType::kUint64) {
106 *out = kBoolToUint64;
107 } else if (ftrace == kFtraceDataLoc && proto == ProtoSchemaType::kString) {
108 *out = kDataLocToString;
109 } else if (ftrace == kFtraceSymAddr64 && proto == ProtoSchemaType::kUint64) {
110 *out = kFtraceSymAddr64ToUint64;
111 } else {
112 PERFETTO_DLOG("No translation strategy for '%s' -> '%s'", ToString(ftrace),
113 ProtoSchemaToString(proto));
114 return false;
115 }
116 return true;
117 }
118
119 } // namespace perfetto
120