1 /* 2 * Copyright (C) 2023 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_NETWORK_TRACE_MODULE_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_NETWORK_TRACE_MODULE_H_ 19 20 #include <cstdint> 21 22 #include "perfetto/protozero/scattered_heap_buffer.h" 23 #include "protos/perfetto/trace/android/network_trace.pbzero.h" 24 #include "protos/perfetto/trace/trace_packet.pbzero.h" 25 #include "src/trace_processor/importers/common/args_tracker.h" 26 #include "src/trace_processor/importers/common/parser_types.h" 27 #include "src/trace_processor/importers/proto/proto_importer_module.h" 28 #include "src/trace_processor/storage/trace_storage.h" 29 #include "src/trace_processor/types/trace_processor_context.h" 30 31 namespace perfetto { 32 namespace trace_processor { 33 34 class NetworkTraceModule : public ProtoImporterModule { 35 public: 36 explicit NetworkTraceModule(TraceProcessorContext* context); 37 ~NetworkTraceModule() override = default; 38 39 // Tokenize and de-intern NetworkPacketBundles so that bundles of multiple 40 // packets are sorted appropriately. This splits bundles with per-packet 41 // details (packet_timestamps and packet_lengths) into one NetworkTraceEvent 42 // per packet. Bundles with aggregates (i.e. total_packets) are forwarded 43 // after de-interning the packet context. 44 ModuleResult TokenizePacket( 45 const protos::pbzero::TracePacket::Decoder& decoder, 46 TraceBlobView* packet, 47 int64_t ts, 48 PacketSequenceState* state, 49 uint32_t field_id) override; 50 51 void ParseTracePacketData(const protos::pbzero::TracePacket::Decoder& decoder, 52 int64_t ts, 53 const TracePacketData&, 54 uint32_t field_id) override; 55 56 private: 57 void ParseGenericEvent( 58 int64_t ts, 59 int64_t dur, 60 protos::pbzero::NetworkPacketEvent::Decoder& evt, 61 std::function<void(ArgsTracker::BoundInserter*)> extra_args); 62 63 void ParseNetworkPacketEvent(int64_t ts, protozero::ConstBytes blob); 64 void ParseNetworkPacketBundle(int64_t ts, protozero::ConstBytes blob); 65 66 // Helper to simplify pushing a TracePacket to the sorter. The caller fills in 67 // the packet buffer and uses this to push for sorting and reset the buffer. 68 void PushPacketBufferForSort(int64_t timestamp, PacketSequenceState* state); 69 70 TraceProcessorContext* context_; 71 protozero::HeapBuffered<protos::pbzero::TracePacket> packet_buffer_; 72 73 const StringId net_arg_length_; 74 const StringId net_arg_ip_proto_; 75 const StringId net_arg_tcp_flags_; 76 const StringId net_arg_tag_; 77 const StringId net_arg_uid_; 78 const StringId net_arg_local_port_; 79 const StringId net_arg_remote_port_; 80 const StringId net_ipproto_tcp_; 81 const StringId net_ipproto_udp_; 82 const StringId packet_count_; 83 }; 84 85 } // namespace trace_processor 86 } // namespace perfetto 87 88 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_NETWORK_TRACE_MODULE_H_ 89