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 #include "chrome/common/chrome_version_info.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const int kHistogramMinTimeMilliseconds = 200; | |
| 18 const int kHistogramMaxTimeSeconds = 45; | |
| 19 | |
| 20 // There is a lot of noise in the dev channel. One possible cause is that the | |
| 21 // bucket ranges are too wide. The bucket count is chosen such that the size of | |
| 22 // the bucket is 1% of its minimum. Notice that this also means that | |
| 23 // subsequent buckets will satisfy Min(bucket N + 1) / Min(bucket N) = 1.01. | |
| 24 // Then we want X, such that 1.01 ^ X = 45 * 1000 / 200. Some quick math shows | |
| 25 // that X = 544. | |
| 26 const int kHistogramBucketCount = 544; | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 scoped_ptr<FirstWebContentsProfiler> | |
| 31 FirstWebContentsProfiler::CreateProfilerForFirstWebContents( | |
| 32 FirstWebContentsProfilerDelegate* delegate) { | |
| 33 DCHECK(delegate); | |
| 34 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) { | |
| 35 Browser* browser = *iterator; | |
| 36 content::WebContents* web_contents = | |
| 37 browser->tab_strip_model()->GetActiveWebContents(); | |
| 38 if (web_contents) { | |
| 39 return scoped_ptr<FirstWebContentsProfiler>( | |
| 40 new FirstWebContentsProfiler(web_contents, delegate)); | |
| 41 } | |
| 42 } | |
| 43 return nullptr; | |
| 44 } | |
| 45 | |
| 46 bool FirstWebContentsProfiler::ShouldCollectMetrics() { | |
| 47 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | |
| 48 return channel == chrome::VersionInfo::CHANNEL_CANARY || | |
| 49 channel == chrome::VersionInfo::CHANNEL_DEV; | |
| 50 } | |
| 51 | |
| 52 FirstWebContentsProfiler::FirstWebContentsProfiler( | |
| 53 content::WebContents* web_contents, | |
| 54 FirstWebContentsProfilerDelegate* delegate) | |
| 55 : content::WebContentsObserver(web_contents), | |
| 56 collected_paint_metric_(false), | |
| 57 collected_load_metric_(false), | |
| 58 delegate_(delegate) { | |
| 59 } | |
| 60 | |
| 61 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | |
| 62 if (collected_paint_metric_) | |
| 63 return; | |
| 64 collected_paint_metric_ = true; | |
| 65 const base::Time process_creation_time = | |
| 66 base::CurrentProcessInfo::CreationTime(); | |
|
Alexei Svitkine (slow)
2014/12/03 20:05:57
CreationTime() seems like it's doing a system call
erikchen
2014/12/03 21:38:41
Done. I'm surprised that the function doesn't cach
| |
| 67 if (!process_creation_time.is_null()) { | |
|
Alexei Svitkine (slow)
2014/12/03 20:05:57
Nit: Early return instead. Same below.
erikchen
2014/12/03 21:38:41
That would change the behavior of this method (it
| |
| 68 base::TimeDelta elapsed = base::Time::Now() - process_creation_time; | |
| 69 | |
| 70 // TODO(erikchen): Revisit these metrics once data has been collected to | |
| 71 // determine whether using more buckets reduces noise and provides higher | |
| 72 // quality information. | |
| 73 UMA_HISTOGRAM_CUSTOM_TIMES( | |
| 74 "Startup.Experimental.FirstWebContents.NonEmptyPaint." | |
| 75 "ManyBuckets", | |
| 76 elapsed, | |
| 77 base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds), | |
| 78 base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds), | |
| 79 kHistogramBucketCount); | |
| 80 UMA_HISTOGRAM_TIMES( | |
|
Alexei Svitkine (slow)
2014/12/03 20:05:57
Use UMA_HISTOGRAM_TIMES_100
erikchen
2014/12/03 21:38:41
Done.
| |
| 81 "Startup.Experimental.FirstWebContents.NonEmptyPaint.StandardBuckets", | |
| 82 elapsed); | |
| 83 } | |
| 84 | |
| 85 if (IsFinishedCollectingMetrics()) | |
| 86 FinishedCollectingMetrics(); | |
| 87 } | |
| 88 | |
| 89 void FirstWebContentsProfiler::DocumentOnLoadCompletedInMainFrame() { | |
| 90 if (collected_load_metric_) | |
| 91 return; | |
| 92 collected_load_metric_ = true; | |
| 93 const base::Time process_creation_time = | |
| 94 base::CurrentProcessInfo::CreationTime(); | |
| 95 if (!process_creation_time.is_null()) { | |
| 96 base::TimeDelta elapsed = base::Time::Now() - process_creation_time; | |
| 97 | |
| 98 // TODO(erikchen): Revisit these metrics once data has been collected to | |
| 99 // determine whether using more buckets reduces noise and provides higher | |
| 100 // quality information. | |
| 101 UMA_HISTOGRAM_CUSTOM_TIMES( | |
| 102 "Startup.Experimental.FirstWebContents.MainFrameLoad." | |
| 103 "ManyBuckets", | |
| 104 elapsed, | |
| 105 base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds), | |
| 106 base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds), | |
| 107 kHistogramBucketCount); | |
| 108 UMA_HISTOGRAM_TIMES( | |
|
Alexei Svitkine (slow)
2014/12/03 20:05:57
Ditto.
erikchen
2014/12/03 21:38:41
Done.
| |
| 109 "Startup.Experimental.FirstWebContents.MainFrameLoad.StandardBuckets", | |
| 110 elapsed); | |
| 111 } | |
| 112 | |
| 113 if (IsFinishedCollectingMetrics()) | |
| 114 FinishedCollectingMetrics(); | |
| 115 } | |
| 116 | |
| 117 void FirstWebContentsProfiler::WebContentsDestroyed() { | |
| 118 FinishedCollectingMetrics(); | |
| 119 } | |
| 120 | |
| 121 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() { | |
| 122 return collected_paint_metric_ && collected_load_metric_; | |
| 123 } | |
| 124 | |
| 125 void FirstWebContentsProfiler::FinishedCollectingMetrics() { | |
| 126 delegate_->ProfilerFinishedCollectingMetrics(); | |
| 127 } | |
| OLD | NEW |