Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/metrics/first_web_contents_profiler.h" | |
| 6 | |
| 7 #include "base/metrics/histogram.h" | |
| 8 #include "base/process/process_info.h" | |
| 9 #include "base/time/time.h" | |
| 10 #include "chrome/browser/ui/browser.h" | |
| 11 #include "chrome/browser/ui/browser_iterator.h" | |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const int kHistogramMinTimeMilliseconds = 200; | |
| 17 const int kHistogramMaxTimeSeconds = 45; | |
| 18 | |
| 19 // Startup histograms are always bimodal. I strongly suspect that the two modes | |
| 20 // correspond to devices with an SSD vs. devices with an HDD. As such, neither | |
| 21 // the mean nor the median are particularly relevant. | |
| 22 // | |
| 23 // Most changes to startup improvement will be incremenetal, and have a | |
| 24 // relatively small effect on one or both of the modes. It's important that the | |
| 25 // bucket count is sufficiently large that these changes can be measured to | |
| 26 // determine whether their intended effect matches the actual effect. | |
| 27 // | |
| 28 // I want to be able to differentiate between 1% improvements, so the | |
| 29 // logarithmic difference between buckets must be 0.01. | |
|
Ilya Sherman
2014/11/26 22:04:08
What is the connection between 1% and a logarithmi
| |
| 30 // | |
| 31 // Total logarithmic difference between top/bottom buckets = lg(45 * 1000 / | |
| 32 // 200) = 7.81 | |
| 33 // The number of buckets needed for a logarithmic difference of 0.01 is 7.81 / | |
| 34 // 0.01 = 781. | |
| 35 const int kHistogramBucketSize = 781; | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 scoped_ptr<FirstWebContentsProfiler> | |
| 40 FirstWebContentsProfiler::CreateProfilerForFirstWebContents( | |
| 41 FirstWebContentsProfilerDelegate* delegate) { | |
| 42 DCHECK(delegate); | |
| 43 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) { | |
| 44 Browser* browser = *iterator; | |
| 45 content::WebContents* web_contents = | |
| 46 browser->tab_strip_model()->GetActiveWebContents(); | |
| 47 if (web_contents) { | |
| 48 return scoped_ptr<FirstWebContentsProfiler>( | |
| 49 new FirstWebContentsProfiler(web_contents, delegate)); | |
| 50 } | |
| 51 } | |
| 52 return nullptr; | |
| 53 } | |
| 54 | |
| 55 FirstWebContentsProfiler::FirstWebContentsProfiler( | |
| 56 content::WebContents* web_contents, | |
| 57 FirstWebContentsProfilerDelegate* delegate) | |
| 58 : content::WebContentsObserver(web_contents), | |
| 59 collected_paint_metric_(false), | |
| 60 collected_load_metric_(false), | |
| 61 delegate_(delegate) { | |
| 62 } | |
| 63 | |
| 64 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | |
| 65 if (collected_paint_metric_) | |
| 66 return; | |
| 67 collected_paint_metric_ = true; | |
| 68 const base::Time process_creation_time = | |
| 69 base::CurrentProcessInfo::CreationTime(); | |
| 70 if (!process_creation_time.is_null()) { | |
| 71 base::TimeDelta elapsed = base::Time::Now() - process_creation_time; | |
| 72 UMA_HISTOGRAM_CUSTOM_TIMES( | |
| 73 "Startup.FirstWebContents.NonEmptyPaint", elapsed, | |
| 74 base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds), | |
| 75 base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds), | |
| 76 kHistogramBucketSize); | |
| 77 } | |
| 78 | |
| 79 if (IsFinishedCollectingMetrics()) | |
| 80 FinishedCollectingMetrics(); | |
| 81 } | |
| 82 | |
| 83 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { | |
| 84 if (collected_load_metric_) | |
| 85 return; | |
| 86 collected_load_metric_ = true; | |
| 87 const base::Time process_creation_time = | |
| 88 base::CurrentProcessInfo::CreationTime(); | |
| 89 if (!process_creation_time.is_null()) { | |
| 90 base::TimeDelta elapsed = base::Time::Now() - process_creation_time; | |
| 91 UMA_HISTOGRAM_CUSTOM_TIMES( | |
| 92 "Startup.FirstWebContents.MainFrameLoad", elapsed, | |
| 93 base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds), | |
| 94 base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds), | |
| 95 kHistogramBucketSize); | |
| 96 } | |
| 97 | |
| 98 if (IsFinishedCollectingMetrics()) | |
| 99 FinishedCollectingMetrics(); | |
| 100 } | |
| 101 | |
| 102 void FirstWebContentsProfiler::WebContentsDestroyed() { | |
| 103 FinishedCollectingMetrics(); | |
| 104 } | |
| 105 | |
| 106 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() { | |
| 107 return collected_paint_metric_ && collected_load_metric_; | |
| 108 } | |
| 109 | |
| 110 void FirstWebContentsProfiler::FinishedCollectingMetrics() { | |
| 111 delegate_->ProfilerFinishedCollectingMetrics(); | |
| 112 } | |
| OLD | NEW |