1 /* 2 * Copyright (C) 2019 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_PROTO_TRACK_EVENT_PARSER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_PARSER_H_ 19 20 #include <array> 21 #include <map> 22 23 #include "perfetto/base/build_config.h" 24 #include "perfetto/protozero/field.h" 25 #include "src/trace_processor/importers/common/args_tracker.h" 26 #include "src/trace_processor/importers/common/parser_types.h" 27 #include "src/trace_processor/importers/common/slice_tracker.h" 28 #include "src/trace_processor/importers/common/trace_parser.h" 29 #include "src/trace_processor/importers/proto/active_chrome_processes_tracker.h" 30 #include "src/trace_processor/importers/proto/chrome_string_lookup.h" 31 #include "src/trace_processor/storage/trace_storage.h" 32 #include "src/trace_processor/util/proto_to_args_parser.h" 33 34 #include "protos/perfetto/trace/track_event/track_event.pbzero.h" 35 36 namespace Json { 37 class Value; 38 } 39 40 namespace perfetto { 41 namespace trace_processor { 42 43 // Field numbers to be added to args table automatically via reflection 44 // 45 // TODO(ddrone): replace with a predicate on field id to import new fields 46 // automatically 47 static constexpr uint16_t kReflectFields[] = {24, 25, 26, 27, 28, 29, 32, 33, 48 34, 35, 38, 39, 40, 41, 43, 49}; 49 50 class PacketSequenceStateGeneration; 51 class TraceProcessorContext; 52 class TrackEventTracker; 53 54 class TrackEventParser { 55 public: 56 TrackEventParser(TraceProcessorContext*, TrackEventTracker*); 57 58 void ParseTrackDescriptor(int64_t packet_timestamp, 59 protozero::ConstBytes, 60 uint32_t packet_sequence_id); 61 UniquePid ParseProcessDescriptor(int64_t packet_timestamp, 62 protozero::ConstBytes); 63 UniqueTid ParseThreadDescriptor(protozero::ConstBytes); 64 65 void ParseTrackEvent(int64_t ts, 66 const TrackEventData* event_data, 67 protozero::ConstBytes, 68 uint32_t packet_sequence_id); 69 70 void NotifyEndOfFile(); 71 72 private: 73 class EventImporter; 74 75 void ParseChromeProcessDescriptor(UniquePid, protozero::ConstBytes); 76 void ParseChromeThreadDescriptor(UniqueTid, protozero::ConstBytes); 77 void ParseCounterDescriptor(TrackId, protozero::ConstBytes); 78 void AddActiveProcess(int64_t packet_timestamp, int32_t pid); 79 80 // Reflection-based proto TrackEvent field parser. 81 util::ProtoToArgsParser args_parser_; 82 83 TraceProcessorContext* context_; 84 TrackEventTracker* track_event_tracker_; 85 86 const StringId counter_name_thread_time_id_; 87 const StringId counter_name_thread_instruction_count_id_; 88 const StringId task_file_name_args_key_id_; 89 const StringId task_function_name_args_key_id_; 90 const StringId task_line_number_args_key_id_; 91 const StringId log_message_body_key_id_; 92 const StringId log_message_source_location_function_name_key_id_; 93 const StringId log_message_source_location_file_name_key_id_; 94 const StringId log_message_source_location_line_number_key_id_; 95 const StringId source_location_function_name_key_id_; 96 const StringId source_location_file_name_key_id_; 97 const StringId source_location_line_number_key_id_; 98 const StringId raw_legacy_event_id_; 99 const StringId legacy_event_passthrough_utid_id_; 100 const StringId legacy_event_category_key_id_; 101 const StringId legacy_event_name_key_id_; 102 const StringId legacy_event_phase_key_id_; 103 const StringId legacy_event_duration_ns_key_id_; 104 const StringId legacy_event_thread_timestamp_ns_key_id_; 105 const StringId legacy_event_thread_duration_ns_key_id_; 106 const StringId legacy_event_thread_instruction_count_key_id_; 107 const StringId legacy_event_thread_instruction_delta_key_id_; 108 const StringId legacy_event_use_async_tts_key_id_; 109 const StringId legacy_event_unscoped_id_key_id_; 110 const StringId legacy_event_global_id_key_id_; 111 const StringId legacy_event_local_id_key_id_; 112 const StringId legacy_event_id_scope_key_id_; 113 const StringId legacy_event_bind_id_key_id_; 114 const StringId legacy_event_bind_to_enclosing_key_id_; 115 const StringId legacy_event_flow_direction_key_id_; 116 const StringId histogram_name_key_id_; 117 const StringId flow_direction_value_in_id_; 118 const StringId flow_direction_value_out_id_; 119 const StringId flow_direction_value_inout_id_; 120 const StringId chrome_legacy_ipc_class_args_key_id_; 121 const StringId chrome_legacy_ipc_line_args_key_id_; 122 const StringId chrome_host_app_package_name_id_; 123 const StringId chrome_crash_trace_id_name_id_; 124 const StringId chrome_process_label_flat_key_id_; 125 const StringId chrome_process_type_id_; 126 const StringId event_category_key_id_; 127 const StringId event_name_key_id_; 128 129 ChromeStringLookup chrome_string_lookup_; 130 std::array<StringId, 4> counter_unit_ids_; 131 132 std::vector<uint16_t> reflect_fields_; 133 134 ActiveChromeProcessesTracker active_chrome_processes_tracker_; 135 }; 136 137 } // namespace trace_processor 138 } // namespace perfetto 139 140 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_PARSER_H_ 141