blob: ed3e43ea29ce94159da688e391d6a911b1f2c8c8 [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"
Lalit Magantieb63b082020-09-10 14:12:20 +010027
28namespace protozero {
29struct ConstBytes;
30}
31
32namespace perfetto {
33
34namespace protos {
35namespace pbzero {
36class TracePacket_Decoder;
Lalit Maganti88eb6982021-03-01 14:28:51 +000037class TraceConfig_Decoder;
Lalit Magantieb63b082020-09-10 14:12:20 +010038} // namespace pbzero
39} // namespace protos
40
41namespace trace_processor {
42
43class PacketSequenceState;
44class TraceProcessorContext;
45class TraceSorter;
46class TraceStorage;
47
48// Implementation of ChunkedTraceReader for proto traces. Tokenizes a proto
49// trace into packets, handles parsing of any packets which need to be
50// handled in trace-order and passes the remainder to TraceSorter to sort
51// into timestamp order.
52class ProtoTraceReader : public ChunkedTraceReader {
53 public:
54 // |reader| is the abstract method of getting chunks of size |chunk_size_b|
55 // from a trace file with these chunks parsed into |trace|.
56 explicit ProtoTraceReader(TraceProcessorContext*);
57 ~ProtoTraceReader() override;
58
59 // ChunkedTraceReader implementation.
Primiano Tucci3264b592021-11-08 18:20:51 +000060 util::Status Parse(TraceBlobView) override;
Lalit Magantieb63b082020-09-10 14:12:20 +010061 void NotifyEndOfFile() override;
62
63 private:
64 using ConstBytes = protozero::ConstBytes;
65 util::Status ParsePacket(TraceBlobView);
66 util::Status ParseServiceEvent(int64_t ts, ConstBytes);
67 util::Status ParseClockSnapshot(ConstBytes blob, uint32_t seq_id);
68 void HandleIncrementalStateCleared(
69 const protos::pbzero::TracePacket_Decoder&);
70 void HandlePreviousPacketDropped(const protos::pbzero::TracePacket_Decoder&);
71 void ParseTracePacketDefaults(const protos::pbzero::TracePacket_Decoder&,
72 TraceBlobView trace_packet_defaults);
73 void ParseInternedData(const protos::pbzero::TracePacket_Decoder&,
74 TraceBlobView interned_data);
Lalit Maganti88eb6982021-03-01 14:28:51 +000075 void ParseTraceConfig(ConstBytes);
76
Lalit Maganti710fbbb2021-05-14 17:48:01 +010077 base::Optional<StringId> GetBuiltinClockNameOrNull(uint64_t clock_id);
78
Lalit Magantieb63b082020-09-10 14:12:20 +010079 PacketSequenceState* GetIncrementalStateForPacketSequence(
80 uint32_t sequence_id) {
81 if (!incremental_state)
82 incremental_state.reset(new ProtoIncrementalState(context_));
83 return incremental_state->GetOrCreateStateForPacketSequence(sequence_id);
84 }
85 util::Status ParseExtensionDescriptor(ConstBytes descriptor);
86
87 TraceProcessorContext* context_;
88
89 ProtoTraceTokenizer tokenizer_;
90
91 // Temporary. Currently trace packets do not have a timestamp, so the
92 // timestamp given is latest_timestamp_.
93 int64_t latest_timestamp_ = 0;
94
95 // Stores incremental state and references to interned data, e.g. for track
96 // event protos.
97 std::unique_ptr<ProtoIncrementalState> incremental_state;
98};
99
100} // namespace trace_processor
101} // namespace perfetto
102
103#endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_READER_H_