Eric Seckler | de58995 | 2019-10-17 12:46:07 +0100 | [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 | #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_MODULE_H_ |
| 18 | #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_MODULE_H_ |
| 19 | |
| 20 | #include "perfetto/base/build_config.h" |
| 21 | #include "src/trace_processor/importers/proto/proto_importer_module.h" |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 22 | #include "src/trace_processor/importers/proto/track_event_parser.h" |
| 23 | #include "src/trace_processor/importers/proto/track_event_tokenizer.h" |
| 24 | #include "src/trace_processor/timestamped_trace_piece.h" |
Eric Seckler | de58995 | 2019-10-17 12:46:07 +0100 | [diff] [blame] | 25 | |
Eric Seckler | d2af989 | 2019-11-01 10:10:53 +0000 | [diff] [blame] | 26 | #include "protos/perfetto/config/trace_config.pbzero.h" |
| 27 | #include "protos/perfetto/trace/trace_packet.pbzero.h" |
| 28 | |
Eric Seckler | de58995 | 2019-10-17 12:46:07 +0100 | [diff] [blame] | 29 | namespace perfetto { |
| 30 | namespace trace_processor { |
| 31 | |
| 32 | class TrackEventModule : public ProtoImporterModuleBase</*IsEnabled=*/1> { |
| 33 | public: |
| 34 | explicit TrackEventModule(TraceProcessorContext* context) |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 35 | : ProtoImporterModuleBase(context), |
| 36 | tokenizer_(context), |
| 37 | parser_(context) {} |
Eric Seckler | de58995 | 2019-10-17 12:46:07 +0100 | [diff] [blame] | 38 | |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 39 | ModuleResult TokenizePacket( |
| 40 | const protos::pbzero::TracePacket::Decoder& decoder, |
| 41 | TraceBlobView* packet, |
| 42 | int64_t packet_timestamp, |
| 43 | PacketSequenceState* state) { |
| 44 | if (decoder.has_track_descriptor()) { |
| 45 | tokenizer_.TokenizeTrackDescriptorPacket(decoder); |
| 46 | return ModuleResult::Handled(); |
| 47 | } |
| 48 | |
| 49 | if (decoder.has_track_event()) { |
| 50 | tokenizer_.TokenizeTrackEventPacket(state, decoder, packet, |
| 51 | packet_timestamp); |
| 52 | return ModuleResult::Handled(); |
| 53 | } |
| 54 | |
| 55 | // TODO(eseckler): Remove these once Chrome has switched fully over to |
| 56 | // TrackDescriptors. |
| 57 | if (decoder.has_thread_descriptor()) { |
| 58 | tokenizer_.TokenizeThreadDescriptorPacket(state, decoder); |
| 59 | return ModuleResult::Handled(); |
| 60 | } |
| 61 | if (decoder.has_process_descriptor()) { |
| 62 | tokenizer_.TokenizeProcessDescriptorPacket(decoder); |
| 63 | return ModuleResult::Handled(); |
| 64 | } |
| 65 | |
Eric Seckler | de58995 | 2019-10-17 12:46:07 +0100 | [diff] [blame] | 66 | return ModuleResult::Ignored(); |
| 67 | } |
| 68 | |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 69 | ModuleResult ParsePacket(const protos::pbzero::TracePacket::Decoder& decoder, |
| 70 | const TimestampedTracePiece& ttp) { |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 71 | if (decoder.has_track_event()) { |
| 72 | parser_.ParseTrackEvent( |
| 73 | ttp.timestamp, ttp.thread_timestamp, ttp.thread_instruction_count, |
| 74 | ttp.packet_sequence_state, ttp.packet_sequence_state_generation, |
| 75 | decoder.track_event()); |
| 76 | return ModuleResult::Handled(); |
| 77 | } |
Eric Seckler | de58995 | 2019-10-17 12:46:07 +0100 | [diff] [blame] | 78 | return ModuleResult::Ignored(); |
| 79 | } |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 80 | |
| 81 | private: |
| 82 | TrackEventTokenizer tokenizer_; |
| 83 | TrackEventParser parser_; |
Eric Seckler | de58995 | 2019-10-17 12:46:07 +0100 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace trace_processor |
| 87 | } // namespace perfetto |
| 88 | |
| 89 | #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_MODULE_H_ |