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 #if !defined(OS_ANDROID) | 5 #if !defined(OS_ANDROID) |
6 | 6 |
7 #include "chrome/browser/metrics/first_web_contents_profiler.h" | 7 #include "chrome/browser/metrics/first_web_contents_profiler.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" |
12 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
13 #include "base/process/process_info.h" | 14 #include "base/process/process_info.h" |
14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_iterator.h" | 19 #include "chrome/browser/ui/browser_iterator.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "components/metrics/profiler/tracking_synchronizer.h" | 21 #include "components/metrics/profiler/tracking_synchronizer.h" |
21 #include "components/metrics/proto/profiler_event.pb.h" | 22 #include "components/metrics/proto/profiler_event.pb.h" |
22 #include "components/startup_metric_utils/startup_metric_utils.h" | 23 #include "components/startup_metric_utils/startup_metric_utils.h" |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/navigation_details.h" | 25 #include "content/public/browser/navigation_handle.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // The initial delay for responsiveness prober in milliseconds. | 29 // The initial delay for responsiveness prober in milliseconds. |
29 const int kInitialDelayMs = 20; | 30 const int kInitialDelayMs = 20; |
30 | 31 |
31 // The following is the multiplier is used to delay the probe for | 32 // The following is the multiplier is used to delay the probe for |
32 // responsiveness. | 33 // responsiveness. |
33 const double kBackoffMultiplier = 1.5; | 34 const double kBackoffMultiplier = 1.5; |
34 | 35 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 new FirstWebContentsProfiler(web_contents, delegate)); | 111 new FirstWebContentsProfiler(web_contents, delegate)); |
111 } | 112 } |
112 } | 113 } |
113 return nullptr; | 114 return nullptr; |
114 } | 115 } |
115 | 116 |
116 FirstWebContentsProfiler::FirstWebContentsProfiler( | 117 FirstWebContentsProfiler::FirstWebContentsProfiler( |
117 content::WebContents* web_contents, | 118 content::WebContents* web_contents, |
118 Delegate* delegate) | 119 Delegate* delegate) |
119 : content::WebContentsObserver(web_contents), | 120 : content::WebContentsObserver(web_contents), |
120 initial_entry_committed_(false), | |
121 collected_paint_metric_(false), | 121 collected_paint_metric_(false), |
122 collected_load_metric_(false), | 122 collected_load_metric_(false), |
| 123 collected_main_navigation_start_metric_(false), |
| 124 collected_main_navigation_finished_metric_(false), |
123 delegate_(delegate), | 125 delegate_(delegate), |
124 responsiveness_histogram_(NULL), | 126 responsiveness_histogram_(NULL), |
125 responsiveness_1sec_histogram_(NULL), | 127 responsiveness_1sec_histogram_(NULL), |
126 responsiveness_10sec_histogram_(NULL), | 128 responsiveness_10sec_histogram_(NULL), |
127 unresponsiveness_histogram_(NULL), | 129 unresponsiveness_histogram_(NULL), |
128 unresponsiveness_1sec_histogram_(NULL), | 130 unresponsiveness_1sec_histogram_(NULL), |
129 unresponsiveness_10sec_histogram_(NULL) { | 131 unresponsiveness_10sec_histogram_(NULL) { |
130 InitHistograms(); | 132 InitHistograms(); |
131 } | 133 } |
132 | 134 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return; | 178 return; |
177 } | 179 } |
178 | 180 |
179 collected_load_metric_ = true; | 181 collected_load_metric_ = true; |
180 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); | 182 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); |
181 | 183 |
182 if (IsFinishedCollectingMetrics()) | 184 if (IsFinishedCollectingMetrics()) |
183 FinishedCollectingMetrics(FinishReason::DONE); | 185 FinishedCollectingMetrics(FinishReason::DONE); |
184 } | 186 } |
185 | 187 |
186 void FirstWebContentsProfiler::NavigationEntryCommitted( | 188 void FirstWebContentsProfiler::DidStartNavigation( |
187 const content::LoadCommittedDetails& load_details) { | 189 content::NavigationHandle* navigation_handle) { |
188 // Abandon profiling on any navigation to a different page as it: | 190 if (collected_main_navigation_start_metric_) |
189 // (1) is no longer a fair timing; and | 191 return; |
190 // (2) can cause http://crbug.com/525209 where one of the timing heuristics | 192 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
191 // (e.g. first paint) didn't fire for the initial content but fires | 193 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
192 // after a lot of idle time when the user finally navigates to another | 194 return; |
193 // page that does trigger it. | |
194 if (load_details.is_navigation_to_different_page()) { | |
195 if (initial_entry_committed_) | |
196 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION); | |
197 else | |
198 initial_entry_committed_ = true; | |
199 } | 195 } |
| 196 |
| 197 // The first navigation has to be the main frame's. |
| 198 DCHECK(navigation_handle->IsInMainFrame()); |
| 199 |
| 200 collected_main_navigation_start_metric_ = true; |
| 201 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( |
| 202 base::Time::Now()); |
| 203 } |
| 204 |
| 205 void FirstWebContentsProfiler::DidFinishNavigation( |
| 206 content::NavigationHandle* navigation_handle) { |
| 207 if (collected_main_navigation_finished_metric_) { |
| 208 // Abandon profiling on a top-level navigation to a different page as it: |
| 209 // (1) is no longer a fair timing; and |
| 210 // (2) can cause http://crbug.com/525209 where one of the timing |
| 211 // heuristics (e.g. first paint) didn't fire for the initial content |
| 212 // but fires after a lot of idle time when the user finally navigates |
| 213 // to another page that does trigger it. |
| 214 if (navigation_handle->IsInMainFrame() && |
| 215 navigation_handle->HasCommitted() && |
| 216 !navigation_handle->IsSamePage()) { |
| 217 FinishedCollectingMetrics(FinishReason::ABANDON_NEW_NAVIGATION); |
| 218 } |
| 219 return; |
| 220 } |
| 221 |
| 222 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
| 223 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 224 return; |
| 225 } |
| 226 |
| 227 // The first navigation has to be the main frame's. |
| 228 DCHECK(navigation_handle->IsInMainFrame()); |
| 229 |
| 230 if (!navigation_handle->HasCommitted() || |
| 231 navigation_handle->IsErrorPage()) { |
| 232 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); |
| 233 return; |
| 234 } |
| 235 |
| 236 collected_main_navigation_finished_metric_ = true; |
| 237 startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( |
| 238 base::Time::Now()); |
200 } | 239 } |
201 | 240 |
202 void FirstWebContentsProfiler::WasHidden() { | 241 void FirstWebContentsProfiler::WasHidden() { |
203 // Stop profiling if the content gets hidden as its load may be deprioritized | 242 // Stop profiling if the content gets hidden as its load may be deprioritized |
204 // and timing it becomes meaningless. | 243 // and timing it becomes meaningless. |
205 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); | 244 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); |
206 } | 245 } |
207 | 246 |
208 void FirstWebContentsProfiler::WebContentsDestroyed() { | 247 void FirstWebContentsProfiler::WebContentsDestroyed() { |
209 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_DESTROYED); | 248 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_DESTROYED); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 100, base::Histogram::kUmaTargetedHistogramFlag); | 304 100, base::Histogram::kUmaTargetedHistogramFlag); |
266 | 305 |
267 const std::string unresponsiveness_10sec_histogram_name = | 306 const std::string unresponsiveness_10sec_histogram_name = |
268 "Startup.FirstWebContents.UINotResponsive_10sec"; | 307 "Startup.FirstWebContents.UINotResponsive_10sec"; |
269 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( | 308 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( |
270 unresponsiveness_10sec_histogram_name, | 309 unresponsiveness_10sec_histogram_name, |
271 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), | 310 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), |
272 100, base::Histogram::kUmaTargetedHistogramFlag); | 311 100, base::Histogram::kUmaTargetedHistogramFlag); |
273 } | 312 } |
274 #endif // !defined(OS_ANDROID) | 313 #endif // !defined(OS_ANDROID) |
OLD | NEW |