Chromium Code Reviews| 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), | |
| 119 responsiveness_histogram_(NULL), | 122 responsiveness_histogram_(NULL), |
| 120 responsiveness_1sec_histogram_(NULL), | 123 responsiveness_1sec_histogram_(NULL), |
| 121 responsiveness_10sec_histogram_(NULL), | 124 responsiveness_10sec_histogram_(NULL), |
| 122 unresponsiveness_histogram_(NULL), | 125 unresponsiveness_histogram_(NULL), |
| 123 unresponsiveness_1sec_histogram_(NULL), | 126 unresponsiveness_1sec_histogram_(NULL), |
| 124 unresponsiveness_10sec_histogram_(NULL) { | 127 unresponsiveness_10sec_histogram_(NULL) { |
| 125 InitHistograms(); | 128 InitHistograms(); |
| 126 } | 129 } |
| 127 | 130 |
| 128 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | 131 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 return; | 174 return; |
| 172 } | 175 } |
| 173 | 176 |
| 174 collected_load_metric_ = true; | 177 collected_load_metric_ = true; |
| 175 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); | 178 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); |
| 176 | 179 |
| 177 if (IsFinishedCollectingMetrics()) | 180 if (IsFinishedCollectingMetrics()) |
| 178 FinishedCollectingMetrics(FinishReason::DONE); | 181 FinishedCollectingMetrics(FinishReason::DONE); |
| 179 } | 182 } |
| 180 | 183 |
| 184 void FirstWebContentsProfiler::DidStartNavigation( | |
| 185 content::NavigationHandle* navigation_handle) { | |
| 186 if (collected_main_navigation_start_metric_) | |
| 187 return; | |
| 188 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | |
| 189 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | |
| 190 return; | |
| 191 } | |
| 192 | |
| 193 if (navigation_handle->IsInMainFrame()) { | |
|
clamy
2015/10/26 17:51:42
I think you could just DCHECK(navigation_handle->I
gab
2015/10/27 15:56:15
Done.
| |
| 194 collected_main_navigation_start_metric_ = true; | |
| 195 startup_metric_utils::RecordFirstWebContentsMainNavigationStart( | |
| 196 base::Time::Now()); | |
| 197 } | |
| 198 } | |
| 199 | |
| 200 void FirstWebContentsProfiler::DidFinishNavigation( | |
| 201 content::NavigationHandle* navigation_handle) { | |
| 202 if (collected_main_navigation_finished_metric_) | |
| 203 return; | |
| 204 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | |
| 205 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | |
| 206 return; | |
| 207 } | |
| 208 | |
| 209 if (navigation_handle->IsInMainFrame()) { | |
|
clamy
2015/10/26 17:51:42
Same here, DCHECK(navigation_handle->IsInMainFrame
gab
2015/10/27 15:56:15
Done.
| |
| 210 if (!navigation_handle->HasCommitted() || | |
| 211 navigation_handle->IsErrorPage()) { | |
| 212 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION_ERROR); | |
| 213 return; | |
| 214 } | |
| 215 collected_main_navigation_finished_metric_ = true; | |
| 216 startup_metric_utils::RecordFirstWebContentsMainNavigationFinished( | |
| 217 base::Time::Now()); | |
| 218 } | |
| 219 } | |
| 220 | |
| 181 void FirstWebContentsProfiler::NavigationEntryCommitted( | 221 void FirstWebContentsProfiler::NavigationEntryCommitted( |
| 182 const content::LoadCommittedDetails& load_details) { | 222 const content::LoadCommittedDetails& load_details) { |
| 183 // Abandon profiling on any navigation to a different page as it: | 223 // Abandon profiling on any navigation to a different page as it: |
| 184 // (1) is no longer a fair timing; and | 224 // (1) is no longer a fair timing; and |
| 185 // (2) can cause http://crbug.com/525209 where one of the timing heuristics | 225 // (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 | 226 // (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 | 227 // after a lot of idle time when the user finally navigates to another |
| 188 // page that does trigger it. | 228 // page that does trigger it. |
| 189 if (load_details.is_navigation_to_different_page()) { | 229 if (load_details.is_navigation_to_different_page()) { |
| 190 if (initial_entry_committed_) | 230 if (initial_entry_committed_) |
| 191 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION); | 231 FinishedCollectingMetrics(FinishReason::ABANDON_NEW_NAVIGATION); |
| 192 else | 232 else |
| 193 initial_entry_committed_ = true; | 233 initial_entry_committed_ = true; |
| 194 } | 234 } |
| 195 } | 235 } |
| 196 | 236 |
| 197 void FirstWebContentsProfiler::WasHidden() { | 237 void FirstWebContentsProfiler::WasHidden() { |
| 198 // Stop profiling if the content gets hidden as its load may be deprioritized | 238 // Stop profiling if the content gets hidden as its load may be deprioritized |
| 199 // and timing it becomes meaningless. | 239 // and timing it becomes meaningless. |
| 200 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); | 240 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); |
| 201 } | 241 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 100, base::Histogram::kUmaTargetedHistogramFlag); | 300 100, base::Histogram::kUmaTargetedHistogramFlag); |
| 261 | 301 |
| 262 const std::string unresponsiveness_10sec_histogram_name = | 302 const std::string unresponsiveness_10sec_histogram_name = |
| 263 "Startup.FirstWebContents.UINotResponsive_10sec"; | 303 "Startup.FirstWebContents.UINotResponsive_10sec"; |
| 264 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( | 304 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( |
| 265 unresponsiveness_10sec_histogram_name, | 305 unresponsiveness_10sec_histogram_name, |
| 266 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), | 306 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), |
| 267 100, base::Histogram::kUmaTargetedHistogramFlag); | 307 100, base::Histogram::kUmaTargetedHistogramFlag); |
| 268 } | 308 } |
| 269 #endif // !defined(OS_ANDROID) | 309 #endif // !defined(OS_ANDROID) |
| OLD | NEW |