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 | 25 |
| 25 namespace { | 26 namespace { |
| 27 | |
| 26 // The initial delay for responsiveness prober in milliseconds. | 28 // The initial delay for responsiveness prober in milliseconds. |
| 27 const int kInitialDelayMs = 20; | 29 const int kInitialDelayMs = 20; |
| 28 | 30 |
| 29 // The following is the multiplier is used to delay the probe for | 31 // The following is the multiplier is used to delay the probe for |
| 30 // responsiveness. | 32 // responsiveness. |
| 31 const double kBackoffMultiplier = 1.5; | 33 const double kBackoffMultiplier = 1.5; |
| 32 | 34 |
| 33 // The maximum backoff delay in milliseconds. | 35 // The maximum backoff delay in milliseconds. |
| 34 const int kMaxDelayMs = 250; | 36 const int kMaxDelayMs = 250; |
| 35 | 37 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 new FirstWebContentsProfiler(web_contents, delegate)); | 110 new FirstWebContentsProfiler(web_contents, delegate)); |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 return nullptr; | 113 return nullptr; |
| 112 } | 114 } |
| 113 | 115 |
| 114 FirstWebContentsProfiler::FirstWebContentsProfiler( | 116 FirstWebContentsProfiler::FirstWebContentsProfiler( |
| 115 content::WebContents* web_contents, | 117 content::WebContents* web_contents, |
| 116 Delegate* delegate) | 118 Delegate* delegate) |
| 117 : content::WebContentsObserver(web_contents), | 119 : content::WebContentsObserver(web_contents), |
| 120 initial_entry_committed_(false), | |
| 118 collected_paint_metric_(false), | 121 collected_paint_metric_(false), |
| 119 collected_load_metric_(false), | 122 collected_load_metric_(false), |
| 120 delegate_(delegate), | 123 delegate_(delegate), |
| 121 responsiveness_histogram_(NULL), | 124 responsiveness_histogram_(NULL), |
| 122 responsiveness_1sec_histogram_(NULL), | 125 responsiveness_1sec_histogram_(NULL), |
| 123 responsiveness_10sec_histogram_(NULL), | 126 responsiveness_10sec_histogram_(NULL), |
| 124 unresponsiveness_histogram_(NULL), | 127 unresponsiveness_histogram_(NULL), |
| 125 unresponsiveness_1sec_histogram_(NULL), | 128 unresponsiveness_1sec_histogram_(NULL), |
| 126 unresponsiveness_10sec_histogram_(NULL) { | 129 unresponsiveness_10sec_histogram_(NULL) { |
| 127 InitHistograms(); | 130 InitHistograms(); |
| 128 } | 131 } |
| 129 | 132 |
| 130 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | 133 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { |
| 131 if (collected_paint_metric_) | 134 if (collected_paint_metric_) |
| 132 return; | 135 return; |
| 133 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 136 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
| 134 FinishedCollectingMetrics(); | 137 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 135 return; | 138 return; |
| 136 } | 139 } |
| 137 | 140 |
| 138 collected_paint_metric_ = true; | 141 collected_paint_metric_ = true; |
| 139 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint(base::Time::Now()); | 142 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint(base::Time::Now()); |
| 140 | 143 |
| 141 metrics::TrackingSynchronizer::OnProfilingPhaseCompleted( | 144 metrics::TrackingSynchronizer::OnProfilingPhaseCompleted( |
| 142 metrics::ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | 145 metrics::ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); |
| 143 | 146 |
| 144 // Measures responsiveness now. | 147 // Measures responsiveness now. |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 155 unresponsiveness_1sec_histogram_), | 158 unresponsiveness_1sec_histogram_), |
| 156 base::TimeDelta::FromSeconds(1)); | 159 base::TimeDelta::FromSeconds(1)); |
| 157 | 160 |
| 158 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 161 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 159 FROM_HERE, | 162 FROM_HERE, |
| 160 base::Bind(&MeasureUIResponsiveness, responsiveness_10sec_histogram_, | 163 base::Bind(&MeasureUIResponsiveness, responsiveness_10sec_histogram_, |
| 161 unresponsiveness_10sec_histogram_), | 164 unresponsiveness_10sec_histogram_), |
| 162 base::TimeDelta::FromSeconds(10)); | 165 base::TimeDelta::FromSeconds(10)); |
| 163 | 166 |
| 164 if (IsFinishedCollectingMetrics()) | 167 if (IsFinishedCollectingMetrics()) |
| 165 FinishedCollectingMetrics(); | 168 FinishedCollectingMetrics(FinishReason::DONE); |
| 166 } | 169 } |
| 167 | 170 |
| 168 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { | 171 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { |
| 169 if (collected_load_metric_) | 172 if (collected_load_metric_) |
| 170 return; | 173 return; |
| 171 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 174 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
| 172 FinishedCollectingMetrics(); | 175 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
| 173 return; | 176 return; |
| 174 } | 177 } |
| 175 | 178 |
| 176 collected_load_metric_ = true; | 179 collected_load_metric_ = true; |
| 177 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); | 180 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); |
| 178 | 181 |
| 179 if (IsFinishedCollectingMetrics()) | 182 if (IsFinishedCollectingMetrics()) |
| 180 FinishedCollectingMetrics(); | 183 FinishedCollectingMetrics(FinishReason::DONE); |
| 184 } | |
| 185 | |
| 186 void FirstWebContentsProfiler::NavigationEntryCommitted( | |
| 187 const content::LoadCommittedDetails& load_details) { | |
| 188 // Stop profiling on any navigation to a different page as it (1) is no longer | |
|
rkaplow
2015/10/20 20:08:30
text seems good but I would break this is up, a lo
gab
2015/10/20 20:16:21
Kept sentence, but re-ordered in bullet points, WD
| |
| 189 // a fair timing and (2) can cause http://crbug.com/525209 where one of the | |
| 190 // timing heuristics (e.g. first paint) didn't fire for the initial content | |
| 191 // but fires after a lot of idle time when the user finally navigates to | |
| 192 // another page that does trigger it. | |
| 193 if (load_details.is_navigation_to_different_page()) { | |
| 194 if (initial_entry_committed_) | |
| 195 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION); | |
| 196 else | |
| 197 initial_entry_committed_ = true; | |
| 198 } | |
| 199 } | |
| 200 | |
| 201 void FirstWebContentsProfiler::WasHidden() { | |
| 202 // Stop profiling if the content gets hidden as its load may be deprioritized | |
| 203 // and timing it becomes meaningless. | |
| 204 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN); | |
| 181 } | 205 } |
| 182 | 206 |
| 183 void FirstWebContentsProfiler::WebContentsDestroyed() { | 207 void FirstWebContentsProfiler::WebContentsDestroyed() { |
| 184 FinishedCollectingMetrics(); | 208 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_DESTROYED); |
| 185 } | 209 } |
| 186 | 210 |
| 187 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() { | 211 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() { |
| 188 return collected_paint_metric_ && collected_load_metric_; | 212 return collected_paint_metric_ && collected_load_metric_; |
| 189 } | 213 } |
| 190 | 214 |
| 191 void FirstWebContentsProfiler::FinishedCollectingMetrics() { | 215 void FirstWebContentsProfiler::FinishedCollectingMetrics( |
| 216 FinishReason finish_reason) { | |
| 217 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason", | |
| 218 finish_reason, FinishReason::COUNT); | |
| 219 if (!collected_paint_metric_) { | |
| 220 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoPaint", | |
| 221 finish_reason, FinishReason::COUNT); | |
| 222 } | |
| 223 if (!collected_load_metric_) { | |
| 224 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoLoad", | |
| 225 finish_reason, FinishReason::COUNT); | |
| 226 } | |
| 192 delegate_->ProfilerFinishedCollectingMetrics(); | 227 delegate_->ProfilerFinishedCollectingMetrics(); |
| 193 } | 228 } |
| 194 | 229 |
| 195 void FirstWebContentsProfiler::InitHistograms() { | 230 void FirstWebContentsProfiler::InitHistograms() { |
| 196 const std::string responsiveness_histogram_name = | 231 const std::string responsiveness_histogram_name = |
| 197 "Startup.FirstWebContents.UIResponsive"; | 232 "Startup.FirstWebContents.UIResponsive"; |
| 198 responsiveness_histogram_ = base::Histogram::FactoryTimeGet( | 233 responsiveness_histogram_ = base::Histogram::FactoryTimeGet( |
| 199 responsiveness_histogram_name, base::TimeDelta::FromMilliseconds(1), | 234 responsiveness_histogram_name, base::TimeDelta::FromMilliseconds(1), |
| 200 base::TimeDelta::FromSeconds(60), 100, | 235 base::TimeDelta::FromSeconds(60), 100, |
| 201 base::Histogram::kUmaTargetedHistogramFlag); | 236 base::Histogram::kUmaTargetedHistogramFlag); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 229 100, base::Histogram::kUmaTargetedHistogramFlag); | 264 100, base::Histogram::kUmaTargetedHistogramFlag); |
| 230 | 265 |
| 231 const std::string unresponsiveness_10sec_histogram_name = | 266 const std::string unresponsiveness_10sec_histogram_name = |
| 232 "Startup.FirstWebContents.UINotResponsive_10sec"; | 267 "Startup.FirstWebContents.UINotResponsive_10sec"; |
| 233 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( | 268 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( |
| 234 unresponsiveness_10sec_histogram_name, | 269 unresponsiveness_10sec_histogram_name, |
| 235 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), | 270 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), |
| 236 100, base::Histogram::kUmaTargetedHistogramFlag); | 271 100, base::Histogram::kUmaTargetedHistogramFlag); |
| 237 } | 272 } |
| 238 #endif // !defined(OS_ANDROID) | 273 #endif // !defined(OS_ANDROID) |
| OLD | NEW |