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/ext/base/string_view.h" 24 #include "perfetto/protozero/field.h" 25 #include "src/trace_processor/storage/trace_storage.h" 26 27 namespace perfetto::trace_processor { 28 29 class TraceProcessorContext; 30 31 class VirtioGpuTracker { 32 public: 33 explicit VirtioGpuTracker(TraceProcessorContext*); 34 35 void ParseVirtioGpu(int64_t timestamp, 36 uint32_t field_id, 37 uint32_t pid, 38 protozero::ConstBytes blob); 39 40 private: 41 class VirtioGpuQueue { 42 public: 43 VirtioGpuQueue(TraceProcessorContext* context, const char* name); 44 45 void HandleNumFree(int64_t timestamp, uint32_t num_free); 46 void HandleCmdQueue(int64_t timestamp, 47 uint32_t seqno, 48 uint32_t type, 49 uint64_t fence_id); 50 void HandleCmdResponse(int64_t timestamp, uint32_t seqno); 51 52 private: 53 TraceProcessorContext* context_; 54 base::StringView 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