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 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 if (expected_queueing_time_ms > 450) { | 132 if (expected_queueing_time_ms > 450) { |
132 UMA_HISTOGRAM_TIMES( | 133 UMA_HISTOGRAM_TIMES( |
133 "RendererScheduler." | 134 "RendererScheduler." |
134 "QueueingDurationWhenExpectedQueueingTime_GreaterThan.450ms", | 135 "QueueingDurationWhenExpectedQueueingTime_GreaterThan.450ms", |
135 queueing_time); | 136 queueing_time); |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 } // namespace | 140 } // namespace |
140 | 141 |
141 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() | 142 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker( |
143 bool metric_sampling) | |
142 : ukm_source_id_(-1), | 144 : ukm_source_id_(-1), |
143 last_event_id_(0), | 145 last_event_id_(0), |
144 latency_component_id_(0), | 146 latency_component_id_(0), |
145 device_scale_factor_(1), | 147 device_scale_factor_(1), |
146 has_seen_first_gesture_scroll_update_(false), | 148 has_seen_first_gesture_scroll_update_(false), |
147 active_multi_finger_gesture_(false), | 149 active_multi_finger_gesture_(false), |
148 touch_start_default_prevented_(false), | 150 touch_start_default_prevented_(false), |
151 metric_sampling_(metric_sampling), | |
149 render_widget_host_delegate_(nullptr) {} | 152 render_widget_host_delegate_(nullptr) {} |
150 | 153 |
151 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} | 154 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() {} |
152 | 155 |
153 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, | 156 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, |
154 int process_id) { | 157 int process_id) { |
155 DCHECK_EQ(0, last_event_id_); | 158 DCHECK_EQ(0, last_event_id_); |
156 DCHECK_EQ(0, latency_component_id_); | 159 DCHECK_EQ(0, latency_component_id_); |
157 last_event_id_ = static_cast<int64_t>(process_id) << 32; | 160 last_event_id_ = static_cast<int64_t>(process_id) << 32; |
158 latency_component_id_ = routing_id | last_event_id_; | 161 latency_component_id_ = routing_id | last_event_id_; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 return ukm_source_id_; | 410 return ukm_source_id_; |
408 } | 411 } |
409 | 412 |
410 void RenderWidgetHostLatencyTracker::ReportUkmScrollLatency( | 413 void RenderWidgetHostLatencyTracker::ReportUkmScrollLatency( |
411 const std::string& event_name, | 414 const std::string& event_name, |
412 const std::string& metric_name, | 415 const std::string& metric_name, |
413 const LatencyInfo::LatencyComponent& start_component, | 416 const LatencyInfo::LatencyComponent& start_component, |
414 const LatencyInfo::LatencyComponent& end_component) { | 417 const LatencyInfo::LatencyComponent& end_component) { |
415 CONFIRM_VALID_TIMING(start_component, end_component) | 418 CONFIRM_VALID_TIMING(start_component, end_component) |
416 | 419 |
420 // Only report a subset of this metric as the volume is too high. | |
421 if (event_name == "Event.ScrollUpdate.Touch") { | |
422 if (metric_sampling_ && base::RandUint64() % 10) | |
tdresser
2017/07/17 16:26:40
RandUint64 is thread safe and cryptographically se
Navid Zolghadr
2017/07/17 20:15:14
I changed the implementation to only use random on
| |
423 return; | |
424 } | |
425 | |
417 ukm::SourceId ukm_source_id = GetUkmSourceId(); | 426 ukm::SourceId ukm_source_id = GetUkmSourceId(); |
418 ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get(); | 427 ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get(); |
419 | 428 |
420 if (ukm_source_id == -1 || !ukm_recorder) | 429 if (ukm_source_id == -1 || !ukm_recorder) |
421 return; | 430 return; |
422 | 431 |
423 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 432 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
424 ukm_recorder->GetEntryBuilder(ukm_source_id, event_name.c_str()); | 433 ukm_recorder->GetEntryBuilder(ukm_source_id, event_name.c_str()); |
425 builder->AddMetric(metric_name.c_str(), (end_component.last_event_time - | 434 builder->AddMetric(metric_name.c_str(), (end_component.last_event_time - |
426 start_component.first_event_time) | 435 start_component.first_event_time) |
427 .InMicroseconds()); | 436 .InMicroseconds()); |
428 } | 437 } |
429 } // namespace content | 438 } // namespace content |
OLD | NEW |