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/trace_processor/types/trace_processor_context.h" 18 19 #include <memory> 20 #include <optional> 21 22 #include "src/trace_processor/forwarding_trace_parser.h" 23 #include "src/trace_processor/importers/common/args_tracker.h" 24 #include "src/trace_processor/importers/common/args_translation_table.h" 25 #include "src/trace_processor/importers/common/clock_converter.h" 26 #include "src/trace_processor/importers/common/clock_tracker.h" 27 #include "src/trace_processor/importers/common/cpu_tracker.h" 28 #include "src/trace_processor/importers/common/event_tracker.h" 29 #include "src/trace_processor/importers/common/flow_tracker.h" 30 #include "src/trace_processor/importers/common/global_args_tracker.h" 31 #include "src/trace_processor/importers/common/legacy_v8_cpu_profile_tracker.h" 32 #include "src/trace_processor/importers/common/machine_tracker.h" 33 #include "src/trace_processor/importers/common/mapping_tracker.h" 34 #include "src/trace_processor/importers/common/metadata_tracker.h" 35 #include "src/trace_processor/importers/common/process_track_translation_table.h" 36 #include "src/trace_processor/importers/common/process_tracker.h" 37 #include "src/trace_processor/importers/common/sched_event_tracker.h" 38 #include "src/trace_processor/importers/common/slice_tracker.h" 39 #include "src/trace_processor/importers/common/slice_translation_table.h" 40 #include "src/trace_processor/importers/common/stack_profile_tracker.h" 41 #include "src/trace_processor/importers/common/trace_file_tracker.h" 42 #include "src/trace_processor/importers/common/track_compressor.h" 43 #include "src/trace_processor/importers/common/track_tracker.h" 44 #include "src/trace_processor/importers/proto/multi_machine_trace_manager.h" 45 #include "src/trace_processor/importers/proto/perf_sample_tracker.h" 46 #include "src/trace_processor/importers/proto/proto_importer_module.h" 47 #include "src/trace_processor/storage/trace_storage.h" 48 #include "src/trace_processor/trace_reader_registry.h" 49 50 namespace perfetto::trace_processor { 51 TraceProcessorContext(const InitArgs & args)52TraceProcessorContext::TraceProcessorContext(const InitArgs& args) 53 : config(args.config), storage(args.storage) { 54 reader_registry = std::make_unique<TraceReaderRegistry>(this); 55 // Init the trackers. 56 machine_tracker = std::make_unique<MachineTracker>(this, args.raw_machine_id); 57 if (!machine_id()) { 58 multi_machine_trace_manager = 59 std::make_unique<MultiMachineTraceManager>(this); 60 } 61 track_tracker = std::make_unique<TrackTracker>(this); 62 track_compressor = std::make_unique<TrackCompressor>(this); 63 args_tracker = std::make_unique<ArgsTracker>(this); 64 args_translation_table = 65 std::make_unique<ArgsTranslationTable>(storage.get()); 66 slice_tracker = std::make_unique<SliceTracker>(this); 67 slice_translation_table = 68 std::make_unique<SliceTranslationTable>(storage.get()); 69 flow_tracker = std::make_unique<FlowTracker>(this); 70 event_tracker = std::make_unique<EventTracker>(this); 71 sched_event_tracker = std::make_unique<SchedEventTracker>(this); 72 process_tracker = std::make_unique<ProcessTracker>(this); 73 process_track_translation_table = 74 std::make_unique<ProcessTrackTranslationTable>(storage.get()); 75 clock_tracker = std::make_unique<ClockTracker>(this); 76 clock_converter = std::make_unique<ClockConverter>(this); 77 mapping_tracker = std::make_unique<MappingTracker>(this); 78 perf_sample_tracker = std::make_unique<PerfSampleTracker>(this); 79 stack_profile_tracker = std::make_unique<StackProfileTracker>(this); 80 metadata_tracker = std::make_unique<MetadataTracker>(storage.get()); 81 cpu_tracker = std::make_unique<CpuTracker>(this); 82 global_args_tracker = std::make_shared<GlobalArgsTracker>(storage.get()); 83 descriptor_pool_ = std::make_unique<DescriptorPool>(); 84 85 slice_tracker->SetOnSliceBeginCallback( 86 [this](TrackId track_id, SliceId slice_id) { 87 flow_tracker->ClosePendingEventsOnTrack(track_id, slice_id); 88 }); 89 90 trace_file_tracker = std::make_unique<TraceFileTracker>(this); 91 legacy_v8_cpu_profile_tracker = 92 std::make_unique<LegacyV8CpuProfileTracker>(this); 93 } 94 95 TraceProcessorContext::TraceProcessorContext() = default; 96 TraceProcessorContext::~TraceProcessorContext() = default; 97 98 TraceProcessorContext::TraceProcessorContext(TraceProcessorContext&&) = default; 99 TraceProcessorContext& TraceProcessorContext::operator=( 100 TraceProcessorContext&&) = default; 101 machine_id() const102std::optional<MachineId> TraceProcessorContext::machine_id() const { 103 if (!machine_tracker) { 104 // Doesn't require that |machine_tracker| is initialzed, e.g. in unit tests. 105 return std::nullopt; 106 } 107 return machine_tracker->machine_id(); 108 } 109 110 } // namespace perfetto::trace_processor 111