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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_DESCRIPTORS_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_DESCRIPTORS_H_ 19 20 #include <array> 21 22 #include "perfetto/ext/base/string_view.h" 23 #include "perfetto/protozero/proto_utils.h" 24 25 namespace perfetto { 26 namespace trace_processor { 27 28 using protozero::proto_utils::ProtoSchemaType; 29 30 // We assume that no ftrace event (e.g. SchedSwitchFtraceEvent) has a proto 31 // field which id is >= this. 32 static constexpr size_t kMaxFtraceEventFields = 32; 33 34 // This file is the header for the generated descriptors for all ftrace event 35 // protos. These descriptors can be used to parse ftrace event protos without 36 // needing individual parsing logic for every event. (In proto_trace_parser.cc) 37 // By generating these descriptors we avoid having to build the full proto 38 // library. These structs deliberately don't have a ctor (nor are initialized) 39 // because they are used to define linker-initialized dicts in the .cc file. 40 struct FieldDescriptor { 41 const char* name; 42 ProtoSchemaType type; 43 }; 44 45 struct MessageDescriptor { 46 const char* name; 47 size_t max_field_id; 48 FieldDescriptor fields[kMaxFtraceEventFields]; 49 }; 50 51 MessageDescriptor* GetMessageDescriptorForId(size_t id); 52 MessageDescriptor* GetMessageDescriptorForName(base::StringView name); 53 size_t GetDescriptorsSize(); 54 55 } // namespace trace_processor 56 } // namespace perfetto 57 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_FTRACE_DESCRIPTORS_H_ 58