blob: 9f7a40350c0b9dcca4de19ffba5b43f6a677f76a [file] [log] [blame]
Lalit Magantieb63b082020-09-10 14:12:20 +01001/*
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_IMPORTERS_PROTO_PROTO_TRACE_READER_H_
18#define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_READER_H_
19
20#include <stdint.h>
21
22#include <memory>
23
Lalit Maganti1534bb72021-04-23 14:11:26 +010024#include "src/trace_processor/importers/common/chunked_trace_reader.h"
Lalit Magantieb63b082020-09-10 14:12:20 +010025#include "src/trace_processor/importers/proto/proto_incremental_state.h"
26#include "src/trace_processor/importers/proto/proto_trace_tokenizer.h"
Alexander Timin97d87852021-05-17 18:01:33 +000027#include "src/trace_processor/util/trace_blob_view.h"
Lalit Magantieb63b082020-09-10 14:12:20 +010028
29namespace protozero {
30struct ConstBytes;
31}
32
33namespace perfetto {
34
35namespace protos {
36namespace pbzero {
37class TracePacket_Decoder;
Lalit Maganti88eb6982021-03-01 14:28:51 +000038class TraceConfig_Decoder;
Lalit Magantieb63b082020-09-10 14:12:20 +010039} // namespace pbzero
40} // namespace protos
41
42namespace trace_processor {
43
44class PacketSequenceState;
45class TraceProcessorContext;
46class TraceSorter;
47class TraceStorage;
48
49// Implementation of ChunkedTraceReader for proto traces. Tokenizes a proto
50// trace into packets, handles parsing of any packets which need to be
51// handled in trace-order and passes the remainder to TraceSorter to sort
52// into timestamp order.
53class ProtoTraceReader : public ChunkedTraceReader {
54 public:
55 // |reader| is the abstract method of getting chunks of size |chunk_size_b|
56 // from a trace file with these chunks parsed into |trace|.
57 explicit ProtoTraceReader(TraceProcessorContext*);
58 ~ProtoTraceReader() override;
59
60 // ChunkedTraceReader implementation.
61 util::Status Parse(std::unique_ptr<uint8_t[]>, size_t size) override;
62 void NotifyEndOfFile() override;
63
64 private:
65 using ConstBytes = protozero::ConstBytes;
66 util::Status ParsePacket(TraceBlobView);
67 util::Status ParseServiceEvent(int64_t ts, ConstBytes);
68 util::Status ParseClockSnapshot(ConstBytes blob, uint32_t seq_id);
69 void HandleIncrementalStateCleared(
70 const protos::pbzero::TracePacket_Decoder&);
71 void HandlePreviousPacketDropped(const protos::pbzero::TracePacket_Decoder&);
72 void ParseTracePacketDefaults(const protos::pbzero::TracePacket_Decoder&,
73 TraceBlobView trace_packet_defaults);
74 void ParseInternedData(const protos::pbzero::TracePacket_Decoder&,
75 TraceBlobView interned_data);
Lalit Maganti88eb6982021-03-01 14:28:51 +000076 void ParseTraceConfig(ConstBytes);
77
Lalit Magantieb63b082020-09-10 14:12:20 +010078 PacketSequenceState* GetIncrementalStateForPacketSequence(
79 uint32_t sequence_id) {
80 if (!incremental_state)
81 incremental_state.reset(new ProtoIncrementalState(context_));
82 return incremental_state->GetOrCreateStateForPacketSequence(sequence_id);
83 }
84 util::Status ParseExtensionDescriptor(ConstBytes descriptor);
85
86 TraceProcessorContext* context_;
87
88 ProtoTraceTokenizer tokenizer_;
89
90 // Temporary. Currently trace packets do not have a timestamp, so the
91 // timestamp given is latest_timestamp_.
92 int64_t latest_timestamp_ = 0;
93
94 // Stores incremental state and references to interned data, e.g. for track
95 // event protos.
96 std::unique_ptr<ProtoIncrementalState> incremental_state;
97};
98
99} // namespace trace_processor
100} // namespace perfetto
101
102#endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_READER_H_