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 namespace perfetto { 20 using protozero::proto_utils::ProtoSchemaType; 21 22 Field MakeField(const char* name, uint32_t id, ProtoSchemaType type) { 23 Field field{}; 24 field.ftrace_name = name; 25 field.proto_field_id = id; 26 field.proto_field_type = type; 27 return field; 28 } 29 30 std::vector<Field> GetStaticCommonFieldsInfo() { 31 std::vector<Field> fields; 32 33 fields.push_back(MakeField("common_pid", 2, ProtoSchemaType::kInt32)); 34 35 return fields; 36 } 37 38 bool SetTranslationStrategy(FtraceFieldType ftrace, 39 ProtoSchemaType proto, 40 TranslationStrategy* out) { 41 if (ftrace == kFtraceCommonPid32 && proto == ProtoSchemaType::kInt32) { 42 *out = kCommonPid32ToInt32; 43 } else if (ftrace == kFtraceCommonPid32 && proto == ProtoSchemaType::kInt64) { 44 *out = kCommonPid32ToInt64; 45 } else if (ftrace == kFtraceInode32 && proto == ProtoSchemaType::kUint64) { 46 *out = kInode32ToUint64; 47 } else if (ftrace == kFtraceInode64 && proto == ProtoSchemaType::kUint64) { 48 *out = kInode64ToUint64; 49 } else if (ftrace == kFtracePid32 && proto == ProtoSchemaType::kInt32) { 50 *out = kPid32ToInt32; 51 } else if (ftrace == kFtracePid32 && proto == ProtoSchemaType::kInt64) { 52 *out = kPid32ToInt64; 53 } else if (ftrace == kFtraceDevId32 && proto == ProtoSchemaType::kUint64) { 54 *out = kDevId32ToUint64; 55 } else if (ftrace == kFtraceDevId64 && proto == ProtoSchemaType::kUint64) { 56 *out = kDevId64ToUint64; 57 } else if (ftrace == kFtraceUint8 && proto == ProtoSchemaType::kUint32) { 58 *out = kUint8ToUint32; 59 } else if (ftrace == kFtraceUint8 && proto == ProtoSchemaType::kUint64) { 60 *out = kUint8ToUint64; 61 } else if (ftrace == kFtraceUint16 && proto == ProtoSchemaType::kUint32) { 62 *out = kUint16ToUint32; 63 } else if (ftrace == kFtraceUint16 && proto == ProtoSchemaType::kUint64) { 64 *out = kUint16ToUint64; 65 } else if (ftrace == kFtraceUint32 && proto == ProtoSchemaType::kUint32) { 66 *out = kUint32ToUint32; 67 } else if (ftrace == kFtraceUint32 && proto == ProtoSchemaType::kUint64) { 68 *out = kUint32ToUint64; 69 } else if (ftrace == kFtraceUint64 && proto == ProtoSchemaType::kUint64) { 70 *out = kUint64ToUint64; 71 } else if (ftrace == kFtraceInt8 && proto == ProtoSchemaType::kInt32) { 72 *out = kInt8ToInt32; 73 } else if (ftrace == kFtraceInt8 && proto == ProtoSchemaType::kInt64) { 74 *out = kInt8ToInt64; 75 } else if (ftrace == kFtraceInt16 && proto == ProtoSchemaType::kInt32) { 76 *out = kInt16ToInt32; 77 } else if (ftrace == kFtraceInt16 && proto == ProtoSchemaType::kInt64) { 78 *out = kInt16ToInt64; 79 } else if (ftrace == kFtraceInt32 && proto == ProtoSchemaType::kInt32) { 80 *out = kInt32ToInt32; 81 } else if (ftrace == kFtraceInt32 && proto == ProtoSchemaType::kInt64) { 82 *out = kInt32ToInt64; 83 } else if (ftrace == kFtraceInt64 && proto == ProtoSchemaType::kInt64) { 84 *out = kInt64ToInt64; 85 } else if (ftrace == kFtraceFixedCString && 86 proto == ProtoSchemaType::kString) { 87 *out = kFixedCStringToString; 88 } else if (ftrace == kFtraceCString && proto == ProtoSchemaType::kString) { 89 *out = kCStringToString; 90 } else if (ftrace == kFtraceStringPtr && proto == ProtoSchemaType::kString) { 91 *out = kStringPtrToString; 92 } else if (ftrace == kFtraceBool && proto == ProtoSchemaType::kUint32) { 93 *out = kBoolToUint32; 94 } else if (ftrace == kFtraceBool && proto == ProtoSchemaType::kUint64) { 95 *out = kBoolToUint64; 96 } else if (ftrace == kFtraceDataLoc && proto == ProtoSchemaType::kString) { 97 *out = kDataLocToString; 98 } else { 99 PERFETTO_DLOG("No translation strategy for '%s' -> '%s'", ToString(ftrace), 100 ProtoSchemaToString(proto)); 101 return false; 102 } 103 return true; 104 } 105 106 } // namespace perfetto 107