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

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

Issue 760763002: Add startup metrics that measure the performance of the first web contents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" 5 #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/cpu.h" 11 #include "base/cpu.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/sparse_histogram.h" 13 #include "base/metrics/sparse_histogram.h"
14 #include "base/process/process_info.h"
14 #include "base/sys_info.h" 15 #include "base/sys_info.h"
15 #include "base/threading/sequenced_worker_pool.h" 16 #include "base/threading/sequenced_worker_pool.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "chrome/browser/about_flags.h" 18 #include "chrome/browser/about_flags.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chrome_browser_main.h" 20 #include "chrome/browser/chrome_browser_main.h"
20 #include "chrome/browser/mac/bluetooth_utility.h" 21 #include "chrome/browser/mac/bluetooth_utility.h"
21 #include "chrome/browser/pref_service_flags_storage.h" 22 #include "chrome/browser/pref_service_flags_storage.h"
22 #include "chrome/browser/shell_integration.h" 23 #include "chrome/browser/shell_integration.h"
24 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_iterator.h"
26 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/web_contents_observer.h"
24 #include "ui/base/touch/touch_device.h" 29 #include "ui/base/touch/touch_device.h"
25 #include "ui/base/ui_base_switches.h" 30 #include "ui/base/ui_base_switches.h"
26 #include "ui/events/event_switches.h" 31 #include "ui/events/event_switches.h"
27 #include "ui/gfx/screen.h" 32 #include "ui/gfx/screen.h"
28 33
29 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 34 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
30 #include <gnu/libc-version.h> 35 #include <gnu/libc-version.h>
31 36
32 #include "base/version.h" 37 #include "base/version.h"
33 #if defined(USE_X11) 38 #if defined(USE_X11)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 NOTREACHED(); 220 NOTREACHED();
216 return; 221 return;
217 } 222 }
218 223
219 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", state, 224 UMA_HISTOGRAM_ENUMERATION("Touchscreen.TouchEventsEnabled", state,
220 UMA_TOUCH_EVENTS_STATE_COUNT); 225 UMA_TOUCH_EVENTS_STATE_COUNT);
221 } 226 }
222 227
223 } // namespace 228 } // namespace
224 229
230 // Measures start up performance of the first active web contents.
231 class ChromeBrowserMainExtraPartsMetrics::FirstWebContentsProfiler
232 : public content::WebContentsObserver {
233 public:
234 FirstWebContentsProfiler(content::WebContents* web_contents,
235 ChromeBrowserMainExtraPartsMetrics* metrics)
236 : content::WebContentsObserver(web_contents),
237 recorded_paint_metric_(false),
238 recorded_load_metric_(false),
239 metrics_(metrics) {}
240
241 private:
242 void DidFirstVisuallyNonEmptyPaint() override {
243 if (recorded_paint_metric_)
244 return;
245 recorded_paint_metric_ = true;
246 const base::Time process_creation_time =
247 base::CurrentProcessInfo::CreationTime();
248 if (!process_creation_time.is_null()) {
249 base::TimeDelta elapsed = base::Time::Now() - process_creation_time;
250 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstWebContents.NonEmptyPaint",
251 elapsed,
252 base::TimeDelta::FromMilliseconds(100),
253 base::TimeDelta::FromMinutes(2), 300);
Ilya Sherman 2014/11/26 02:24:55 Could you clarify why you need such fine granulari
erikchen 2014/11/26 03:48:43 I am basing these numbers on the histograms Startu
254 }
255
256 if (FinishedRecordingMetrics())
257 DestroySelf();
258 }
259
260 void DocumentOnLoadCompletedInMainFrame() override {
261 if (recorded_load_metric_)
262 return;
263 recorded_load_metric_ = true;
264 const base::Time process_creation_time =
265 base::CurrentProcessInfo::CreationTime();
266 if (!process_creation_time.is_null()) {
267 base::TimeDelta elapsed = base::Time::Now() - process_creation_time;
268 UMA_HISTOGRAM_CUSTOM_TIMES("Startup.FirstWebContents.MainFrameLoad",
269 elapsed,
270 base::TimeDelta::FromMilliseconds(100),
271 base::TimeDelta::FromMinutes(2), 300);
272 }
273
274 if (FinishedRecordingMetrics())
275 DestroySelf();
276 }
277
278 void WebContentsDestroyed() override { DestroySelf(); }
279
280 // Whether all metrics have been recorded.
281 bool FinishedRecordingMetrics() {
282 return recorded_paint_metric_ && recorded_load_metric_;
283 }
284
285 // Tells the owner of |this| to destroy |this|.
286 void DestroySelf() { metrics_->FirstWebContentsProfilerWantsDestruction(); }
287
288 // Whether the "NonEmptyPaint" metric has been recorded.
289 bool recorded_paint_metric_;
290
291 // Whether the "MainFrameLoad" metric has been recorded.
292 bool recorded_load_metric_;
293
294 // |metrics_| owns |this|.
295 ChromeBrowserMainExtraPartsMetrics* metrics_;
296
297 DISALLOW_COPY_AND_ASSIGN(FirstWebContentsProfiler);
298 };
Ilya Sherman 2014/11/26 02:24:55 Please split this class out into its own implement
erikchen 2014/11/26 03:48:43 I split out the file into its own implementation.
299
225 ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics() 300 ChromeBrowserMainExtraPartsMetrics::ChromeBrowserMainExtraPartsMetrics()
226 : display_count_(0), is_screen_observer_(false) { 301 : display_count_(0), is_screen_observer_(false) {
227 } 302 }
228 303
229 ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() { 304 ChromeBrowserMainExtraPartsMetrics::~ChromeBrowserMainExtraPartsMetrics() {
230 if (is_screen_observer_) 305 if (is_screen_observer_)
231 gfx::Screen::GetNativeScreen()->RemoveObserver(this); 306 gfx::Screen::GetNativeScreen()->RemoveObserver(this);
232 } 307 }
233 308
234 void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() { 309 void ChromeBrowserMainExtraPartsMetrics::PreProfileInit() {
(...skipping 22 matching lines...) Expand all
257 const int kStartupMetricsGatheringDelaySeconds = 45; 332 const int kStartupMetricsGatheringDelaySeconds = 45;
258 content::BrowserThread::GetBlockingPool()->PostDelayedTask( 333 content::BrowserThread::GetBlockingPool()->PostDelayedTask(
259 FROM_HERE, 334 FROM_HERE,
260 base::Bind(&RecordStartupMetricsOnBlockingPool), 335 base::Bind(&RecordStartupMetricsOnBlockingPool),
261 base::TimeDelta::FromSeconds(kStartupMetricsGatheringDelaySeconds)); 336 base::TimeDelta::FromSeconds(kStartupMetricsGatheringDelaySeconds));
262 337
263 display_count_ = gfx::Screen::GetNativeScreen()->GetNumDisplays(); 338 display_count_ = gfx::Screen::GetNativeScreen()->GetNumDisplays();
264 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnStartup", display_count_); 339 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnStartup", display_count_);
265 gfx::Screen::GetNativeScreen()->AddObserver(this); 340 gfx::Screen::GetNativeScreen()->AddObserver(this);
266 is_screen_observer_ = true; 341 is_screen_observer_ = true;
342
343 // Record startup metrics for the active web contents. If there are multiple
344 // browsers, choose the first one.
345 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) {
346 Browser* browser = *iterator;
347 content::WebContents* web_contents =
348 browser->tab_strip_model()->GetActiveWebContents();
349 if (web_contents) {
350 first_web_contents_profiler_.reset(
351 new FirstWebContentsProfiler(web_contents, this));
352 break;
353 }
354 }
Ilya Sherman 2014/11/26 02:24:55 I think this logic could safely be internal to the
erikchen 2014/11/26 03:48:43 Done.
267 } 355 }
268 356
269 void ChromeBrowserMainExtraPartsMetrics::OnDisplayAdded( 357 void ChromeBrowserMainExtraPartsMetrics::OnDisplayAdded(
270 const gfx::Display& new_display) { 358 const gfx::Display& new_display) {
271 EmitDisplaysChangedMetric(); 359 EmitDisplaysChangedMetric();
272 } 360 }
273 361
274 void ChromeBrowserMainExtraPartsMetrics::OnDisplayRemoved( 362 void ChromeBrowserMainExtraPartsMetrics::OnDisplayRemoved(
275 const gfx::Display& old_display) { 363 const gfx::Display& old_display) {
276 EmitDisplaysChangedMetric(); 364 EmitDisplaysChangedMetric();
277 } 365 }
278 366
279 void ChromeBrowserMainExtraPartsMetrics::OnDisplayMetricsChanged( 367 void ChromeBrowserMainExtraPartsMetrics::OnDisplayMetricsChanged(
280 const gfx::Display& display, 368 const gfx::Display& display,
281 uint32_t changed_metrics) { 369 uint32_t changed_metrics) {
282 } 370 }
283 371
284 void ChromeBrowserMainExtraPartsMetrics::EmitDisplaysChangedMetric() { 372 void ChromeBrowserMainExtraPartsMetrics::EmitDisplaysChangedMetric() {
285 int display_count = gfx::Screen::GetNativeScreen()->GetNumDisplays(); 373 int display_count = gfx::Screen::GetNativeScreen()->GetNumDisplays();
286 if (display_count != display_count_) { 374 if (display_count != display_count_) {
287 display_count_ = display_count; 375 display_count_ = display_count;
288 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnChange", display_count_); 376 UMA_HISTOGRAM_COUNTS_100("Hardware.Display.Count.OnChange", display_count_);
289 } 377 }
290 } 378 }
291 379
380 void ChromeBrowserMainExtraPartsMetrics::
381 FirstWebContentsProfilerWantsDestruction() {
382 first_web_contents_profiler_.reset();
383 }
384
292 namespace chrome { 385 namespace chrome {
293 386
294 void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) { 387 void AddMetricsExtraParts(ChromeBrowserMainParts* main_parts) {
295 main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics()); 388 main_parts->AddParts(new ChromeBrowserMainExtraPartsMetrics());
296 } 389 }
297 390
298 } // namespace chrome 391 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698