xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/proto/proto_trace_parser_impl.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 
17 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_PARSER_IMPL_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_PARSER_IMPL_H_
19 
20 #include <cstdint>
21 
22 #include "perfetto/ext/base/flat_hash_map.h"
23 #include "perfetto/protozero/field.h"
24 #include "src/trace_processor/importers/common/parser_types.h"
25 #include "src/trace_processor/importers/common/trace_parser.h"
26 #include "src/trace_processor/storage/trace_storage.h"
27 
28 namespace perfetto {
29 
30 namespace protos::pbzero {
31 class TracePacket_Decoder;
32 }  // namespace protos::pbzero
33 
34 namespace trace_processor {
35 
36 class PacketSequenceState;
37 class TraceProcessorContext;
38 
39 class ProtoTraceParserImpl : public ProtoTraceParser {
40  public:
41   using ConstBytes = protozero::ConstBytes;
42   explicit ProtoTraceParserImpl(TraceProcessorContext*);
43   ~ProtoTraceParserImpl() override;
44 
45   void ParseTrackEvent(int64_t ts, TrackEventData data) override;
46   void ParseTracePacket(int64_t ts, TracePacketData data) override;
47 
48   void ParseEtwEvent(uint32_t cpu,
49                      int64_t /*ts*/,
50                      TracePacketData data) override;
51 
52   void ParseFtraceEvent(uint32_t cpu,
53                         int64_t /*ts*/,
54                         TracePacketData data) override;
55 
56   void ParseInlineSchedSwitch(uint32_t cpu,
57                               int64_t /*ts*/,
58                               InlineSchedSwitch data) override;
59 
60   void ParseInlineSchedWaking(uint32_t cpu,
61                               int64_t /*ts*/,
62                               InlineSchedWaking data) override;
63 
64  private:
65   StringId GetMetatraceInternedString(uint64_t iid);
66 
67   void ParseChromeEvents(int64_t ts, ConstBytes);
68   void ParseMetatraceEvent(int64_t ts, ConstBytes);
69 
70   TraceProcessorContext* context_;
71 
72   const StringId metatrace_id_;
73   const StringId data_name_id_;
74   const StringId raw_chrome_metadata_event_id_;
75   const StringId raw_chrome_legacy_system_trace_event_id_;
76   const StringId raw_chrome_legacy_user_trace_event_id_;
77   const StringId missing_metatrace_interned_string_id_;
78 
79   base::FlatHashMap<uint64_t, StringId> metatrace_interned_strings_;
80 };
81 
82 }  // namespace trace_processor
83 }  // namespace perfetto
84 
85 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_PROTO_TRACE_PARSER_IMPL_H_
86