OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/renderer_host/input/render_widget_host_latency_tracker .h" | 5 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker .h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram_functions.h" | 10 #include "base/metrics/histogram_functions.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/rand_util.h" | |
12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
13 #include "components/rappor/public/rappor_utils.h" | 14 #include "components/rappor/public/rappor_utils.h" |
14 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 15 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/content_browser_client.h" | 17 #include "content/public/browser/content_browser_client.h" |
17 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
18 #include "services/metrics/public/cpp/ukm_entry_builder.h" | 19 #include "services/metrics/public/cpp/ukm_entry_builder.h" |
19 #include "ui/events/blink/web_input_event_traits.h" | 20 #include "ui/events/blink/web_input_event_traits.h" |
20 #include "ui/latency/latency_histogram_macros.h" | 21 #include "ui/latency/latency_histogram_macros.h" |
21 | 22 |
22 using blink::WebGestureEvent; | 23 using blink::WebGestureEvent; |
23 using blink::WebInputEvent; | 24 using blink::WebInputEvent; |
24 using blink::WebMouseEvent; | 25 using blink::WebMouseEvent; |
25 using blink::WebMouseWheelEvent; | 26 using blink::WebMouseWheelEvent; |
26 using blink::WebTouchEvent; | 27 using blink::WebTouchEvent; |
27 using ui::LatencyInfo; | 28 using ui::LatencyInfo; |
28 | 29 |
29 namespace content { | 30 namespace content { |
30 namespace { | 31 namespace { |
31 | 32 |
33 constexpr int kSamplingInterval = 10; | |
34 | |
32 std::string WebInputEventTypeToInputModalityString(WebInputEvent::Type type) { | 35 std::string WebInputEventTypeToInputModalityString(WebInputEvent::Type type) { |
33 if (type == blink::WebInputEvent::kMouseWheel) { | 36 if (type == blink::WebInputEvent::kMouseWheel) { |
34 return "Wheel"; | 37 return "Wheel"; |
35 } else if (WebInputEvent::IsKeyboardEventType(type)) { | 38 } else if (WebInputEvent::IsKeyboardEventType(type)) { |
36 // We should only be reporting latency for key presses. | 39 // We should only be reporting latency for key presses. |
37 DCHECK(type == WebInputEvent::kRawKeyDown || type == WebInputEvent::kChar); | 40 DCHECK(type == WebInputEvent::kRawKeyDown || type == WebInputEvent::kChar); |
38 return "KeyPress"; | 41 return "KeyPress"; |
39 } else if (WebInputEvent::IsMouseEventType(type)) { | 42 } else if (WebInputEvent::IsMouseEventType(type)) { |
40 return "Mouse"; | 43 return "Mouse"; |
41 } else if (WebInputEvent::IsTouchEventType(type)) { | 44 } else if (WebInputEvent::IsTouchEventType(type)) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 if (expected_queueing_time_ms > 450) { | 134 if (expected_queueing_time_ms > 450) { |
132 UMA_HISTOGRAM_TIMES( | 135 UMA_HISTOGRAM_TIMES( |
133 "RendererScheduler." | 136 "RendererScheduler." |
134 "QueueingDurationWhenExpectedQueueingTime_GreaterThan.450ms", | 137 "QueueingDurationWhenExpectedQueueingTime_GreaterThan.450ms", |
135 queueing_time); | 138 queueing_time); |
136 } | 139 } |
137 } | 140 } |
138 | 141 |
139 } // namespace | 142 } // namespace |
140 | 143 |
141 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() | 144 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker( |
145 bool metric_sampling) | |
142 : ukm_source_id_(-1), | 146 : ukm_source_id_(-1), |
143 last_event_id_(0), | 147 last_event_id_(0), |
144 latency_component_id_(0), | 148 latency_component_id_(0), |
145 device_scale_factor_(1), | 149 device_scale_factor_(1), |
146 has_seen_first_gesture_scroll_update_(false), | 150 has_seen_first_gesture_scroll_update_(false), |
147 active_multi_finger_gesture_(false), | 151 active_multi_finger_gesture_(false), |
148 touch_start_default_prevented_(false), | 152 touch_start_default_prevented_(false), |
149 render_widget_host_delegate_(nullptr) {} | 153 metric_sampling_(metric_sampling), |
154 metric_sampling_countdown_(-1), | |
155 render_widget_host_delegate_(nullptr) { | |
156 if (metric_sampling) | |
157 metric_sampling_countdown_ = base::RandUint64() % kSamplingInterval; | |
158 } | |
150 | 159 |
151 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} | 160 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} |
152 | 161 |
153 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, | 162 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, |
154 int process_id) { | 163 int process_id) { |
155 DCHECK_EQ(0, last_event_id_); | 164 DCHECK_EQ(0, last_event_id_); |
156 DCHECK_EQ(0, latency_component_id_); | 165 DCHECK_EQ(0, latency_component_id_); |
157 last_event_id_ = static_cast<int64_t>(process_id) << 32; | 166 last_event_id_ = static_cast<int64_t>(process_id) << 32; |
158 latency_component_id_ = routing_id | last_event_id_; | 167 latency_component_id_ = routing_id | last_event_id_; |
159 } | 168 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 return ukm_source_id_; | 416 return ukm_source_id_; |
408 } | 417 } |
409 | 418 |
410 void RenderWidgetHostLatencyTracker::ReportUkmScrollLatency( | 419 void RenderWidgetHostLatencyTracker::ReportUkmScrollLatency( |
411 const std::string& event_name, | 420 const std::string& event_name, |
412 const std::string& metric_name, | 421 const std::string& metric_name, |
413 const LatencyInfo::LatencyComponent& start_component, | 422 const LatencyInfo::LatencyComponent& start_component, |
414 const LatencyInfo::LatencyComponent& end_component) { | 423 const LatencyInfo::LatencyComponent& end_component) { |
415 CONFIRM_VALID_TIMING(start_component, end_component) | 424 CONFIRM_VALID_TIMING(start_component, end_component) |
416 | 425 |
426 // Only report a subset of this metric as the volume is too high. | |
427 if (event_name == "Event.ScrollUpdate.Touch") { | |
428 metric_sampling_countdown_++; | |
tdresser
2017/07/17 20:25:22
"countdown" implies it counts down, but it counts
Navid Zolghadr
2017/07/19 15:57:46
Done.
| |
429 metric_sampling_countdown_ %= kSamplingInterval; | |
430 if (metric_sampling_ && metric_sampling_countdown_) | |
431 return; | |
432 metric_sampling_countdown_ = 0; | |
dtapuska
2017/07/17 20:21:41
This line is useless.
Navid Zolghadr
2017/07/19 15:57:46
Done.
| |
433 } | |
434 | |
417 ukm::SourceId ukm_source_id = GetUkmSourceId(); | 435 ukm::SourceId ukm_source_id = GetUkmSourceId(); |
418 ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get(); | 436 ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get(); |
419 | 437 |
420 if (ukm_source_id == -1 || !ukm_recorder) | 438 if (ukm_source_id == -1 || !ukm_recorder) |
421 return; | 439 return; |
422 | 440 |
423 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 441 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
424 ukm_recorder->GetEntryBuilder(ukm_source_id, event_name.c_str()); | 442 ukm_recorder->GetEntryBuilder(ukm_source_id, event_name.c_str()); |
425 builder->AddMetric(metric_name.c_str(), (end_component.last_event_time - | 443 builder->AddMetric(metric_name.c_str(), (end_component.last_event_time - |
426 start_component.first_event_time) | 444 start_component.first_event_time) |
427 .InMicroseconds()); | 445 .InMicroseconds()); |
428 } | 446 } |
429 } // namespace content | 447 } // namespace content |
OLD | NEW |