OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_DEBUG_FRAME_TIMING_TRACKER_H_ | |
6 #define CC_DEBUG_FRAME_TIMING_TRACKER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 #include <unordered_map> | |
12 #include <utility> | |
13 #include <vector> | |
14 | |
15 #include "base/macros.h" | |
16 #include "base/time/time.h" | |
17 #include "cc/base/cc_export.h" | |
18 #include "cc/base/delayed_unique_notifier.h" | |
19 | |
20 namespace cc { | |
21 | |
22 class LayerTreeHostImpl; | |
23 | |
24 // This class maintains a history of timestamps and rect IDs to communicate | |
25 // frame events back to Blink | |
26 // TODO(mpb): Start using this. crbug.com/442554 | |
27 class CC_EXPORT FrameTimingTracker { | |
28 public: | |
29 struct CC_EXPORT CompositeTimingEvent { | |
30 CompositeTimingEvent(int, base::TimeTicks); | |
31 ~CompositeTimingEvent(); | |
32 | |
33 int frame_id; | |
34 base::TimeTicks timestamp; | |
35 }; | |
36 | |
37 using CompositeTimingSet = | |
38 std::unordered_map<int64_t, std::vector<CompositeTimingEvent>>; | |
39 | |
40 struct CC_EXPORT MainFrameTimingEvent { | |
41 MainFrameTimingEvent(int frame_id, | |
42 base::TimeTicks timestamp, | |
43 base::TimeTicks end_time); | |
44 ~MainFrameTimingEvent(); | |
45 | |
46 int frame_id; | |
47 base::TimeTicks timestamp; | |
48 base::TimeTicks end_time; | |
49 }; | |
50 | |
51 using MainFrameTimingSet = | |
52 std::unordered_map<int64_t, std::vector<MainFrameTimingEvent>>; | |
53 | |
54 static std::unique_ptr<FrameTimingTracker> Create( | |
55 LayerTreeHostImpl* layer_tree_host_impl); | |
56 | |
57 ~FrameTimingTracker(); | |
58 | |
59 // This routine takes all of the individual CompositeEvents stored in the | |
60 // tracker and collects them by "rect_id", as in the example below. | |
61 // [ {f_id1,r_id1,t1}, {f_id2,r_id1,t2}, {f_id3,r_id2,t3} ] | |
62 // ====> | |
63 // [ {r_id1,<{f_id1,t1},{f_id2,t2}>}, {r_id2,<{f_id3,t3}>} ] | |
64 std::unique_ptr<CompositeTimingSet> GroupCompositeCountsByRectId(); | |
65 | |
66 // This routine takes all of the individual MainFrameEvents stored in the | |
67 // tracker and collects them by "rect_id", as in the example below. | |
68 std::unique_ptr<MainFrameTimingSet> GroupMainFrameCountsByRectId(); | |
69 | |
70 // This routine takes a timestamp and an array of frame_id,rect_id pairs | |
71 // and generates CompositeTimingEvents (frame_id, timestamp) and adds them to | |
72 // internal hash_map keyed on rect_id | |
73 using FrameAndRectIds = std::pair<int, int64_t>; | |
74 void SaveTimeStamps(base::TimeTicks timestamp, | |
75 const std::vector<FrameAndRectIds>& frame_ids); | |
76 | |
77 void SaveMainFrameTimeStamps(const std::vector<int64_t>& request_ids, | |
78 base::TimeTicks main_frame_time, | |
79 base::TimeTicks end_time, | |
80 int source_frame_number); | |
81 | |
82 private: | |
83 explicit FrameTimingTracker(LayerTreeHostImpl* layer_tree_host_impl); | |
84 | |
85 void PostEvents(); | |
86 | |
87 std::unique_ptr<CompositeTimingSet> composite_events_; | |
88 std::unique_ptr<MainFrameTimingSet> main_frame_events_; | |
89 | |
90 LayerTreeHostImpl* layer_tree_host_impl_; | |
91 DelayedUniqueNotifier post_events_notifier_; | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(FrameTimingTracker); | |
94 }; | |
95 | |
96 } // namespace cc | |
97 | |
98 #endif // CC_DEBUG_FRAME_TIMING_TRACKER_H_ | |
OLD | NEW |