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