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 <optional> 21 #include <vector> 22 23 #include "perfetto/ext/base/string_writer.h" 24 #include "perfetto/protozero/field.h" 25 #include "src/trace_processor/importers/common/args_tracker.h" 26 #include "src/trace_processor/importers/proto/vulkan_memory_tracker.h" 27 #include "src/trace_processor/storage/trace_storage.h" 28 29 #include "protos/perfetto/trace/android/graphics_frame_event.pbzero.h" 30 31 namespace perfetto { 32 33 namespace trace_processor { 34 35 class TraceProcessorContext; 36 37 // Class for parsing graphics frame related events. 38 class GraphicsFrameEventParser { 39 public: 40 using ConstBytes = protozero::ConstBytes; 41 explicit GraphicsFrameEventParser(TraceProcessorContext*); 42 43 void ParseGraphicsFrameEvent(int64_t timestamp, ConstBytes); 44 45 private: 46 using GraphicsFrameEventDecoder = 47 protos::pbzero::GraphicsFrameEvent_BufferEvent_Decoder; 48 using GraphicsFrameEvent = protos::pbzero::GraphicsFrameEvent; 49 bool CreateBufferEvent(int64_t timestamp, GraphicsFrameEventDecoder& event); 50 void CreatePhaseEvent(int64_t timestamp, GraphicsFrameEventDecoder& event); 51 // Invalidate a phase slice that has one of the events missing 52 void InvalidatePhaseEvent(int64_t timestamp, 53 TrackId track_id, 54 bool reset_name = false); 55 56 TraceProcessorContext* const context_; 57 const StringId graphics_event_scope_id_; 58 const StringId unknown_event_name_id_; 59 const StringId no_layer_name_name_id_; 60 const StringId layer_name_key_id_; 61 std::array<StringId, 14> event_type_name_ids_; 62 const StringId queue_lost_message_id_; 63 // Map of (buffer ID + layer name) -> slice id of the dequeue event 64 std::unordered_map<StringId, SliceId> dequeue_slice_ids_; 65 66 // Row indices of frame stats table. Used to populate the slice_id after 67 // inserting the rows. 68 std::vector<uint32_t> graphics_frame_stats_idx_; 69 // Map of (buffer ID + layer name) 70 // -> (Map of GraphicsFrameEvent -> ts of that event) 71 std::unordered_map<StringId, std::unordered_map<uint64_t, int64_t>> 72 graphics_frame_stats_map_; 73 74 // Maps of (buffer id + layer name) -> track id 75 std::unordered_map<StringId, TrackId> dequeue_map_; 76 std::unordered_map<StringId, TrackId> queue_map_; 77 std::unordered_map<StringId, TrackId> latch_map_; 78 // Map of layer name -> track id 79 std::unordered_map<StringId, TrackId> display_map_; 80 81 // Maps of (buffer id + layer name) -> timestamp 82 std::unordered_map<StringId, int64_t> last_dequeued_; 83 std::unordered_map<StringId, int64_t> last_acquired_; 84 }; 85 } // namespace trace_processor 86 } // namespace perfetto 87 88 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_GRAPHICS_FRAME_EVENT_PARSER_H_ 89