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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 return nullptr; | 115 return nullptr; |
114 } | 116 } |
115 | 117 |
116 FirstWebContentsProfiler::FirstWebContentsProfiler( | 118 FirstWebContentsProfiler::FirstWebContentsProfiler( |
117 content::WebContents* web_contents, | 119 content::WebContents* web_contents, |
118 Delegate* delegate) | 120 Delegate* delegate) |
119 : content::WebContentsObserver(web_contents), | 121 : content::WebContentsObserver(web_contents), |
120 initial_entry_committed_(false), | 122 initial_entry_committed_(false), |
121 collected_paint_metric_(false), | 123 collected_paint_metric_(false), |
122 collected_load_metric_(false), | 124 collected_load_metric_(false), |
125 collected_main_navigation_start_metric_(false), | |
126 collected_main_navigation_finished_metric_(false), | |
123 delegate_(delegate), | 127 delegate_(delegate), |
124 responsiveness_histogram_(NULL), | 128 responsiveness_histogram_(NULL), |
125 responsiveness_1sec_histogram_(NULL), | 129 responsiveness_1sec_histogram_(NULL), |
126 responsiveness_10sec_histogram_(NULL), | 130 responsiveness_10sec_histogram_(NULL), |
127 unresponsiveness_histogram_(NULL), | 131 unresponsiveness_histogram_(NULL), |
128 unresponsiveness_1sec_histogram_(NULL), | 132 unresponsiveness_1sec_histogram_(NULL), |
129 unresponsiveness_10sec_histogram_(NULL) { | 133 unresponsiveness_10sec_histogram_(NULL) { |
130 InitHistograms(); | 134 InitHistograms(); |
131 } | 135 } |
132 | 136 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 return; | 180 return; |
177 } | 181 } |
178 | 182 |
179 collected_load_metric_ = true; | 183 collected_load_metric_ = true; |
180 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); | 184 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); |
181 | 185 |
182 if (IsFinishedCollectingMetrics()) | 186 if (IsFinishedCollectingMetrics()) |
183 FinishedCollectingMetrics(FinishReason::DONE); | 187 FinishedCollectingMetrics(FinishReason::DONE); |
184 } | 188 } |
185 | 189 |
190 void FirstWebContentsProfiler::DidStartNavigation( | |
191 content::NavigationHandle* navigation_handle) { | |
192 if (collected_main_navigation_start_metric_) | |
193 return; | |
194 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | |
195 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | |
196 return; | |
197 } | |
198 | |
199 // The first navigation has to be the main frame's. | |
200 DCHECK(navigation_handle->IsInMainFrame()); | |
201 | |
202 collected_main_navigation_start_metric_ = true; | |
203 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( | |
204 base::Time::Now()); | |
205 } | |
206 | |
207 void FirstWebContentsProfiler::DidFinishNavigation( | |
208 content::NavigationHandle* navigation_handle) { | |
209 if (collected_main_navigation_finished_metric_) | |
210 return; | |
211 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | |
212 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | |
213 return; | |
214 } | |
215 | |
216 // The first navigation has to be the main frame's. | |
217 DCHECK(navigation_handle->IsInMainFrame()); | |
218 | |
219 if (!navigation_handle->HasCommitted() || | |
220 navigation_handle->IsErrorPage()) { | |
221 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); | |
222 return; | |
223 } | |
224 | |
225 collected_main_navigation_finished_metric_ = true; | |
226 startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( | |
227 base::Time::Now()); | |
228 } | |
229 | |
186 void FirstWebContentsProfiler::NavigationEntryCommitted( | 230 void FirstWebContentsProfiler::NavigationEntryCommitted( |
clamy
2015/10/28 11:55:59
I think this can be merged inside DidFinishNavigat
gab
2015/10/28 20:17:38
Awesome, done :-)! (also added IsMainFrame() to th
Charlie Reis
2015/10/28 20:58:26
IsSamePage means you haven't left the current docu
| |
187 const content::LoadCommittedDetails& load_details) { | 231 const content::LoadCommittedDetails& load_details) { |
188 // Abandon profiling on any navigation to a different page as it: | 232 // Abandon profiling on any navigation to a different page as it: |
189 // (1) is no longer a fair timing; and | 233 // (1) is no longer a fair timing; and |
190 // (2) can cause http://crbug.com/525209 where one of the timing heuristics | 234 // (2) can cause http://crbug.com/525209 where one of the timing heuristics |
191 // (e.g. first paint) didn't fire for the initial content but fires | 235 // (e.g. first paint) didn't fire for the initial content but fires |
192 // after a lot of idle time when the user finally navigates to another | 236 // after a lot of idle time when the user finally navigates to another |
193 // page that does trigger it. | 237 // page that does trigger it. |
194 if (load_details.is_navigation_to_different_page()) { | 238 if (load_details.is_navigation_to_different_page()) { |
195 if (initial_entry_committed_) | 239 if (initial_entry_committed_) |
196 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION); | 240 FinishedCollectingMetrics(FinishReason::ABANDON_NEW_NAVIGATION); |
197 else | 241 else |
198 initial_entry_committed_ = true; | 242 initial_entry_committed_ = true; |
199 } | 243 } |
200 } | 244 } |
201 | 245 |
202 void FirstWebContentsProfiler::WasHidden() { | 246 void FirstWebContentsProfiler::WasHidden() { |
203 // Stop profiling if the content gets hidden as its load may be deprioritized | 247 // Stop profiling if the content gets hidden as its load may be deprioritized |
204 // and timing it becomes meaningless. | 248 // and timing it becomes meaningless. |
205 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); | 249 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); |
206 } | 250 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 100, base::Histogram::kUmaTargetedHistogramFlag); | 309 100, base::Histogram::kUmaTargetedHistogramFlag); |
266 | 310 |
267 const std::string unresponsiveness_10sec_histogram_name = | 311 const std::string unresponsiveness_10sec_histogram_name = |
268 "Startup.FirstWebContents.UINotResponsive_10sec"; | 312 "Startup.FirstWebContents.UINotResponsive_10sec"; |
269 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( | 313 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( |
270 unresponsiveness_10sec_histogram_name, | 314 unresponsiveness_10sec_histogram_name, |
271 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), | 315 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), |
272 100, base::Histogram::kUmaTargetedHistogramFlag); | 316 100, base::Histogram::kUmaTargetedHistogramFlag); |
273 } | 317 } |
274 #endif // !defined(OS_ANDROID) | 318 #endif // !defined(OS_ANDROID) |
OLD | NEW |