Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 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 | |
Eric Seckler | 137a467 | 2019-10-24 08:51:14 +0100 | [diff] [blame] | 17 | #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_TOKENIZER_H_ |
| 18 | #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_TOKENIZER_H_ |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <memory> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include "src/trace_processor/chunked_trace_reader.h" |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 26 | #include "src/trace_processor/importers/proto/proto_incremental_state.h" |
| 27 | #include "src/trace_processor/trace_blob_view.h" |
Eric Seckler | 684a4f7 | 2019-04-26 14:34:07 +0100 | [diff] [blame] | 28 | |
Primiano Tucci | 6756fb0 | 2019-08-14 15:49:18 +0200 | [diff] [blame] | 29 | namespace protozero { |
| 30 | struct ConstBytes; |
| 31 | } |
| 32 | |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 33 | namespace perfetto { |
Eric Seckler | d2af989 | 2019-11-01 10:10:53 +0000 | [diff] [blame] | 34 | |
| 35 | namespace protos { |
| 36 | namespace pbzero { |
| 37 | class TracePacket_Decoder; |
| 38 | } // namespace pbzero |
| 39 | } // namespace protos |
| 40 | |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 41 | namespace trace_processor { |
| 42 | |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 43 | class PacketSequenceState; |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 44 | class TraceProcessorContext; |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 45 | class TraceSorter; |
Primiano Tucci | 0e38a14 | 2019-01-07 20:51:09 +0000 | [diff] [blame] | 46 | class TraceStorage; |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 47 | |
| 48 | // Reads a protobuf trace in chunks and extracts boundaries of trace packets |
| 49 | // (or subfields, for the case of ftrace) with their timestamps. |
| 50 | class ProtoTraceTokenizer : public ChunkedTraceReader { |
| 51 | public: |
| 52 | // |reader| is the abstract method of getting chunks of size |chunk_size_b| |
| 53 | // from a trace file with these chunks parsed into |trace|. |
| 54 | explicit ProtoTraceTokenizer(TraceProcessorContext*); |
| 55 | ~ProtoTraceTokenizer() override; |
| 56 | |
| 57 | // ChunkedTraceReader implementation. |
Lalit Maganti | d71a945 | 2019-05-09 15:13:24 +0100 | [diff] [blame] | 58 | util::Status Parse(std::unique_ptr<uint8_t[]>, size_t size) override; |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 59 | |
| 60 | private: |
Primiano Tucci | 6756fb0 | 2019-08-14 15:49:18 +0200 | [diff] [blame] | 61 | using ConstBytes = protozero::ConstBytes; |
Lalit Maganti | d71a945 | 2019-05-09 15:13:24 +0100 | [diff] [blame] | 62 | util::Status ParseInternal(std::unique_ptr<uint8_t[]> owned_buf, |
| 63 | uint8_t* data, |
| 64 | size_t size); |
| 65 | util::Status ParsePacket(TraceBlobView); |
Primiano Tucci | 6756fb0 | 2019-08-14 15:49:18 +0200 | [diff] [blame] | 66 | util::Status ParseClockSnapshot(ConstBytes blob, uint32_t seq_id); |
Eric Seckler | 684a4f7 | 2019-04-26 14:34:07 +0100 | [diff] [blame] | 67 | void HandleIncrementalStateCleared( |
Eric Seckler | d2af989 | 2019-11-01 10:10:53 +0000 | [diff] [blame] | 68 | const protos::pbzero::TracePacket_Decoder&); |
| 69 | void HandlePreviousPacketDropped(const protos::pbzero::TracePacket_Decoder&); |
| 70 | void ParseInternedData(const protos::pbzero::TracePacket_Decoder&, |
Primiano Tucci | 6756fb0 | 2019-08-14 15:49:18 +0200 | [diff] [blame] | 71 | TraceBlobView interned_data); |
Eric Seckler | 771960c | 2019-10-22 15:37:12 +0100 | [diff] [blame] | 72 | PacketSequenceState* GetIncrementalStateForPacketSequence( |
| 73 | uint32_t sequence_id) { |
Eric Seckler | 684a4f7 | 2019-04-26 14:34:07 +0100 | [diff] [blame] | 74 | if (!incremental_state) |
Eric Seckler | 02cdcef | 2019-10-14 08:56:28 +0100 | [diff] [blame] | 75 | incremental_state.reset(new ProtoIncrementalState(context_)); |
Eric Seckler | 684a4f7 | 2019-04-26 14:34:07 +0100 | [diff] [blame] | 76 | return incremental_state->GetOrCreateStateForPacketSequence(sequence_id); |
| 77 | } |
| 78 | |
Deepanjan Roy | 01994ca | 2019-04-02 11:05:34 -0700 | [diff] [blame] | 79 | TraceProcessorContext* context_; |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 80 | |
| 81 | // Used to glue together trace packets that span across two (or more) |
| 82 | // Parse() boundaries. |
| 83 | std::vector<uint8_t> partial_buf_; |
| 84 | |
| 85 | // Temporary. Currently trace packets do not have a timestamp, so the |
Lalit Maganti | fa21a28 | 2019-01-17 19:03:04 +0000 | [diff] [blame] | 86 | // timestamp given is latest_timestamp_. |
| 87 | int64_t latest_timestamp_ = 0; |
Eric Seckler | 684a4f7 | 2019-04-26 14:34:07 +0100 | [diff] [blame] | 88 | |
| 89 | // Stores incremental state and references to interned data, e.g. for track |
| 90 | // event protos. |
| 91 | std::unique_ptr<ProtoIncrementalState> incremental_state; |
Primiano Tucci | d933d91 | 2018-09-04 09:15:07 +0100 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace trace_processor |
| 95 | } // namespace perfetto |
| 96 | |
Eric Seckler | 137a467 | 2019-10-24 08:51:14 +0100 | [diff] [blame] | 97 | #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_TOKENIZER_H_ |