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_TYPES_TRACE_PROCESSOR_CONTEXT_H_ 18 #define SRC_TRACE_PROCESSOR_TYPES_TRACE_PROCESSOR_CONTEXT_H_ 19 20 #include <memory> 21 #include <vector> 22 23 #include "perfetto/trace_processor/basic_types.h" 24 #include "src/trace_processor/types/destructible.h" 25 26 namespace perfetto { 27 namespace trace_processor { 28 29 enum TraceType { 30 kUnknownTraceType, 31 kProtoTraceType, 32 kJsonTraceType, 33 kFuchsiaTraceType, 34 kSystraceTraceType, 35 kGzipTraceType, 36 kCtraceTraceType, 37 kNinjaLogTraceType, 38 kAndroidBugreportTraceType, 39 }; 40 41 class ArgsTracker; 42 class ArgsTranslationTable; 43 class AsyncTrackSetTracker; 44 class AndroidProbesTracker; 45 class ChunkedTraceReader; 46 class ClockTracker; 47 class ClockConverter; 48 class DeobfuscationMappingTable; 49 class EventTracker; 50 class ForwardingTraceParser; 51 class FtraceModule; 52 class GlobalArgsTracker; 53 class GlobalStackProfileTracker; 54 class HeapGraphTracker; 55 class HeapProfileTracker; 56 class PerfSampleTracker; 57 class MetadataTracker; 58 class PacketAnalyzer; 59 class ProtoImporterModule; 60 class TrackEventModule; 61 class ProcessTracker; 62 class SliceTracker; 63 class SliceTranslationTable; 64 class FlowTracker; 65 class TraceParser; 66 class TraceSorter; 67 class TraceStorage; 68 class TrackTracker; 69 class DescriptorPool; 70 71 class TraceProcessorContext { 72 public: 73 TraceProcessorContext(); 74 ~TraceProcessorContext(); 75 76 TraceProcessorContext(TraceProcessorContext&&) = default; 77 TraceProcessorContext& operator=(TraceProcessorContext&&) = default; 78 79 Config config; 80 81 std::unique_ptr<TraceStorage> storage; 82 83 std::unique_ptr<ChunkedTraceReader> chunk_reader; 84 std::unique_ptr<TraceSorter> sorter; 85 86 // Keep the global tracker before the args tracker as we access the global 87 // tracker in the destructor of the args tracker. Also keep it before other 88 // trackers, as they may own ArgsTrackers themselves. 89 std::unique_ptr<GlobalArgsTracker> global_args_tracker; 90 std::unique_ptr<ArgsTracker> args_tracker; 91 std::unique_ptr<ArgsTranslationTable> args_translation_table; 92 93 std::unique_ptr<TrackTracker> track_tracker; 94 std::unique_ptr<AsyncTrackSetTracker> async_track_set_tracker; 95 std::unique_ptr<SliceTracker> slice_tracker; 96 std::unique_ptr<SliceTranslationTable> slice_translation_table; 97 std::unique_ptr<FlowTracker> flow_tracker; 98 std::unique_ptr<ProcessTracker> process_tracker; 99 std::unique_ptr<EventTracker> event_tracker; 100 std::unique_ptr<ClockTracker> clock_tracker; 101 std::unique_ptr<ClockConverter> clock_converter; 102 std::unique_ptr<HeapProfileTracker> heap_profile_tracker; 103 std::unique_ptr<PerfSampleTracker> perf_sample_tracker; 104 std::unique_ptr<GlobalStackProfileTracker> global_stack_profile_tracker; 105 std::unique_ptr<MetadataTracker> metadata_tracker; 106 107 // These fields are stored as pointers to Destructible objects rather than 108 // their actual type (a subclass of Destructible), as the concrete subclass 109 // type is only available in storage_full target. To access these fields use 110 // the GetOrCreate() method on their subclass type, e.g. 111 // SyscallTracker::GetOrCreate(context) 112 std::unique_ptr<Destructible> android_probes_tracker; // AndroidProbesTracker 113 std::unique_ptr<Destructible> binder_tracker; // BinderTracker 114 std::unique_ptr<Destructible> heap_graph_tracker; // HeapGraphTracker 115 std::unique_ptr<Destructible> sched_tracker; // SchedEventTracker 116 std::unique_ptr<Destructible> syscall_tracker; // SyscallTracker 117 std::unique_ptr<Destructible> system_info_tracker; // SystemInfoTracker 118 std::unique_ptr<Destructible> v4l2_tracker; // V4l2Tracker 119 std::unique_ptr<Destructible> virtio_video_tracker; // VirtioVideoTracker 120 std::unique_ptr<Destructible> systrace_parser; // SystraceParser 121 std::unique_ptr<Destructible> thread_state_tracker; // ThreadStateTracker 122 std::unique_ptr<Destructible> i2c_tracker; // I2CTracker 123 std::unique_ptr<Destructible> content_analyzer; 124 125 // These fields are trace readers which will be called by |forwarding_parser| 126 // once the format of the trace is discovered. They are placed here as they 127 // are only available in the lib target. 128 std::unique_ptr<ChunkedTraceReader> json_trace_tokenizer; 129 std::unique_ptr<ChunkedTraceReader> fuchsia_trace_tokenizer; 130 std::unique_ptr<ChunkedTraceReader> ninja_log_parser; 131 std::unique_ptr<ChunkedTraceReader> android_bugreport_parser; 132 std::unique_ptr<ChunkedTraceReader> systrace_trace_parser; 133 std::unique_ptr<ChunkedTraceReader> gzip_trace_parser; 134 135 // These fields are trace parsers which will be called by |forwarding_parser| 136 // once the format of the trace is discovered. They are placed here as they 137 // are only available in the lib target. 138 std::unique_ptr<TraceParser> json_trace_parser; 139 std::unique_ptr<TraceParser> fuchsia_trace_parser; 140 141 // This field contains the list of proto descriptors that can be used by 142 // reflection-based parsers. 143 std::unique_ptr<DescriptorPool> descriptor_pool_; 144 145 // The module at the index N is registered to handle field id N in 146 // TracePacket. 147 std::vector<std::vector<ProtoImporterModule*>> modules_by_field; 148 std::vector<std::unique_ptr<ProtoImporterModule>> modules; 149 // Pointers to modules from the modules vector that need to be called for 150 // all fields. 151 std::vector<ProtoImporterModule*> modules_for_all_fields; 152 FtraceModule* ftrace_module = nullptr; 153 TrackEventModule* track_module = nullptr; 154 155 // Marks whether the uuid was read from the trace. 156 // If the uuid was NOT read, the uuid will be made from the hash of the first 157 // 4KB of the trace. 158 bool uuid_found_in_trace = false; 159 160 TraceType trace_type = kUnknownTraceType; 161 }; 162 163 } // namespace trace_processor 164 } // namespace perfetto 165 166 #endif // SRC_TRACE_PROCESSOR_TYPES_TRACE_PROCESSOR_CONTEXT_H_ 167