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