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 #include "src/trace_processor/importers/etw/etw_module_impl.h"
18
19 #include "perfetto/trace_processor/trace_blob_view.h"
20 #include "src/trace_processor/importers/etw/etw_tokenizer.h"
21
22 #include "protos/perfetto/trace/trace_packet.pbzero.h"
23 #include "src/trace_processor/importers/proto/packet_sequence_state_generation.h"
24
25 namespace perfetto {
26 namespace trace_processor {
27
28 using perfetto::protos::pbzero::TracePacket;
29
EtwModuleImpl(TraceProcessorContext * context)30 EtwModuleImpl::EtwModuleImpl(TraceProcessorContext* context)
31 : tokenizer_(context), parser_(context) {
32 RegisterForField(TracePacket::kEtwEventsFieldNumber, context);
33 }
34
TokenizePacket(const protos::pbzero::TracePacket::Decoder & decoder,TraceBlobView * packet,int64_t,RefPtr<PacketSequenceStateGeneration> seq_state,uint32_t field_id)35 ModuleResult EtwModuleImpl::TokenizePacket(
36 const protos::pbzero::TracePacket::Decoder& decoder,
37 TraceBlobView* packet,
38 int64_t /*packet_timestamp*/,
39 RefPtr<PacketSequenceStateGeneration> seq_state,
40 uint32_t field_id) {
41 switch (field_id) {
42 case TracePacket::kEtwEventsFieldNumber: {
43 auto etw_field = decoder.etw_events();
44 tokenizer_.TokenizeEtwBundle(
45 packet->slice(etw_field.data, etw_field.size), std::move(seq_state));
46 return ModuleResult::Handled();
47 }
48 }
49 return ModuleResult::Ignored();
50 }
51
52 } // namespace trace_processor
53 } // namespace perfetto
54