xref: /aosp_15_r20/external/perfetto/src/trace_processor/importers/proto/track_event_tokenizer.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2019 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_TRACK_EVENT_TOKENIZER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_TOKENIZER_H_
19 
20 #include <array>
21 #include <cstddef>
22 #include <cstdint>
23 
24 #include "perfetto/base/status.h"
25 #include "perfetto/protozero/proto_decoder.h"
26 #include "perfetto/trace_processor/ref_counted.h"
27 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h"
28 #include "src/trace_processor/importers/proto/proto_importer_module.h"
29 #include "src/trace_processor/storage/trace_storage.h"
30 
31 namespace perfetto {
32 
33 namespace protos::pbzero {
34 class ChromeThreadDescriptor_Decoder;
35 class ProcessDescriptor_Decoder;
36 class ThreadDescriptor_Decoder;
37 class TracePacket_Decoder;
38 class TrackEvent_Decoder;
39 class TrackEvent_LegacyEvent_Decoder;
40 }  // namespace protos::pbzero
41 
42 namespace trace_processor {
43 
44 class TraceProcessorContext;
45 class TraceBlobView;
46 class TrackEventTracker;
47 struct TrackEventData;
48 
49 class TrackEventTokenizer {
50  public:
51   explicit TrackEventTokenizer(TraceProcessorContext*, TrackEventTracker*);
52 
53   ModuleResult TokenizeRangeOfInterestPacket(
54       RefPtr<PacketSequenceStateGeneration> state,
55       const protos::pbzero::TracePacket_Decoder&,
56       int64_t packet_timestamp);
57   ModuleResult TokenizeTrackDescriptorPacket(
58       RefPtr<PacketSequenceStateGeneration> state,
59       const protos::pbzero::TracePacket_Decoder&,
60       int64_t packet_timestamp);
61   ModuleResult TokenizeThreadDescriptorPacket(
62       RefPtr<PacketSequenceStateGeneration> state,
63       const protos::pbzero::TracePacket_Decoder&);
64   ModuleResult TokenizeTrackEventPacket(
65       RefPtr<PacketSequenceStateGeneration> state,
66       const protos::pbzero::TracePacket_Decoder&,
67       TraceBlobView* packet,
68       int64_t packet_timestamp);
69 
70  private:
71   void TokenizeThreadDescriptor(
72       PacketSequenceStateGeneration& state,
73       const protos::pbzero::ThreadDescriptor_Decoder&);
74   template <typename T>
75   base::Status AddExtraCounterValues(
76       TrackEventData& data,
77       size_t& index,
78       uint32_t trusted_packet_sequence_id,
79       protozero::RepeatedFieldIterator<T> value_it,
80       protozero::RepeatedFieldIterator<uint64_t> packet_track_uuid_it,
81       protozero::RepeatedFieldIterator<uint64_t> default_track_uuid_it);
82   base::Status TokenizeLegacySampleEvent(
83       const protos::pbzero::TrackEvent_Decoder&,
84       const protos::pbzero::TrackEvent_LegacyEvent_Decoder&,
85       PacketSequenceStateGeneration& state);
86 
87   TraceProcessorContext* const context_;
88   TrackEventTracker* const track_event_tracker_;
89 
90   const StringId counter_name_thread_time_id_;
91   const StringId counter_name_thread_instruction_count_id_;
92 
93   std::array<StringId, 4> counter_unit_ids_;
94 };
95 
96 }  // namespace trace_processor
97 }  // namespace perfetto
98 
99 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_TOKENIZER_H_
100