• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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_PROTO_GRAPHICS_FRAME_EVENT_PARSER_H_
18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_GRAPHICS_FRAME_EVENT_PARSER_H_
19 
20 #include <array>
21 #include <cstdint>
22 #include <optional>
23 #include <variant>
24 
25 #include "perfetto/ext/base/flat_hash_map.h"
26 #include "perfetto/protozero/field.h"
27 #include "src/trace_processor/storage/trace_storage.h"
28 
29 #include "protos/perfetto/trace/android/graphics_frame_event.pbzero.h"
30 #include "src/trace_processor/tables/slice_tables_py.h"
31 
32 namespace perfetto::trace_processor {
33 
34 class TraceProcessorContext;
35 
36 // Class for parsing graphics frame related events.
37 class GraphicsFrameEventParser {
38  public:
39   using ConstBytes = protozero::ConstBytes;
40   explicit GraphicsFrameEventParser(TraceProcessorContext*);
41 
42   void ParseGraphicsFrameEvent(int64_t timestamp, ConstBytes);
43 
44  private:
45   using SliceRowNumber = tables::SliceTable::RowNumber;
46   struct BufferEvent {
47     int64_t acquire_ts = 0;
48     int64_t queue_ts = 0;
49     int64_t latch_ts = 0;
50     bool is_most_recent_dequeue_ = false;
51   };
52   struct DequeueInfo {
53     tables::SliceTable::RowNumber slice_row;
54     int64_t timestamp;
55   };
56   struct QueueInfo {
57     TrackId track;
58   };
59   struct LatchInfo {
60     TrackId track;
61   };
62   struct PhaseEvent {
63     std::variant<std::monostate, DequeueInfo, QueueInfo, LatchInfo>
64         most_recent_event;
65     std::optional<int64_t> last_acquire_ts;
66   };
67 
68   using GraphicsFrameEventDecoder =
69       protos::pbzero::GraphicsFrameEvent_BufferEvent_Decoder;
70   using GraphicsFrameEvent = protos::pbzero::GraphicsFrameEvent;
71 
72   void CreateBufferEvent(int64_t timestamp,
73                          const GraphicsFrameEventDecoder&,
74                          StringId layer_name_id,
75                          StringId event_key);
76   void CreatePhaseEvent(int64_t timestamp,
77                         const GraphicsFrameEventDecoder&,
78                         StringId layer_name_id,
79                         StringId event_key);
80 
81   std::optional<SliceRowNumber> InsertPhaseSlice(
82       int64_t timestamp,
83       const GraphicsFrameEventDecoder&,
84       TrackId track_id,
85       StringId layer_name_id);
86 
87   TraceProcessorContext* const context_;
88   const StringId unknown_event_name_id_;
89   const StringId no_layer_name_name_id_;
90   const StringId layer_name_key_id_;
91   const StringId queue_lost_message_id_;
92   const StringId frame_number_id_;
93   const StringId queue_to_acquire_time_id_;
94   const StringId acquire_to_latch_time_id_;
95   const StringId latch_to_present_time_id_;
96   std::array<StringId, 14> event_type_name_ids_;
97 
98   // Map of (buffer ID + layer name) -> BufferEvent
99   base::FlatHashMap<StringId, BufferEvent> buffer_event_map_;
100 
101   // Maps of (buffer id + layer name) -> track id
102   base::FlatHashMap<StringId, PhaseEvent> phase_event_map_;
103 
104   // Map of layer name -> track id
105   base::FlatHashMap<StringId, TrackId> display_map_;
106 };
107 }  // namespace perfetto::trace_processor
108 
109 #endif  // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_GRAPHICS_FRAME_EVENT_PARSER_H_
110