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