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_details.h" |
| 26 #include "content/public/browser/navigation_handle.h" |
25 | 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 // The initial delay for responsiveness prober in milliseconds. | 30 // The initial delay for responsiveness prober in milliseconds. |
29 const int kInitialDelayMs = 20; | 31 const int kInitialDelayMs = 20; |
30 | 32 |
31 // The following is the multiplier is used to delay the probe for | 33 // The following is the multiplier is used to delay the probe for |
32 // responsiveness. | 34 // responsiveness. |
33 const double kBackoffMultiplier = 1.5; | 35 const double kBackoffMultiplier = 1.5; |
34 | 36 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 111 } |
110 } | 112 } |
111 } | 113 } |
112 | 114 |
113 FirstWebContentsProfiler::FirstWebContentsProfiler( | 115 FirstWebContentsProfiler::FirstWebContentsProfiler( |
114 content::WebContents* web_contents) | 116 content::WebContents* web_contents) |
115 : content::WebContentsObserver(web_contents), | 117 : content::WebContentsObserver(web_contents), |
116 initial_entry_committed_(false), | 118 initial_entry_committed_(false), |
117 collected_paint_metric_(false), | 119 collected_paint_metric_(false), |
118 collected_load_metric_(false), | 120 collected_load_metric_(false), |
| 121 collected_main_navigation_start_metric_(false), |
| 122 collected_main_navigation_finished_metric_(false), |
119 responsiveness_histogram_(NULL), | 123 responsiveness_histogram_(NULL), |
120 responsiveness_1sec_histogram_(NULL), | 124 responsiveness_1sec_histogram_(NULL), |
121 responsiveness_10sec_histogram_(NULL), | 125 responsiveness_10sec_histogram_(NULL), |
122 unresponsiveness_histogram_(NULL), | 126 unresponsiveness_histogram_(NULL), |
123 unresponsiveness_1sec_histogram_(NULL), | 127 unresponsiveness_1sec_histogram_(NULL), |
124 unresponsiveness_10sec_histogram_(NULL) { | 128 unresponsiveness_10sec_histogram_(NULL) { |
125 InitHistograms(); | 129 InitHistograms(); |
126 } | 130 } |
127 | 131 |
128 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | 132 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 return; | 175 return; |
172 } | 176 } |
173 | 177 |
174 collected_load_metric_ = true; | 178 collected_load_metric_ = true; |
175 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); | 179 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); |
176 | 180 |
177 if (IsFinishedCollectingMetrics()) | 181 if (IsFinishedCollectingMetrics()) |
178 FinishedCollectingMetrics(FinishReason::DONE); | 182 FinishedCollectingMetrics(FinishReason::DONE); |
179 } | 183 } |
180 | 184 |
| 185 void FirstWebContentsProfiler::DidStartNavigation( |
| 186 content::NavigationHandle* navigation_handle) { |
| 187 if (collected_main_navigation_start_metric_) |
| 188 return; |
| 189 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
| 190 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 191 return; |
| 192 } |
| 193 |
| 194 // The first navigation has to be the main frame's. |
| 195 DCHECK(navigation_handle->IsInMainFrame()); |
| 196 |
| 197 collected_main_navigation_start_metric_ = true; |
| 198 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( |
| 199 base::Time::Now()); |
| 200 } |
| 201 |
| 202 void FirstWebContentsProfiler::DidFinishNavigation( |
| 203 content::NavigationHandle* navigation_handle) { |
| 204 if (collected_main_navigation_finished_metric_) |
| 205 return; |
| 206 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
| 207 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 208 return; |
| 209 } |
| 210 |
| 211 // The first navigation has to be the main frame's. |
| 212 DCHECK(navigation_handle->IsInMainFrame()); |
| 213 |
| 214 if (!navigation_handle->HasCommitted() || |
| 215 navigation_handle->IsErrorPage()) { |
| 216 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); |
| 217 return; |
| 218 } |
| 219 |
| 220 collected_main_navigation_finished_metric_ = true; |
| 221 startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( |
| 222 base::Time::Now()); |
| 223 } |
| 224 |
181 void FirstWebContentsProfiler::NavigationEntryCommitted( | 225 void FirstWebContentsProfiler::NavigationEntryCommitted( |
182 const content::LoadCommittedDetails& load_details) { | 226 const content::LoadCommittedDetails& load_details) { |
183 // Abandon profiling on any navigation to a different page as it: | 227 // Abandon profiling on any navigation to a different page as it: |
184 // (1) is no longer a fair timing; and | 228 // (1) is no longer a fair timing; and |
185 // (2) can cause http://crbug.com/525209 where one of the timing heuristics | 229 // (2) can cause http://crbug.com/525209 where one of the timing heuristics |
186 // (e.g. first paint) didn't fire for the initial content but fires | 230 // (e.g. first paint) didn't fire for the initial content but fires |
187 // after a lot of idle time when the user finally navigates to another | 231 // after a lot of idle time when the user finally navigates to another |
188 // page that does trigger it. | 232 // page that does trigger it. |
189 if (load_details.is_navigation_to_different_page()) { | 233 if (load_details.is_navigation_to_different_page()) { |
190 if (initial_entry_committed_) | 234 if (initial_entry_committed_) |
191 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION); | 235 FinishedCollectingMetrics(FinishReason::ABANDON_NEW_NAVIGATION); |
192 else | 236 else |
193 initial_entry_committed_ = true; | 237 initial_entry_committed_ = true; |
194 } | 238 } |
195 } | 239 } |
196 | 240 |
197 void FirstWebContentsProfiler::WasHidden() { | 241 void FirstWebContentsProfiler::WasHidden() { |
198 // 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 |
199 // and timing it becomes meaningless. | 243 // and timing it becomes meaningless. |
200 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); | 244 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); |
201 } | 245 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 100, base::Histogram::kUmaTargetedHistogramFlag); | 304 100, base::Histogram::kUmaTargetedHistogramFlag); |
261 | 305 |
262 const std::string unresponsiveness_10sec_histogram_name = | 306 const std::string unresponsiveness_10sec_histogram_name = |
263 "Startup.FirstWebContents.UINotResponsive_10sec"; | 307 "Startup.FirstWebContents.UINotResponsive_10sec"; |
264 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( | 308 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( |
265 unresponsiveness_10sec_histogram_name, | 309 unresponsiveness_10sec_histogram_name, |
266 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), | 310 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), |
267 100, base::Histogram::kUmaTargetedHistogramFlag); | 311 100, base::Histogram::kUmaTargetedHistogramFlag); |
268 } | 312 } |
269 #endif // !defined(OS_ANDROID) | 313 #endif // !defined(OS_ANDROID) |
OLD | NEW |