xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/proto/args_parser.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 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_ARGS_PARSER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_ARGS_PARSER_H_
19 
20 #include "src/trace_processor/importers/common/args_tracker.h"
21 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h"
22 #include "src/trace_processor/types/trace_processor_context.h"
23 #include "src/trace_processor/util/proto_to_args_parser.h"
24 
25 namespace perfetto::trace_processor {
26 
27 // A ProtoToArgsParser::Delegate that writes the parsed proto data into
28 // TraceStorage after interning key strings.
29 class ArgsParser : public util::ProtoToArgsParser::Delegate {
30  public:
31   using Key = util::ProtoToArgsParser::Key;
32 
33   ArgsParser(int64_t packet_timestamp,
34                       ArgsTracker::BoundInserter& inserter,
35                       TraceStorage& storage,
36                       PacketSequenceStateGeneration* sequence_state = nullptr,
37                       bool support_json = false);
38   ~ArgsParser() override;
39   void AddInteger(const Key&, int64_t) override;
40   void AddUnsignedInteger(const Key&, uint64_t) override;
41   void AddString(const Key&, const protozero::ConstChars&) override;
42   void AddString(const Key&, const std::string&) override;
43   void AddDouble(const Key&, double) override;
44   void AddPointer(const Key&, const void*) override;
45   void AddBoolean(const Key&, bool) override;
46   void AddBytes(const Key&, const protozero::ConstBytes&) override;
47   bool AddJson(const Key&, const protozero::ConstChars&) override;
48   void AddNull(const Key&) override;
49   size_t GetArrayEntryIndex(const std::string& array_key) override;
50   size_t IncrementArrayEntryIndex(const std::string& array_key) override;
51   int64_t packet_timestamp() override;
52   PacketSequenceStateGeneration* seq_state() override;
53 
54  protected:
55   InternedMessageView* GetInternedMessageView(uint32_t field_id,
56                                               uint64_t iid) override;
57 
58  private:
59   const bool support_json_;
60   const int64_t packet_timestamp_;
61   PacketSequenceStateGeneration* const sequence_state_;
62   ArgsTracker::BoundInserter& inserter_;
63   TraceStorage& storage_;
64 };
65 
66 }  // namespace perfetto::trace_processor
67 
68 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_ARGS_PARSER_H_
69