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/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/process/process_info.h" | 13 #include "base/process/process_info.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_iterator.h" | 18 #include "chrome/browser/ui/browser_iterator.h" |
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
20 #include "components/metrics/profiler/tracking_synchronizer.h" | 20 #include "components/metrics/profiler/tracking_synchronizer.h" |
21 #include "components/metrics/proto/profiler_event.pb.h" | 21 #include "components/metrics/proto/profiler_event.pb.h" |
22 #include "components/startup_metric_utils/startup_metric_utils.h" | 22 #include "components/startup_metric_utils/startup_metric_utils.h" |
23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/navigation_details.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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 } | 110 } |
110 } | 111 } |
111 } | 112 } |
112 | 113 |
113 FirstWebContentsProfiler::FirstWebContentsProfiler( | 114 FirstWebContentsProfiler::FirstWebContentsProfiler( |
114 content::WebContents* web_contents) | 115 content::WebContents* web_contents) |
115 : content::WebContentsObserver(web_contents), | 116 : content::WebContentsObserver(web_contents), |
116 initial_entry_committed_(false), | 117 initial_entry_committed_(false), |
117 collected_paint_metric_(false), | 118 collected_paint_metric_(false), |
118 collected_load_metric_(false), | 119 collected_load_metric_(false), |
120 collected_main_navigation_start_metric_(false), | |
121 collected_main_navigation_finished_metric_(false), | |
122 collected_main_navigation_finished_all_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 |
132 FirstWebContentsProfiler::~FirstWebContentsProfiler() { | |
133 } | |
134 | |
128 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | 135 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { |
129 if (collected_paint_metric_) | 136 if (collected_paint_metric_) |
130 return; | 137 return; |
131 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 138 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
132 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 139 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
133 return; | 140 return; |
134 } | 141 } |
135 | 142 |
136 collected_paint_metric_ = true; | 143 collected_paint_metric_ = true; |
137 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint(base::Time::Now()); | 144 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint(base::Time::Now()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 return; | 178 return; |
172 } | 179 } |
173 | 180 |
174 collected_load_metric_ = true; | 181 collected_load_metric_ = true; |
175 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); | 182 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); |
176 | 183 |
177 if (IsFinishedCollectingMetrics()) | 184 if (IsFinishedCollectingMetrics()) |
178 FinishedCollectingMetrics(FinishReason::DONE); | 185 FinishedCollectingMetrics(FinishReason::DONE); |
179 } | 186 } |
180 | 187 |
188 void FirstWebContentsProfiler::DidStartNavigation( | |
189 content::NavigationHandle* navigation_handle) { | |
190 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | |
191 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | |
192 return; | |
193 } | |
194 | |
195 if (!navigation_handle->IsInMainFrame()) | |
196 return; | |
197 | |
198 // Record that the navigation identified by |navigation_handle| has started. | |
199 // DidFinishNavigation() assumes that every |navigation_handle| seen here is a | |
200 // new navigation, assert that this is true. | |
201 bool new_navigation = | |
202 main_navigation_handles_.insert(navigation_handle).second; | |
203 DCHECK(new_navigation); | |
204 | |
205 if (!collected_main_navigation_start_metric_) { | |
206 collected_main_navigation_start_metric_ = true; | |
207 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( | |
208 base::Time::Now()); | |
209 } | |
210 } | |
211 | |
212 void FirstWebContentsProfiler::DidFinishNavigation( | |
213 content::NavigationHandle* navigation_handle) { | |
214 if (collected_main_navigation_finished_all_metric_) | |
215 return; | |
216 | |
217 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | |
218 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | |
219 return; | |
220 } | |
221 | |
222 if (!navigation_handle->IsInMainFrame()) | |
223 return; | |
clamy
2015/10/22 17:21:07
You may also need to check whether the navigation
gab
2015/10/22 20:37:39
Good point, even added it as an explicit early exi
| |
224 | |
225 // Remove |navigation_handle| from the tracked |main_navigation_handles_|. | |
226 size_t handles_tracked = main_navigation_handles_.erase(navigation_handle); | |
227 DCHECK_EQ(handles_tracked, 1U); | |
228 | |
229 // First navigation in main frame is complete. | |
230 if (!collected_main_navigation_finished_metric_) { | |
231 collected_main_navigation_finished_metric_ = true; | |
232 startup_metric_utils::RecordFirstWebContentsMainNavigationFinishedFirst( | |
233 base::Time::Now()); | |
234 } | |
235 | |
236 // All known navigations in main frame are complete. | |
237 if (main_navigation_handles_.empty()) { | |
238 collected_main_navigation_finished_all_metric_ = true; | |
239 startup_metric_utils::RecordFirstWebContentsMainNavigationFinishedAll( | |
clamy
2015/10/22 17:21:07
I don't think this is really needed.
While it's t
gab
2015/10/22 20:37:39
Ah ok, maybe this should be made clearer in WebCon
| |
240 base::Time::Now()); | |
241 } | |
242 } | |
243 | |
181 void FirstWebContentsProfiler::NavigationEntryCommitted( | 244 void FirstWebContentsProfiler::NavigationEntryCommitted( |
182 const content::LoadCommittedDetails& load_details) { | 245 const content::LoadCommittedDetails& load_details) { |
183 // Abandon profiling on any navigation to a different page as it: | 246 // Abandon profiling on any navigation to a different page as it: |
184 // (1) is no longer a fair timing; and | 247 // (1) is no longer a fair timing; and |
185 // (2) can cause http://crbug.com/525209 where one of the timing heuristics | 248 // (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 | 249 // (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 | 250 // after a lot of idle time when the user finally navigates to another |
188 // page that does trigger it. | 251 // page that does trigger it. |
189 if (load_details.is_navigation_to_different_page()) { | 252 if (load_details.is_navigation_to_different_page()) { |
190 if (initial_entry_committed_) | 253 if (initial_entry_committed_) |
191 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION); | 254 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION); |
gab
2015/10/22 20:37:39
While I have your attention and expertise, WDYT of
clamy
2015/10/26 17:51:42
There could be an issue with client-side redirects
gab
2015/10/27 15:56:15
Thanks, +creis to chime in on details.
From what
Charlie Reis
2015/10/27 18:35:21
You will get NavigationEntryCommitted for both the
gab
2015/10/28 01:55:12
Well, we are collecting first commit, but we're al
| |
192 else | 255 else |
193 initial_entry_committed_ = true; | 256 initial_entry_committed_ = true; |
194 } | 257 } |
195 } | 258 } |
196 | 259 |
197 void FirstWebContentsProfiler::WasHidden() { | 260 void FirstWebContentsProfiler::WasHidden() { |
198 // Stop profiling if the content gets hidden as its load may be deprioritized | 261 // Stop profiling if the content gets hidden as its load may be deprioritized |
199 // and timing it becomes meaningless. | 262 // and timing it becomes meaningless. |
200 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); | 263 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); |
201 } | 264 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 100, base::Histogram::kUmaTargetedHistogramFlag); | 323 100, base::Histogram::kUmaTargetedHistogramFlag); |
261 | 324 |
262 const std::string unresponsiveness_10sec_histogram_name = | 325 const std::string unresponsiveness_10sec_histogram_name = |
263 "Startup.FirstWebContents.UINotResponsive_10sec"; | 326 "Startup.FirstWebContents.UINotResponsive_10sec"; |
264 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( | 327 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( |
265 unresponsiveness_10sec_histogram_name, | 328 unresponsiveness_10sec_histogram_name, |
266 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), | 329 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), |
267 100, base::Histogram::kUmaTargetedHistogramFlag); | 330 100, base::Histogram::kUmaTargetedHistogramFlag); |
268 } | 331 } |
269 #endif // !defined(OS_ANDROID) | 332 #endif // !defined(OS_ANDROID) |
OLD | NEW |