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_FRAME_TIMELINE_EVENT_PARSER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_FRAME_TIMELINE_EVENT_PARSER_H_ 19 20 #include "perfetto/ext/base/flat_hash_map.h" 21 #include "perfetto/protozero/field.h" 22 #include "src/trace_processor/importers/common/args_tracker.h" 23 #include "src/trace_processor/importers/common/track_compressor.h" 24 #include "src/trace_processor/storage/trace_storage.h" 25 26 #include "protos/perfetto/trace/android/frame_timeline_event.pbzero.h" 27 28 #include <array> 29 #include <cstdint> 30 #include <map> 31 #include <unordered_map> 32 #include <unordered_set> 33 #include <utility> 34 35 namespace perfetto { 36 37 namespace trace_processor { 38 39 using FrameTimelineEvent = protos::pbzero::FrameTimelineEvent; 40 using FrameTimelineEventDecoder = protos::pbzero::FrameTimelineEvent_Decoder; 41 42 class TraceProcessorContext; 43 44 // Class for parsing graphics frame related events. 45 class FrameTimelineEventParser { 46 public: 47 using ConstBytes = protozero::ConstBytes; 48 explicit FrameTimelineEventParser(TraceProcessorContext*); 49 50 void ParseFrameTimelineEvent(int64_t timestamp, ConstBytes); 51 52 private: 53 enum class TrackType : uint8_t { 54 kExpected, 55 kActual, 56 }; 57 58 void ParseExpectedDisplayFrameStart(int64_t timestamp, ConstBytes); 59 void ParseActualDisplayFrameStart(int64_t timestamp, ConstBytes); 60 61 void ParseExpectedSurfaceFrameStart(int64_t timestamp, ConstBytes); 62 void ParseActualSurfaceFrameStart(int64_t timestamp, ConstBytes); 63 64 void ParseFrameEnd(int64_t timestamp, ConstBytes); 65 66 TraceProcessorContext* const context_; 67 68 // Cookie -> TrackType map. Since cookies are globally unique per slice, this 69 // helps in allowing the producer to send only the cookie as the End marker 70 // without the need for any other fields. 71 base::FlatHashMap<int64_t, std::pair<UniquePid, TrackType>> cookie_map_; 72 73 std::array<StringId, 6> present_type_ids_; 74 std::array<StringId, 4> prediction_type_ids_; 75 std::array<StringId, 4> jank_severity_type_ids_; 76 77 const StringId surface_frame_token_id_; 78 const StringId display_frame_token_id_; 79 const StringId present_type_id_; 80 const StringId on_time_finish_id_; 81 const StringId gpu_composition_id_; 82 const StringId jank_type_id_; 83 const StringId jank_severity_type_id_; 84 const StringId layer_name_id_; 85 const StringId prediction_type_id_; 86 const StringId jank_tag_id_; 87 const StringId is_buffer_id_; 88 89 const StringId jank_tag_none_id_; 90 const StringId jank_tag_self_id_; 91 const StringId jank_tag_other_id_; 92 const StringId jank_tag_dropped_id_; 93 const StringId jank_tag_buffer_stuffing_id_; 94 const StringId jank_tag_sf_stuffing_id_; 95 96 // upid -> set of tokens map. The expected timeline is the same for a given 97 // token no matter how many times its seen. We can safely ignore duplicates 98 // for the expected timeline slices by caching the set of tokens seen so far 99 // per upid. upid is used as a dimension here because we show the timeline 100 // tracks for every process group. 101 // This map is used only for SurfaceFrames because there is no way two 102 // DisplayFrames use the same token unless there is something wrong with 103 // SurfaceFlinger. 104 std::unordered_map<UniquePid, std::unordered_set<int64_t>> 105 expected_timeline_token_map_; 106 107 std::multimap<int64_t, SliceId> display_token_to_surface_slice_; 108 }; 109 } // namespace trace_processor 110 } // namespace perfetto 111 112 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PROTO_FRAME_TIMELINE_EVENT_PARSER_H_ 113