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_macros.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 Delegate* 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 Delegate* delegate) | |
55 : content::WebContentsObserver(web_contents), | |
56 collected_paint_metric_(false), | |
57 collected_load_metric_(false), | |
58 delegate_(delegate) { | |
59 process_creation_time_ = base::CurrentProcessInfo::CreationTime(); | |
60 } | |
61 | |
62 void FirstWebContentsProfiler::DidFirstVisuallyNonEmptyPaint() { | |
63 if (collected_paint_metric_) | |
64 return; | |
65 | |
66 collected_paint_metric_ = true; | |
67 if (!process_creation_time_.is_null()) { | |
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_LONG_TIMES_100( | |
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; | |
Alexei Svitkine (slow)
2014/12/03 22:09:33
Nit: Add a line after this to match the method abo
erikchen
2014/12/03 22:20:11
Done.
| |
92 collected_load_metric_ = true; | |
93 if (!process_creation_time_.is_null()) { | |
94 base::TimeDelta elapsed = base::Time::Now() - process_creation_time_; | |
95 | |
96 // TODO(erikchen): Revisit these metrics once data has been collected to | |
97 // determine whether using more buckets reduces noise and provides higher | |
98 // quality information. | |
99 UMA_HISTOGRAM_CUSTOM_TIMES( | |
100 "Startup.Experimental.FirstWebContents.MainFrameLoad." | |
101 "ManyBuckets", | |
102 elapsed, | |
103 base::TimeDelta::FromMilliseconds(kHistogramMinTimeMilliseconds), | |
104 base::TimeDelta::FromSeconds(kHistogramMaxTimeSeconds), | |
105 kHistogramBucketCount); | |
106 UMA_HISTOGRAM_LONG_TIMES_100( | |
107 "Startup.Experimental.FirstWebContents.MainFrameLoad.StandardBuckets", | |
108 elapsed); | |
109 } | |
110 | |
111 if (IsFinishedCollectingMetrics()) | |
112 FinishedCollectingMetrics(); | |
113 } | |
114 | |
115 void FirstWebContentsProfiler::WebContentsDestroyed() { | |
116 FinishedCollectingMetrics(); | |
117 } | |
118 | |
119 bool FirstWebContentsProfiler::IsFinishedCollectingMetrics() { | |
120 return collected_paint_metric_ && collected_load_metric_; | |
121 } | |
122 | |
123 void FirstWebContentsProfiler::FinishedCollectingMetrics() { | |
124 delegate_->ProfilerFinishedCollectingMetrics(); | |
125 } | |
OLD | NEW |