Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 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 | #include "src/trace_processor/trace_processor_storage_impl.h" |
| 18 | |
| 19 | #include "perfetto/base/logging.h" |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 20 | #include "src/trace_processor/forwarding_trace_parser.h" |
Alexander Timin | 5a99b5c | 2021-05-11 22:48:07 +0000 | [diff] [blame] | 21 | #include "src/trace_processor/importers/chrome_track_event.descriptor.h" |
Lalit Maganti | 617deae | 2020-04-14 21:00:49 +0100 | [diff] [blame] | 22 | #include "src/trace_processor/importers/common/args_tracker.h" |
Lalit Maganti | d5c45f4 | 2020-04-14 21:01:50 +0100 | [diff] [blame] | 23 | #include "src/trace_processor/importers/common/clock_tracker.h" |
| 24 | #include "src/trace_processor/importers/common/event_tracker.h" |
AndrewB330 | c879ea4 | 2020-07-29 14:12:39 +0300 | [diff] [blame] | 25 | #include "src/trace_processor/importers/common/flow_tracker.h" |
Lalit Maganti | 617deae | 2020-04-14 21:00:49 +0100 | [diff] [blame] | 26 | #include "src/trace_processor/importers/common/process_tracker.h" |
Lalit Maganti | d5c45f4 | 2020-04-14 21:01:50 +0100 | [diff] [blame] | 27 | #include "src/trace_processor/importers/common/slice_tracker.h" |
Lalit Maganti | 617deae | 2020-04-14 21:00:49 +0100 | [diff] [blame] | 28 | #include "src/trace_processor/importers/common/track_tracker.h" |
Lalit Maganti | 60af4ef | 2020-04-15 14:27:09 +0100 | [diff] [blame] | 29 | #include "src/trace_processor/importers/default_modules.h" |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 30 | #include "src/trace_processor/importers/proto/async_track_set_tracker.h" |
Lalit Maganti | 05819e2 | 2020-04-14 21:01:38 +0100 | [diff] [blame] | 31 | #include "src/trace_processor/importers/proto/heap_profile_tracker.h" |
| 32 | #include "src/trace_processor/importers/proto/metadata_tracker.h" |
Ryan Savitski | c6c7e84 | 2021-03-10 14:26:59 +0000 | [diff] [blame] | 33 | #include "src/trace_processor/importers/proto/perf_sample_tracker.h" |
Lalit Maganti | 0faddc4 | 2020-04-10 17:58:24 +0100 | [diff] [blame] | 34 | #include "src/trace_processor/importers/proto/proto_importer_module.h" |
Lalit Maganti | eb63b08 | 2020-09-10 14:12:20 +0100 | [diff] [blame] | 35 | #include "src/trace_processor/importers/proto/proto_trace_reader.h" |
Lalit Maganti | 05819e2 | 2020-04-14 21:01:38 +0100 | [diff] [blame] | 36 | #include "src/trace_processor/importers/proto/stack_profile_tracker.h" |
Alexander Timin | 5a99b5c | 2021-05-11 22:48:07 +0000 | [diff] [blame] | 37 | #include "src/trace_processor/importers/track_event.descriptor.h" |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 38 | #include "src/trace_processor/trace_sorter.h" |
Alexander Timin | 5a99b5c | 2021-05-11 22:48:07 +0000 | [diff] [blame] | 39 | #include "src/trace_processor/util/descriptors.h" |
Alexander Timin | 97d8785 | 2021-05-17 18:01:33 +0000 | [diff] [blame^] | 40 | #include "src/trace_processor/util/trace_blob_view.h" |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 41 | |
| 42 | namespace perfetto { |
| 43 | namespace trace_processor { |
| 44 | |
| 45 | TraceProcessorStorageImpl::TraceProcessorStorageImpl(const Config& cfg) { |
| 46 | context_.config = cfg; |
Lalit Maganti | 88eb698 | 2021-03-01 14:28:51 +0000 | [diff] [blame] | 47 | |
Eric Seckler | 0eccc52 | 2019-12-04 11:21:21 +0000 | [diff] [blame] | 48 | context_.storage.reset(new TraceStorage(context_.config)); |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 49 | context_.track_tracker.reset(new TrackTracker(&context_)); |
Lalit Maganti | f7a1a73 | 2020-10-12 15:42:34 +0100 | [diff] [blame] | 50 | context_.async_track_set_tracker.reset(new AsyncTrackSetTracker(&context_)); |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 51 | context_.args_tracker.reset(new ArgsTracker(&context_)); |
| 52 | context_.slice_tracker.reset(new SliceTracker(&context_)); |
AndrewB330 | c879ea4 | 2020-07-29 14:12:39 +0300 | [diff] [blame] | 53 | context_.flow_tracker.reset(new FlowTracker(&context_)); |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 54 | context_.event_tracker.reset(new EventTracker(&context_)); |
| 55 | context_.process_tracker.reset(new ProcessTracker(&context_)); |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 56 | context_.clock_tracker.reset(new ClockTracker(&context_)); |
| 57 | context_.heap_profile_tracker.reset(new HeapProfileTracker(&context_)); |
Ryan Savitski | c6c7e84 | 2021-03-10 14:26:59 +0000 | [diff] [blame] | 58 | context_.perf_sample_tracker.reset(new PerfSampleTracker(&context_)); |
Florian Mayer | 2266874 | 2020-08-13 10:39:41 +0100 | [diff] [blame] | 59 | context_.global_stack_profile_tracker.reset(new GlobalStackProfileTracker()); |
Lalit Maganti | ededb0e | 2020-01-08 12:50:34 +0000 | [diff] [blame] | 60 | context_.metadata_tracker.reset(new MetadataTracker(&context_)); |
Lalit Maganti | 1908e26 | 2020-01-09 14:33:19 +0000 | [diff] [blame] | 61 | context_.global_args_tracker.reset(new GlobalArgsTracker(&context_)); |
Alexander Timin | 5a99b5c | 2021-05-11 22:48:07 +0000 | [diff] [blame] | 62 | { |
| 63 | context_.descriptor_pool_.reset(new DescriptorPool()); |
| 64 | auto status = context_.descriptor_pool_->AddFromFileDescriptorSet( |
| 65 | kTrackEventDescriptor.data(), kTrackEventDescriptor.size()); |
| 66 | |
| 67 | PERFETTO_DCHECK(status.ok()); |
| 68 | |
| 69 | status = context_.descriptor_pool_->AddFromFileDescriptorSet( |
| 70 | kChromeTrackEventDescriptor.data(), kChromeTrackEventDescriptor.size()); |
| 71 | |
| 72 | PERFETTO_DCHECK(status.ok()); |
| 73 | } |
Mikhail Khokhlov | dd1db00 | 2019-12-09 16:34:07 +0000 | [diff] [blame] | 74 | |
AndrewB330 | c879ea4 | 2020-07-29 14:12:39 +0300 | [diff] [blame] | 75 | context_.slice_tracker->SetOnSliceBeginCallback( |
| 76 | [this](TrackId track_id, SliceId slice_id) { |
| 77 | context_.flow_tracker->ClosePendingEventsOnTrack(track_id, slice_id); |
| 78 | }); |
| 79 | |
Eric Seckler | f2de4db | 2020-02-14 14:17:20 +0000 | [diff] [blame] | 80 | RegisterDefaultModules(&context_); |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | TraceProcessorStorageImpl::~TraceProcessorStorageImpl() {} |
| 84 | |
| 85 | util::Status TraceProcessorStorageImpl::Parse(std::unique_ptr<uint8_t[]> data, |
| 86 | size_t size) { |
| 87 | if (size == 0) |
| 88 | return util::OkStatus(); |
| 89 | if (unrecoverable_parse_error_) |
| 90 | return util::ErrStatus( |
| 91 | "Failed unrecoverably while parsing in a previous Parse call"); |
| 92 | if (!context_.chunk_reader) |
| 93 | context_.chunk_reader.reset(new ForwardingTraceParser(&context_)); |
| 94 | |
| 95 | auto scoped_trace = context_.storage->TraceExecutionTimeIntoStats( |
| 96 | stats::parse_trace_duration_ns); |
| 97 | util::Status status = context_.chunk_reader->Parse(std::move(data), size); |
| 98 | unrecoverable_parse_error_ |= !status.ok(); |
| 99 | return status; |
| 100 | } |
| 101 | |
| 102 | void TraceProcessorStorageImpl::NotifyEndOfFile() { |
| 103 | if (unrecoverable_parse_error_ || !context_.chunk_reader) |
| 104 | return; |
| 105 | |
Primiano Tucci | 40da82f | 2020-02-13 18:04:35 +0000 | [diff] [blame] | 106 | context_.chunk_reader->NotifyEndOfFile(); |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 107 | if (context_.sorter) |
| 108 | context_.sorter->ExtractEventsForced(); |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 109 | context_.event_tracker->FlushPendingEvents(); |
| 110 | context_.slice_tracker->FlushPendingSlices(); |
Florian Mayer | 0b6655d | 2020-02-14 09:09:21 -0500 | [diff] [blame] | 111 | context_.heap_profile_tracker->NotifyEndOfFile(); |
Eric Seckler | fbbf022 | 2020-07-23 17:26:29 +0100 | [diff] [blame] | 112 | context_.process_tracker->NotifyEndOfFile(); |
Florian Mayer | 0b6655d | 2020-02-14 09:09:21 -0500 | [diff] [blame] | 113 | for (std::unique_ptr<ProtoImporterModule>& module : context_.modules) { |
| 114 | module->NotifyEndOfFile(); |
| 115 | } |
Sylwester Blaszczyk | 76aa700 | 2020-11-27 15:48:21 +0100 | [diff] [blame] | 116 | context_.args_tracker->Flush(); |
Eric Seckler | a7870e6 | 2019-11-01 10:11:58 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | } // namespace trace_processor |
| 120 | } // namespace perfetto |