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/ftrace_reader/event_info_constants.h" 18 19 namespace perfetto { 20 21 Field MakeField(const char* name, uint32_t id, ProtoFieldType type) { 22 Field field{}; 23 field.ftrace_name = name; 24 field.proto_field_id = id; 25 field.proto_field_type = type; 26 return field; 27 } 28 29 std::vector<Field> GetStaticCommonFieldsInfo() { 30 std::vector<Field> fields; 31 32 fields.push_back(MakeField("common_pid", 2, kProtoInt32)); 33 34 return fields; 35 } 36 37 bool SetTranslationStrategy(FtraceFieldType ftrace, 38 ProtoFieldType proto, 39 TranslationStrategy* out) { 40 if (ftrace == kFtraceCommonPid32 && proto == kProtoInt32) { 41 *out = kCommonPid32ToInt32; 42 } else if (ftrace == kFtraceInode32 && proto == kProtoUint64) { 43 *out = kInode32ToUint64; 44 } else if (ftrace == kFtraceInode64 && proto == kProtoUint64) { 45 *out = kInode64ToUint64; 46 } else if (ftrace == kFtracePid32 && proto == kProtoInt32) { 47 *out = kPid32ToInt32; 48 } else if (ftrace == kFtraceDevId32 && proto == kProtoUint64) { 49 *out = kDevId32ToUint64; 50 } else if (ftrace == kFtraceDevId64 && proto == kProtoUint64) { 51 *out = kDevId64ToUint64; 52 } else if (ftrace == kFtraceUint8 && proto == kProtoUint32) { 53 *out = kUint8ToUint32; 54 } else if (ftrace == kFtraceUint16 && proto == kProtoUint32) { 55 *out = kUint16ToUint32; 56 } else if (ftrace == kFtraceUint32 && proto == kProtoUint32) { 57 *out = kUint32ToUint32; 58 } else if (ftrace == kFtraceUint32 && proto == kProtoUint64) { 59 *out = kUint32ToUint64; 60 } else if (ftrace == kFtraceUint64 && proto == kProtoUint64) { 61 *out = kUint64ToUint64; 62 } else if (ftrace == kFtraceInt8 && proto == kProtoInt32) { 63 *out = kInt8ToInt32; 64 } else if (ftrace == kFtraceInt16 && proto == kProtoInt32) { 65 *out = kInt16ToInt32; 66 } else if (ftrace == kFtraceInt32 && proto == kProtoInt32) { 67 *out = kInt32ToInt32; 68 } else if (ftrace == kFtraceInt32 && proto == kProtoInt64) { 69 *out = kInt32ToInt64; 70 } else if (ftrace == kFtraceInt64 && proto == kProtoInt64) { 71 *out = kInt64ToInt64; 72 } else if (ftrace == kFtraceFixedCString && proto == kProtoString) { 73 *out = kFixedCStringToString; 74 } else if (ftrace == kFtraceCString && proto == kProtoString) { 75 *out = kCStringToString; 76 } else if (ftrace == kFtraceStringPtr && proto == kProtoString) { 77 *out = kStringPtrToString; 78 } else if (ftrace == kFtraceBool && proto == kProtoUint32) { 79 *out = kBoolToUint32; 80 } else { 81 PERFETTO_DLOG("No translation strategy for '%s' -> '%s'", ToString(ftrace), 82 ToString(proto)); 83 return false; 84 } 85 return true; 86 } 87 88 } // namespace perfetto 89