| 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 #include <stdint.h> | |
| 6 | |
| 7 #include <set> | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/time/time.h" | |
| 11 #include "base/trace_event/trace_event_argument.h" | |
| 12 #include "base/values.h" | |
| 13 #include "cc/debug/frame_timing_tracker.h" | |
| 14 #include "cc/test/fake_impl_task_runner_provider.h" | |
| 15 #include "cc/test/fake_layer_tree_host_impl.h" | |
| 16 #include "cc/test/test_shared_bitmap_manager.h" | |
| 17 #include "cc/test/test_task_graph_runner.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 | |
| 20 namespace cc { | |
| 21 namespace { | |
| 22 | |
| 23 std::string CompositeToString( | |
| 24 std::unique_ptr<FrameTimingTracker::CompositeTimingSet> timingset) { | |
| 25 std::unique_ptr<base::trace_event::TracedValue> value( | |
| 26 new base::trace_event::TracedValue()); | |
| 27 value->BeginArray("values"); | |
| 28 std::set<int> rect_ids; | |
| 29 for (const auto& pair : *timingset) | |
| 30 rect_ids.insert(pair.first); | |
| 31 | |
| 32 for (const auto& rect_id : rect_ids) { | |
| 33 auto& events = (*timingset)[rect_id]; | |
| 34 value->BeginDictionary(); | |
| 35 value->SetInteger("rect_id", rect_id); | |
| 36 value->BeginArray("events"); | |
| 37 for (const auto& event : events) { | |
| 38 value->BeginDictionary(); | |
| 39 value->SetInteger("frame_id", event.frame_id); | |
| 40 value->SetInteger("timestamp", event.timestamp.ToInternalValue()); | |
| 41 value->EndDictionary(); | |
| 42 } | |
| 43 value->EndArray(); | |
| 44 value->EndDictionary(); | |
| 45 } | |
| 46 value->EndArray(); | |
| 47 return value->ToString(); | |
| 48 } | |
| 49 | |
| 50 std::string MainFrameToString( | |
| 51 std::unique_ptr<FrameTimingTracker::MainFrameTimingSet> timingset) { | |
| 52 std::unique_ptr<base::trace_event::TracedValue> value( | |
| 53 new base::trace_event::TracedValue()); | |
| 54 value->BeginArray("values"); | |
| 55 std::set<int> rect_ids; | |
| 56 for (const auto& pair : *timingset) | |
| 57 rect_ids.insert(pair.first); | |
| 58 | |
| 59 for (const auto& rect_id : rect_ids) { | |
| 60 auto& events = (*timingset)[rect_id]; | |
| 61 value->BeginDictionary(); | |
| 62 value->SetInteger("rect_id", rect_id); | |
| 63 value->BeginArray("events"); | |
| 64 for (const auto& event : events) { | |
| 65 value->BeginDictionary(); | |
| 66 value->SetInteger("end_time", event.end_time.ToInternalValue()); | |
| 67 value->SetInteger("frame_id", event.frame_id); | |
| 68 value->SetInteger("timestamp", event.timestamp.ToInternalValue()); | |
| 69 value->EndDictionary(); | |
| 70 } | |
| 71 value->EndArray(); | |
| 72 value->EndDictionary(); | |
| 73 } | |
| 74 value->EndArray(); | |
| 75 return value->ToString(); | |
| 76 } | |
| 77 | |
| 78 TEST(FrameTimingTrackerTest, DefaultTrackerIsEmpty) { | |
| 79 FakeImplTaskRunnerProvider task_runner_provider; | |
| 80 TestSharedBitmapManager shared_bitmap_manager; | |
| 81 TestTaskGraphRunner task_graph_runner; | |
| 82 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 83 &task_graph_runner); | |
| 84 | |
| 85 std::unique_ptr<FrameTimingTracker> tracker( | |
| 86 FrameTimingTracker::Create(&host_impl)); | |
| 87 EXPECT_EQ("{\"values\":[]}", | |
| 88 CompositeToString(tracker->GroupCompositeCountsByRectId())); | |
| 89 EXPECT_EQ("{\"values\":[]}", | |
| 90 MainFrameToString(tracker->GroupMainFrameCountsByRectId())); | |
| 91 } | |
| 92 | |
| 93 TEST(FrameTimingTrackerTest, NoFrameIdsIsEmpty) { | |
| 94 FakeImplTaskRunnerProvider task_runner_provider; | |
| 95 TestSharedBitmapManager shared_bitmap_manager; | |
| 96 TestTaskGraphRunner task_graph_runner; | |
| 97 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 98 &task_graph_runner); | |
| 99 | |
| 100 std::unique_ptr<FrameTimingTracker> tracker( | |
| 101 FrameTimingTracker::Create(&host_impl)); | |
| 102 std::vector<std::pair<int, int64_t>> ids; | |
| 103 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(100), ids); | |
| 104 EXPECT_EQ("{\"values\":[]}", | |
| 105 CompositeToString(tracker->GroupCompositeCountsByRectId())); | |
| 106 } | |
| 107 | |
| 108 TEST(FrameTimingTrackerTest, NoRectIdsYieldsNoMainFrameEvents) { | |
| 109 FakeImplTaskRunnerProvider task_runner_provider; | |
| 110 TestSharedBitmapManager shared_bitmap_manager; | |
| 111 TestTaskGraphRunner task_graph_runner; | |
| 112 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 113 &task_graph_runner); | |
| 114 | |
| 115 std::unique_ptr<FrameTimingTracker> tracker( | |
| 116 FrameTimingTracker::Create(&host_impl)); | |
| 117 tracker->SaveMainFrameTimeStamps(std::vector<int64_t>(), | |
| 118 base::TimeTicks::FromInternalValue(100), | |
| 119 base::TimeTicks::FromInternalValue(110), 1); | |
| 120 EXPECT_EQ("{\"values\":[]}", | |
| 121 MainFrameToString(tracker->GroupMainFrameCountsByRectId())); | |
| 122 } | |
| 123 | |
| 124 TEST(FrameTimingTrackerTest, OneFrameId) { | |
| 125 FakeImplTaskRunnerProvider task_runner_provider; | |
| 126 TestSharedBitmapManager shared_bitmap_manager; | |
| 127 TestTaskGraphRunner task_graph_runner; | |
| 128 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 129 &task_graph_runner); | |
| 130 | |
| 131 std::unique_ptr<FrameTimingTracker> tracker( | |
| 132 FrameTimingTracker::Create(&host_impl)); | |
| 133 std::vector<std::pair<int, int64_t>> ids; | |
| 134 ids.push_back(std::make_pair(1, 2)); | |
| 135 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(100), ids); | |
| 136 EXPECT_EQ( | |
| 137 "{\"values\":[{\"events\":[" | |
| 138 "{\"frame_id\":1,\"timestamp\":100}],\"rect_id\":2}]}", | |
| 139 CompositeToString(tracker->GroupCompositeCountsByRectId())); | |
| 140 } | |
| 141 | |
| 142 TEST(FrameTimingTrackerTest, OneMainFrameRect) { | |
| 143 FakeImplTaskRunnerProvider task_runner_provider; | |
| 144 TestSharedBitmapManager shared_bitmap_manager; | |
| 145 TestTaskGraphRunner task_graph_runner; | |
| 146 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 147 &task_graph_runner); | |
| 148 | |
| 149 std::unique_ptr<FrameTimingTracker> tracker( | |
| 150 FrameTimingTracker::Create(&host_impl)); | |
| 151 std::vector<int64_t> rect_ids; | |
| 152 rect_ids.push_back(1); | |
| 153 tracker->SaveMainFrameTimeStamps(rect_ids, | |
| 154 base::TimeTicks::FromInternalValue(100), | |
| 155 base::TimeTicks::FromInternalValue(110), 2); | |
| 156 EXPECT_EQ( | |
| 157 "{\"values\":[{\"events\":[" | |
| 158 "{\"end_time\":110,\"frame_id\":2,\"timestamp\":100}],\"rect_id\":1}]}", | |
| 159 MainFrameToString(tracker->GroupMainFrameCountsByRectId())); | |
| 160 } | |
| 161 | |
| 162 TEST(FrameTimingTrackerTest, UnsortedTimestampsIds) { | |
| 163 FakeImplTaskRunnerProvider task_runner_provider; | |
| 164 TestSharedBitmapManager shared_bitmap_manager; | |
| 165 TestTaskGraphRunner task_graph_runner; | |
| 166 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 167 &task_graph_runner); | |
| 168 | |
| 169 std::unique_ptr<FrameTimingTracker> tracker( | |
| 170 FrameTimingTracker::Create(&host_impl)); | |
| 171 std::vector<std::pair<int, int64_t>> ids; | |
| 172 ids.push_back(std::make_pair(1, 2)); | |
| 173 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(200), ids); | |
| 174 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(400), ids); | |
| 175 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(100), ids); | |
| 176 EXPECT_EQ( | |
| 177 "{\"values\":[{\"events\":[" | |
| 178 "{\"frame_id\":1,\"timestamp\":100}," | |
| 179 "{\"frame_id\":1,\"timestamp\":200}," | |
| 180 "{\"frame_id\":1,\"timestamp\":400}],\"rect_id\":2}]}", | |
| 181 CompositeToString(tracker->GroupCompositeCountsByRectId())); | |
| 182 } | |
| 183 | |
| 184 TEST(FrameTimingTrackerTest, MainFrameUnsortedTimestamps) { | |
| 185 FakeImplTaskRunnerProvider task_runner_provider; | |
| 186 TestSharedBitmapManager shared_bitmap_manager; | |
| 187 TestTaskGraphRunner task_graph_runner; | |
| 188 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 189 &task_graph_runner); | |
| 190 | |
| 191 std::unique_ptr<FrameTimingTracker> tracker( | |
| 192 FrameTimingTracker::Create(&host_impl)); | |
| 193 std::vector<int64_t> rect_ids; | |
| 194 rect_ids.push_back(2); | |
| 195 tracker->SaveMainFrameTimeStamps(rect_ids, | |
| 196 base::TimeTicks::FromInternalValue(200), | |
| 197 base::TimeTicks::FromInternalValue(280), 1); | |
| 198 tracker->SaveMainFrameTimeStamps(rect_ids, | |
| 199 base::TimeTicks::FromInternalValue(400), | |
| 200 base::TimeTicks::FromInternalValue(470), 1); | |
| 201 tracker->SaveMainFrameTimeStamps(rect_ids, | |
| 202 base::TimeTicks::FromInternalValue(100), | |
| 203 base::TimeTicks::FromInternalValue(160), 1); | |
| 204 EXPECT_EQ( | |
| 205 "{\"values\":[{\"events\":[" | |
| 206 "{\"end_time\":160,\"frame_id\":1,\"timestamp\":100}," | |
| 207 "{\"end_time\":280,\"frame_id\":1,\"timestamp\":200}," | |
| 208 "{\"end_time\":470,\"frame_id\":1,\"timestamp\":400}],\"rect_id\":2}]}", | |
| 209 MainFrameToString(tracker->GroupMainFrameCountsByRectId())); | |
| 210 } | |
| 211 | |
| 212 TEST(FrameTimingTrackerTest, MultipleFrameIds) { | |
| 213 FakeImplTaskRunnerProvider task_runner_provider; | |
| 214 TestSharedBitmapManager shared_bitmap_manager; | |
| 215 TestTaskGraphRunner task_graph_runner; | |
| 216 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 217 &task_graph_runner); | |
| 218 | |
| 219 std::unique_ptr<FrameTimingTracker> tracker( | |
| 220 FrameTimingTracker::Create(&host_impl)); | |
| 221 | |
| 222 std::vector<std::pair<int, int64_t>> ids200; | |
| 223 ids200.push_back(std::make_pair(1, 2)); | |
| 224 ids200.push_back(std::make_pair(1, 3)); | |
| 225 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(200), ids200); | |
| 226 | |
| 227 std::vector<std::pair<int, int64_t>> ids400; | |
| 228 ids400.push_back(std::make_pair(2, 2)); | |
| 229 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(400), ids400); | |
| 230 | |
| 231 std::vector<std::pair<int, int64_t>> ids100; | |
| 232 ids100.push_back(std::make_pair(3, 2)); | |
| 233 ids100.push_back(std::make_pair(2, 3)); | |
| 234 ids100.push_back(std::make_pair(3, 4)); | |
| 235 tracker->SaveTimeStamps(base::TimeTicks::FromInternalValue(100), ids100); | |
| 236 | |
| 237 EXPECT_EQ( | |
| 238 "{\"values\":[{\"events\":[" | |
| 239 "{\"frame_id\":3,\"timestamp\":100}," | |
| 240 "{\"frame_id\":1,\"timestamp\":200}," | |
| 241 "{\"frame_id\":2,\"timestamp\":400}],\"rect_id\":2}," | |
| 242 "{\"events\":[" | |
| 243 "{\"frame_id\":2,\"timestamp\":100}," | |
| 244 "{\"frame_id\":1,\"timestamp\":200}],\"rect_id\":3}," | |
| 245 "{\"events\":[" | |
| 246 "{\"frame_id\":3,\"timestamp\":100}],\"rect_id\":4}" | |
| 247 "]}", | |
| 248 CompositeToString(tracker->GroupCompositeCountsByRectId())); | |
| 249 } | |
| 250 | |
| 251 TEST(FrameTimingTrackerTest, MultipleMainFrameEvents) { | |
| 252 FakeImplTaskRunnerProvider task_runner_provider; | |
| 253 TestSharedBitmapManager shared_bitmap_manager; | |
| 254 TestTaskGraphRunner task_graph_runner; | |
| 255 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 256 &task_graph_runner); | |
| 257 | |
| 258 std::unique_ptr<FrameTimingTracker> tracker( | |
| 259 FrameTimingTracker::Create(&host_impl)); | |
| 260 | |
| 261 std::vector<int64_t> rect_ids200; | |
| 262 rect_ids200.push_back(2); | |
| 263 rect_ids200.push_back(3); | |
| 264 tracker->SaveMainFrameTimeStamps(rect_ids200, | |
| 265 base::TimeTicks::FromInternalValue(200), | |
| 266 base::TimeTicks::FromInternalValue(220), 1); | |
| 267 | |
| 268 std::vector<int64_t> rect_ids400; | |
| 269 rect_ids400.push_back(2); | |
| 270 tracker->SaveMainFrameTimeStamps(rect_ids400, | |
| 271 base::TimeTicks::FromInternalValue(400), | |
| 272 base::TimeTicks::FromInternalValue(440), 2); | |
| 273 | |
| 274 std::vector<int64_t> rect_ids100; | |
| 275 rect_ids100.push_back(2); | |
| 276 rect_ids100.push_back(3); | |
| 277 rect_ids100.push_back(4); | |
| 278 tracker->SaveMainFrameTimeStamps(rect_ids100, | |
| 279 base::TimeTicks::FromInternalValue(100), | |
| 280 base::TimeTicks::FromInternalValue(110), 3); | |
| 281 | |
| 282 EXPECT_EQ( | |
| 283 "{\"values\":[{\"events\":[" | |
| 284 "{\"end_time\":110,\"frame_id\":3,\"timestamp\":100}," | |
| 285 "{\"end_time\":220,\"frame_id\":1,\"timestamp\":200}," | |
| 286 "{\"end_time\":440,\"frame_id\":2,\"timestamp\":400}],\"rect_id\":2}," | |
| 287 "{\"events\":[" | |
| 288 "{\"end_time\":110,\"frame_id\":3,\"timestamp\":100}," | |
| 289 "{\"end_time\":220,\"frame_id\":1,\"timestamp\":200}],\"rect_id\":3}," | |
| 290 "{\"events\":[" | |
| 291 "{\"end_time\":110,\"frame_id\":3,\"timestamp\":100}],\"rect_id\":4}" | |
| 292 "]}", | |
| 293 MainFrameToString(tracker->GroupMainFrameCountsByRectId())); | |
| 294 } | |
| 295 | |
| 296 } // namespace | |
| 297 } // namespace cc | |
| OLD | NEW |