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