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 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 FirstWebContentsProfiler::FirstWebContentsProfiler( | 117 FirstWebContentsProfiler::FirstWebContentsProfiler( |
118 content::WebContents* web_contents, | 118 content::WebContents* web_contents, |
119 Delegate* delegate) | 119 Delegate* delegate) |
120 : content::WebContentsObserver(web_contents), | 120 : content::WebContentsObserver(web_contents), |
121 collected_paint_metric_(false), | 121 collected_paint_metric_(false), |
122 collected_load_metric_(false), | 122 collected_load_metric_(false), |
123 collected_main_navigation_start_metric_(false), | 123 collected_main_navigation_start_metric_(false), |
124 collected_main_navigation_finished_metric_(false), | 124 collected_main_navigation_finished_metric_(false), |
| 125 finished_(false), |
125 delegate_(delegate), | 126 delegate_(delegate), |
126 responsiveness_histogram_(NULL), | 127 responsiveness_histogram_(NULL), |
127 responsiveness_1sec_histogram_(NULL), | 128 responsiveness_1sec_histogram_(NULL), |
128 responsiveness_10sec_histogram_(NULL), | 129 responsiveness_10sec_histogram_(NULL), |
129 unresponsiveness_histogram_(NULL), | 130 unresponsiveness_histogram_(NULL), |
130 unresponsiveness_1sec_histogram_(NULL), | 131 unresponsiveness_1sec_histogram_(NULL), |
131 unresponsiveness_10sec_histogram_(NULL) { | 132 unresponsiveness_10sec_histogram_(NULL) { |
132 InitHistograms(); | 133 InitHistograms(); |
133 } | 134 } |
134 | 135 |
135 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | 136 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { |
136 if (collected_paint_metric_) | 137 if (collected_paint_metric_) |
137 return; | 138 return; |
138 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 139 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
139 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 140 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
140 return; | 141 return; |
141 } | 142 } |
142 | 143 |
143 collected_paint_metric_ = true; | 144 collected_paint_metric_ = true; |
144 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint(base::Time::Now()); | 145 const base::Time now = base::Time::Now(); |
| 146 // Record the old metric unconditionally. |
| 147 startup_metric_utils::RecordDeprecatedFirstWebContentsNonEmptyPaint(now); |
| 148 if (!finished_) |
| 149 startup_metric_utils::RecordFirstWebContentsNonEmptyPaint(now); |
145 | 150 |
146 metrics::TrackingSynchronizer::OnProfilingPhaseCompleted( | 151 metrics::TrackingSynchronizer::OnProfilingPhaseCompleted( |
147 metrics::ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | 152 metrics::ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); |
148 | 153 |
149 // Measures responsiveness now. | 154 // Measures responsiveness now. |
150 MeasureUIResponsiveness(responsiveness_histogram_, | 155 MeasureUIResponsiveness(responsiveness_histogram_, |
151 unresponsiveness_histogram_); | 156 unresponsiveness_histogram_); |
152 | 157 |
153 // As it was observed that sometimes the task queue can be free immediately | 158 // As it was observed that sometimes the task queue can be free immediately |
154 // after the first paint but get overloaded shortly thereafter, here we | 159 // after the first paint but get overloaded shortly thereafter, here we |
(...skipping 17 matching lines...) Expand all Loading... |
172 | 177 |
173 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { | 178 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { |
174 if (collected_load_metric_) | 179 if (collected_load_metric_) |
175 return; | 180 return; |
176 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 181 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
177 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); | 182 FinishedCollectingMetrics(FinishReason::ABANDON_BLOCKING_UI); |
178 return; | 183 return; |
179 } | 184 } |
180 | 185 |
181 collected_load_metric_ = true; | 186 collected_load_metric_ = true; |
182 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(base::Time::Now()); | 187 const base::Time now = base::Time::Now(); |
| 188 // Record the old metric unconditionally. |
| 189 startup_metric_utils::RecordDeprecatedFirstWebContentsMainFrameLoad(now); |
| 190 if (!finished_) |
| 191 startup_metric_utils::RecordFirstWebContentsMainFrameLoad(now); |
183 | 192 |
184 if (IsFinishedCollectingMetrics()) | 193 if (IsFinishedCollectingMetrics()) |
185 FinishedCollectingMetrics(FinishReason::DONE); | 194 FinishedCollectingMetrics(FinishReason::DONE); |
186 } | 195 } |
187 | 196 |
188 void FirstWebContentsProfiler::DidStartNavigation( | 197 void FirstWebContentsProfiler::DidStartNavigation( |
189 content::NavigationHandle* navigation_handle) { | 198 content::NavigationHandle* navigation_handle) { |
190 if (collected_main_navigation_start_metric_) | 199 if (collected_main_navigation_start_metric_) |
191 return; | 200 return; |
192 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { | 201 if (startup_metric_utils::WasNonBrowserUIDisplayed()) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 void FirstWebContentsProfiler::WebContentsDestroyed() { | 256 void FirstWebContentsProfiler::WebContentsDestroyed() { |
248 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_DESTROYED); | 257 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_DESTROYED); |
249 } | 258 } |
250 | 259 |
251 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() { | 260 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() { |
252 return collected_paint_metric_ && collected_load_metric_; | 261 return collected_paint_metric_ && collected_load_metric_; |
253 } | 262 } |
254 | 263 |
255 void FirstWebContentsProfiler::FinishedCollectingMetrics( | 264 void FirstWebContentsProfiler::FinishedCollectingMetrics( |
256 FinishReason finish_reason) { | 265 FinishReason finish_reason) { |
257 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason", | 266 if (!finished_) { |
258 finish_reason, FinishReason::ENUM_MAX); | 267 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason", |
259 if (!collected_paint_metric_) { | |
260 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoPaint", | |
261 finish_reason, FinishReason::ENUM_MAX); | 268 finish_reason, FinishReason::ENUM_MAX); |
| 269 if (!collected_paint_metric_) { |
| 270 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoPaint", |
| 271 finish_reason, FinishReason::ENUM_MAX); |
| 272 } |
| 273 if (!collected_load_metric_) { |
| 274 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoLoad", |
| 275 finish_reason, FinishReason::ENUM_MAX); |
| 276 } |
| 277 finished_ = true; |
262 } | 278 } |
263 if (!collected_load_metric_) { | 279 // TODO(gab): Delete right away when getting rid of |finished_|. |
264 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoLoad", | 280 if (IsFinishedCollectingMetrics()) |
265 finish_reason, FinishReason::ENUM_MAX); | 281 delegate_->ProfilerFinishedCollectingMetrics(); |
266 } | |
267 delegate_->ProfilerFinishedCollectingMetrics(); | |
268 } | 282 } |
269 | 283 |
270 void FirstWebContentsProfiler::InitHistograms() { | 284 void FirstWebContentsProfiler::InitHistograms() { |
271 const std::string responsiveness_histogram_name = | 285 const std::string responsiveness_histogram_name = |
272 "Startup.FirstWebContents.UIResponsive"; | 286 "Startup.FirstWebContents.UIResponsive"; |
273 responsiveness_histogram_ = base::Histogram::FactoryTimeGet( | 287 responsiveness_histogram_ = base::Histogram::FactoryTimeGet( |
274 responsiveness_histogram_name, base::TimeDelta::FromMilliseconds(1), | 288 responsiveness_histogram_name, base::TimeDelta::FromMilliseconds(1), |
275 base::TimeDelta::FromSeconds(60), 100, | 289 base::TimeDelta::FromSeconds(60), 100, |
276 base::Histogram::kUmaTargetedHistogramFlag); | 290 base::Histogram::kUmaTargetedHistogramFlag); |
277 | 291 |
(...skipping 26 matching lines...) Expand all Loading... |
304 100, base::Histogram::kUmaTargetedHistogramFlag); | 318 100, base::Histogram::kUmaTargetedHistogramFlag); |
305 | 319 |
306 const std::string unresponsiveness_10sec_histogram_name = | 320 const std::string unresponsiveness_10sec_histogram_name = |
307 "Startup.FirstWebContents.UINotResponsive_10sec"; | 321 "Startup.FirstWebContents.UINotResponsive_10sec"; |
308 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( | 322 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( |
309 unresponsiveness_10sec_histogram_name, | 323 unresponsiveness_10sec_histogram_name, |
310 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), | 324 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), |
311 100, base::Histogram::kUmaTargetedHistogramFlag); | 325 100, base::Histogram::kUmaTargetedHistogramFlag); |
312 } | 326 } |
313 #endif // !defined(OS_ANDROID) | 327 #endif // !defined(OS_ANDROID) |
OLD | NEW |