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 <stdint.h>
21 
22 #include "perfetto/protozero/proto_decoder.h"
23 #include "src/trace_processor/importers/proto/proto_importer_module.h"
24 #include "src/trace_processor/storage/trace_storage.h"
25 
26 namespace perfetto {
27 
28 namespace protos {
29 namespace pbzero {
30 class ChromeThreadDescriptor_Decoder;
31 class ProcessDescriptor_Decoder;
32 class ThreadDescriptor_Decoder;
33 class TracePacket_Decoder;
34 }  // namespace pbzero
35 }  // namespace protos
36 
37 namespace trace_processor {
38 
39 class PacketSequenceState;
40 class TraceProcessorContext;
41 class TraceBlobView;
42 class TrackEventTracker;
43 struct TrackEventData;
44 
45 class TrackEventTokenizer {
46  public:
47   explicit TrackEventTokenizer(TraceProcessorContext*, TrackEventTracker*);
48 
49   ModuleResult TokenizeTrackDescriptorPacket(
50       PacketSequenceState* state,
51       const protos::pbzero::TracePacket_Decoder&,
52       int64_t packet_timestamp);
53   ModuleResult TokenizeThreadDescriptorPacket(
54       PacketSequenceState* state,
55       const protos::pbzero::TracePacket_Decoder&);
56   void TokenizeTrackEventPacket(PacketSequenceState* state,
57                                 const protos::pbzero::TracePacket_Decoder&,
58                                 TraceBlobView* packet,
59                                 int64_t packet_timestamp);
60 
61  private:
62   void TokenizeThreadDescriptor(
63       PacketSequenceState* state,
64       const protos::pbzero::ThreadDescriptor_Decoder&);
65   template <typename T>
66   base::Status AddExtraCounterValues(
67       TrackEventData& data,
68       size_t& index,
69       uint32_t trusted_packet_sequence_id,
70       protozero::RepeatedFieldIterator<T> value_it,
71       protozero::RepeatedFieldIterator<uint64_t> packet_track_uuid_it,
72       protozero::RepeatedFieldIterator<uint64_t> default_track_uuid_it);
73 
74   TraceProcessorContext* context_;
75   TrackEventTracker* track_event_tracker_;
76 
77   const StringId counter_name_thread_time_id_;
78   const StringId counter_name_thread_instruction_count_id_;
79 };
80 
81 }  // namespace trace_processor
82 }  // namespace perfetto
83 
84 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_TRACK_EVENT_TOKENIZER_H_
85