Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: ui/latency/latency_info.cc

Issue 2771053003: WIP: Plumbing input event latency reporting through Mus GPU.
Patch Set: NON_EXPORTED_BASE Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/latency/latency_info.h ('k') | ui/latency/latency_info_test_support.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/latency/latency_info.h" 5 #include "ui/latency/latency_info.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 18
19 namespace { 19 namespace {
20 20
21 const size_t kMaxLatencyInfoNumber = 100; 21 const size_t kMaxLatencyInfoNumber = 100;
22 22
23 const char* GetComponentName(ui::LatencyComponentType type) {
24 #define CASE_TYPE(t) case ui::t: return #t
25 switch (type) {
26 CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT);
27 CASE_TYPE(LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT);
28 CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT);
29 CASE_TYPE(INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT);
30 CASE_TYPE(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT);
31 CASE_TYPE(INPUT_EVENT_LATENCY_UI_COMPONENT);
32 CASE_TYPE(INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT);
33 CASE_TYPE(INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT);
34 CASE_TYPE(INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT);
35 CASE_TYPE(INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT);
36 CASE_TYPE(BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT);
37 CASE_TYPE(TAB_SHOW_COMPONENT);
38 CASE_TYPE(INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT);
39 CASE_TYPE(INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT);
40 CASE_TYPE(INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT);
41 CASE_TYPE(INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT);
42 CASE_TYPE(INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL);
43 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT);
44 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT);
45 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT);
46 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT);
47 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT);
48 default:
49 DLOG(WARNING) << "Unhandled LatencyComponentType.\n";
50 break;
51 }
52 #undef CASE_TYPE
53 return "unknown";
54 }
55
56 bool IsTerminalComponent(ui::LatencyComponentType type) { 23 bool IsTerminalComponent(ui::LatencyComponentType type) {
57 switch (type) { 24 switch (type) {
58 case ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT: 25 case ui::INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT:
59 case ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT: 26 case ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT:
60 case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT: 27 case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT:
61 case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT: 28 case ui::INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT:
62 case ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT: 29 case ui::INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT:
63 return true; 30 return true;
64 default: 31 default:
65 return false; 32 return false;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 const unsigned char* latency_info_enabled; 90 const unsigned char* latency_info_enabled;
124 }; 91 };
125 92
126 static base::LazyInstance<LatencyInfoEnabledInitializer>::Leaky 93 static base::LazyInstance<LatencyInfoEnabledInitializer>::Leaky
127 g_latency_info_enabled = LAZY_INSTANCE_INITIALIZER; 94 g_latency_info_enabled = LAZY_INSTANCE_INITIALIZER;
128 95
129 } // namespace 96 } // namespace
130 97
131 namespace ui { 98 namespace ui {
132 99
100 const char* GetComponentName(ui::LatencyComponentType type) {
101 #define CASE_TYPE(t) case ui::t: return #t
102 switch (type) {
103 CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT);
104 CASE_TYPE(LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT);
105 CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT);
106 CASE_TYPE(INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT);
107 CASE_TYPE(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT);
108 CASE_TYPE(INPUT_EVENT_LATENCY_UI_COMPONENT);
109 CASE_TYPE(INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_MAIN_COMPONENT);
110 CASE_TYPE(INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_IMPL_COMPONENT);
111 CASE_TYPE(INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT);
112 CASE_TYPE(INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT);
113 CASE_TYPE(BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT);
114 CASE_TYPE(TAB_SHOW_COMPONENT);
115 CASE_TYPE(INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT);
116 CASE_TYPE(INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT);
117 CASE_TYPE(DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT);
118 CASE_TYPE(INPUT_EVENT_GPU_SWAP_BUFFER_COMPONENT);
119 CASE_TYPE(INPUT_EVENT_LATENCY_GENERATE_SCROLL_UPDATE_FROM_MOUSE_WHEEL);
120 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_NO_SWAP_COMPONENT);
121 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT);
122 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_COMMIT_FAILED_COMPONENT);
123 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_COMMIT_NO_UPDATE_COMPONENT);
124 CASE_TYPE(INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT);
125 default:
126 DLOG(WARNING) << "Unhandled LatencyComponentType.\n";
127 break;
128 }
129 #undef CASE_TYPE
130 return "unknown";
131 }
132
133 LatencyInfo::LatencyInfo() : LatencyInfo(SourceEventType::UNKNOWN) {} 133 LatencyInfo::LatencyInfo() : LatencyInfo(SourceEventType::UNKNOWN) {}
134 134
135 LatencyInfo::LatencyInfo(SourceEventType type) 135 LatencyInfo::LatencyInfo(SourceEventType type)
136 : input_coordinates_size_(0), 136 : input_coordinates_size_(0),
137 trace_id_(-1), 137 trace_id_(-1),
138 coalesced_(false), 138 coalesced_(false),
139 terminated_(false), 139 terminated_(false),
140 source_event_type_(type) {} 140 source_event_type_(type) {}
141 141
142 LatencyInfo::LatencyInfo(const LatencyInfo& other) = default; 142 LatencyInfo::LatencyInfo(const LatencyInfo& other) = default;
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 LatencyComponent* output) const { 348 LatencyComponent* output) const {
349 LatencyMap::const_iterator it = latency_components_.find( 349 LatencyMap::const_iterator it = latency_components_.find(
350 std::make_pair(type, id)); 350 std::make_pair(type, id));
351 if (it == latency_components_.end()) 351 if (it == latency_components_.end())
352 return false; 352 return false;
353 if (output) 353 if (output)
354 *output = it->second; 354 *output = it->second;
355 return true; 355 return true;
356 } 356 }
357 357
358 bool LatencyInfo::FindLatency(LatencyComponentType type,
359 LatencyComponent* output) const {
360 LatencyMap::const_iterator it = latency_components_.begin();
361 while (it != latency_components_.end()) {
362 if (it->first.first == type) {
363 if (output)
364 *output = it->second;
365 return true;
366 }
367 it++;
368 }
369 return false;
370 }
371
358 void LatencyInfo::RemoveLatency(LatencyComponentType type) { 372 void LatencyInfo::RemoveLatency(LatencyComponentType type) {
359 LatencyMap::iterator it = latency_components_.begin(); 373 LatencyMap::iterator it = latency_components_.begin();
360 while (it != latency_components_.end()) { 374 while (it != latency_components_.end()) {
361 if (it->first.first == type) 375 if (it->first.first == type)
362 it = latency_components_.erase(it); 376 it = latency_components_.erase(it);
363 else 377 else
364 it++; 378 it++;
365 } 379 }
366 } 380 }
367 381
368 bool LatencyInfo::AddInputCoordinate(const gfx::PointF& input_coordinate) { 382 bool LatencyInfo::AddInputCoordinate(const gfx::PointF& input_coordinate) {
369 if (input_coordinates_size_ >= kMaxInputCoordinates) 383 if (input_coordinates_size_ >= kMaxInputCoordinates)
370 return false; 384 return false;
371 input_coordinates_[input_coordinates_size_++] = input_coordinate; 385 input_coordinates_[input_coordinates_size_++] = input_coordinate;
372 return true; 386 return true;
373 } 387 }
374 388
375 } // namespace ui 389 } // namespace ui
OLDNEW
« no previous file with comments | « ui/latency/latency_info.h ('k') | ui/latency/latency_info_test_support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698