Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: chrome/browser/metrics/first_web_contents_profiler.cc

Issue 1416963002: Abandon startup profiling for first WebContents when it gets hidden or navigated to a different ... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review:rkaplow Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 // Abandon profiling on any navigation to a different page as it:
189 // (1) is no longer a fair timing; and
190 // (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
192 // after a lot of idle time when the user finally navigates to another
193 // page that does trigger it.
194 if (load_details.is_navigation_to_different_page()) {
195 if (initial_entry_committed_)
196 FinishedCollectingMetrics(FinishReason::ABANDON_NAVIGATION);
197 else
198 initial_entry_committed_ = true;
199 }
200 }
201
202 void FirstWebContentsProfiler::WasHidden() {
203 // Stop profiling if the content gets hidden as its load may be deprioritized
204 // and timing it becomes meaningless.
205 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_HIDDEN);
181 } 206 }
182 207
183 void FirstWebContentsProfiler::WebContentsDestroyed() { 208 void FirstWebContentsProfiler::WebContentsDestroyed() {
184 FinishedCollectingMetrics(); 209 FinishedCollectingMetrics(FinishReason::ABANDON_CONTENT_DESTROYED);
185 } 210 }
186 211
187 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() { 212 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() {
188 return collected_paint_metric_ && collected_load_metric_; 213 return collected_paint_metric_ && collected_load_metric_;
189 } 214 }
190 215
191 void FirstWebContentsProfiler::FinishedCollectingMetrics() { 216 void FirstWebContentsProfiler::FinishedCollectingMetrics(
217 FinishReason finish_reason) {
218 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason",
219 finish_reason, FinishReason::ENUM_MAX);
220 if (!collected_paint_metric_) {
221 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoPaint",
222 finish_reason, FinishReason::ENUM_MAX);
223 }
224 if (!collected_load_metric_) {
225 UMA_HISTOGRAM_ENUMERATION("Startup.FirstWebContents.FinishReason_NoLoad",
226 finish_reason, FinishReason::ENUM_MAX);
227 }
192 delegate_->ProfilerFinishedCollectingMetrics(); 228 delegate_->ProfilerFinishedCollectingMetrics();
193 } 229 }
194 230
195 void FirstWebContentsProfiler::InitHistograms() { 231 void FirstWebContentsProfiler::InitHistograms() {
196 const std::string responsiveness_histogram_name = 232 const std::string responsiveness_histogram_name =
197 "Startup.FirstWebContents.UIResponsive"; 233 "Startup.FirstWebContents.UIResponsive";
198 responsiveness_histogram_ = base::Histogram::FactoryTimeGet( 234 responsiveness_histogram_ = base::Histogram::FactoryTimeGet(
199 responsiveness_histogram_name, base::TimeDelta::FromMilliseconds(1), 235 responsiveness_histogram_name, base::TimeDelta::FromMilliseconds(1),
200 base::TimeDelta::FromSeconds(60), 100, 236 base::TimeDelta::FromSeconds(60), 100,
201 base::Histogram::kUmaTargetedHistogramFlag); 237 base::Histogram::kUmaTargetedHistogramFlag);
(...skipping 27 matching lines...) Expand all
229 100, base::Histogram::kUmaTargetedHistogramFlag); 265 100, base::Histogram::kUmaTargetedHistogramFlag);
230 266
231 const std::string unresponsiveness_10sec_histogram_name = 267 const std::string unresponsiveness_10sec_histogram_name =
232 "Startup.FirstWebContents.UINotResponsive_10sec"; 268 "Startup.FirstWebContents.UINotResponsive_10sec";
233 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet( 269 unresponsiveness_10sec_histogram_ = base::Histogram::FactoryTimeGet(
234 unresponsiveness_10sec_histogram_name, 270 unresponsiveness_10sec_histogram_name,
235 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60), 271 base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromSeconds(60),
236 100, base::Histogram::kUmaTargetedHistogramFlag); 272 100, base::Histogram::kUmaTargetedHistogramFlag);
237 } 273 }
238 #endif // !defined(OS_ANDROID) 274 #endif // !defined(OS_ANDROID)
OLDNEW
« no previous file with comments | « chrome/browser/metrics/first_web_contents_profiler.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698