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_GPU_TRACKER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_VIRTIO_GPU_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/storage/trace_storage.h" 25 26 namespace perfetto::trace_processor { 27 28 class TraceProcessorContext; 29 30 class VirtioGpuTracker { 31 public: 32 explicit VirtioGpuTracker(TraceProcessorContext*); 33 34 void ParseVirtioGpu(int64_t timestamp, 35 uint32_t field_id, 36 uint32_t pid, 37 protozero::ConstBytes blob); 38 39 private: 40 class VirtioGpuQueue { 41 public: 42 VirtioGpuQueue(TraceProcessorContext* context, const char* name); 43 44 void HandleNumFree(int64_t timestamp, uint32_t num_free); 45 void HandleCmdQueue(int64_t timestamp, 46 uint32_t seqno, 47 uint32_t type, 48 uint64_t fence_id); 49 void HandleCmdResponse(int64_t timestamp, uint32_t seqno); 50 51 private: 52 TraceProcessorContext* context_; 53 StringId queue_track_id_; 54 const char* name_; 55 56 // Maps a seqno to the timestamp of a VirtioGpuCmdQueue. The events 57 // come in pairs of VirtioGpuCmdQueue plus VirtioGpuCmdResponse and 58 // can be matched up via their seqno field. To calculate the slice 59 // duration we need to lookup the timestamp of the matching CmdQueue 60 // event when we get the CmdResponse event. 61 base::FlatHashMap<uint32_t, int64_t> start_timestamps_; 62 }; 63 64 VirtioGpuQueue virtgpu_control_queue_; 65 VirtioGpuQueue virtgpu_cursor_queue_; 66 67 void ParseVirtioGpuCmdQueue(int64_t timestamp, 68 uint32_t pid, 69 protozero::ConstBytes); 70 void ParseVirtioGpuCmdResponse(int64_t timestamp, 71 uint32_t pid, 72 protozero::ConstBytes blob); 73 }; 74 75 } // namespace perfetto::trace_processor 76 77 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_FTRACE_VIRTIO_GPU_TRACKER_H_ 78