1 /* 2 * Copyright (C) 2022 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_FTRACE_VIRTIO_VIDEO_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_VIRTIO_VIDEO_TRACKER_H_ 19 20 #include <cstdint> 21 22 #include "perfetto/ext/base/flat_hash_map.h" 23 24 #include "perfetto/protozero/field.h" 25 #include "protos/perfetto/trace/ftrace/virtio_video.pbzero.h" 26 #include "src/trace_processor/importers/common/args_tracker.h" 27 #include "src/trace_processor/importers/common/async_track_set_tracker.h" 28 #include "src/trace_processor/storage/trace_storage.h" 29 #include "src/trace_processor/types/destructible.h" 30 #include "src/trace_processor/types/trace_processor_context.h" 31 32 namespace perfetto { 33 namespace trace_processor { 34 35 class TraceProcessorContext; 36 37 class VirtioVideoTracker : public Destructible { 38 public: 39 // Declared public for testing only. 40 explicit VirtioVideoTracker(TraceProcessorContext*); 41 VirtioVideoTracker(const VirtioVideoTracker&) = delete; 42 VirtioVideoTracker& operator=(const VirtioVideoTracker&) = delete; 43 ~VirtioVideoTracker() override; 44 GetOrCreate(TraceProcessorContext * context)45 static VirtioVideoTracker* GetOrCreate(TraceProcessorContext* context) { 46 if (!context->virtio_video_tracker) { 47 context->virtio_video_tracker.reset(new VirtioVideoTracker(context)); 48 } 49 return static_cast<VirtioVideoTracker*>( 50 context->virtio_video_tracker.get()); 51 } 52 53 void ParseVirtioVideoEvent(uint64_t fld_id, 54 int64_t timestamp, 55 const protozero::ConstBytes&); 56 57 private: 58 struct FieldsStringIds { 59 FieldsStringIds(TraceStorage& storage); 60 61 StringId stream_id; 62 StringId resource_id; 63 StringId queue_type; 64 StringId data_size0; 65 StringId data_size1; 66 StringId data_size2; 67 StringId data_size3; 68 StringId timestamp; 69 }; 70 71 AsyncTrackSetTracker::TrackSetId InternOrCreateBufferTrack( 72 int32_t stream_id, 73 uint32_t queue_type); 74 75 void AddCommandSlice(int64_t timestamp, 76 uint32_t stream_id, 77 uint64_t type, 78 bool response); 79 80 void AddCommandSliceArgs( 81 protos::pbzero::VirtioVideoResourceQueueDoneFtraceEvent::Decoder*, 82 ArgsTracker::BoundInserter*); 83 84 TraceProcessorContext* const context_; 85 86 StringId unknown_id_; 87 StringId input_queue_id_; 88 StringId output_queue_id_; 89 90 FieldsStringIds fields_string_ids_; 91 base::FlatHashMap<uint64_t, StringId> command_names_; 92 }; 93 94 } // namespace trace_processor 95 } // namespace perfetto 96 97 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_VIRTIO_VIDEO_TRACKER_H_ 98