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