OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ |
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace prerender { | 21 namespace prerender { |
22 | 22 |
23 // Navigation type for histograms. | 23 // Navigation type for histograms. |
24 enum NavigationType { | 24 enum NavigationType { |
25 // A normal completed navigation. | 25 // A normal completed navigation. |
26 NAVIGATION_TYPE_NORMAL, | 26 NAVIGATION_TYPE_NORMAL, |
27 // A completed navigation or swap that began as a prerender. | 27 // A completed navigation or swap that began as a prerender. |
28 NAVIGATION_TYPE_PRERENDERED, | 28 NAVIGATION_TYPE_PRERENDERED, |
29 }; | 29 }; |
30 | 30 |
31 // PrerenderHistograms is responsible for recording all prerender specific | 31 // Records histograms for PrerenderManager. |
32 // histograms for PrerenderManager. It keeps track of the type of prerender | 32 // |
33 // currently underway (based on the PrerenderOrigin of the most recent | 33 // A few histograms are dynamically constructed to avoid binary size bloat from |
34 // prerenders, and any experiments detected). | 34 // histogram_macros.h. Such histograms require careful handling: |
35 // PrerenderHistograms does not necessarily record all histograms related to | 35 // 1. slow - make sure only rare events are recorded this way, a handful of such |
36 // prerendering, only the ones in the context of PrerenderManager. | 36 // events per page load should be OK |
| 37 // 2. may lead to small sporadic memory leaks in Histogram::Factory::Build() - |
| 38 // ensuring that they are recorded from the same thread is sufficient |
| 39 // |
| 40 // Besides thread checking this class is stateless, all public methods are |
| 41 // const. |
37 class PrerenderHistograms { | 42 class PrerenderHistograms { |
38 public: | 43 public: |
39 // Owned by a PrerenderManager object for the lifetime of the | 44 // Owned by a PrerenderManager object for the lifetime of the |
40 // PrerenderManager. | 45 // PrerenderManager. |
41 PrerenderHistograms(); | 46 PrerenderHistograms(); |
42 | 47 |
43 // Records the perceived page load time for a page - effectively the time from | |
44 // when the user navigates to a page to when it finishes loading. The actual | |
45 // load may have started prior to navigation due to prerender hints. | |
46 void RecordPerceivedPageLoadTime(Origin origin, | |
47 base::TimeDelta perceived_page_load_time, | |
48 NavigationType navigation_type, | |
49 const GURL& url); | |
50 | |
51 // Record that a first contentful paint occured, and whether we were able to | 48 // Record that a first contentful paint occured, and whether we were able to |
52 // successfuly record the perceived FCP. | 49 // successfuly record the perceived FCP. |
53 void RecordPerceivedFirstContentfulPaintStatus(Origin origin, | 50 void RecordPerceivedFirstContentfulPaintStatus(Origin origin, |
54 bool successful, | 51 bool successful, |
55 bool was_hidden); | 52 bool was_hidden) const; |
56 | 53 |
57 // Records, in a histogram, the percentage of the page load time that had | 54 // Records, in a histogram, the percentage of the page load time that had |
58 // elapsed by the time it is swapped in. Values outside of [0, 1.0] are | 55 // elapsed by the time it is swapped in. Values outside of [0, 1.0] are |
59 // invalid and ignored. | 56 // invalid and ignored. |
60 void RecordPercentLoadDoneAtSwapin(Origin origin, double fraction) const; | 57 void RecordPercentLoadDoneAtSwapin(Origin origin, double fraction) const; |
61 | 58 |
62 // Records the actual pageload time of a prerender that has not been swapped | |
63 // in yet, but finished loading. | |
64 void RecordPageLoadTimeNotSwappedIn(Origin origin, | |
65 base::TimeDelta page_load_time, | |
66 const GURL& url) const; | |
67 | |
68 // Records the time from when a page starts prerendering to when the user | 59 // Records the time from when a page starts prerendering to when the user |
69 // navigates to it. This must be called on the UI thread. | 60 // navigates to it. This must be called on the UI thread. |
70 void RecordTimeUntilUsed(Origin origin, | 61 void RecordTimeUntilUsed(Origin origin, |
71 base::TimeDelta time_until_used) const; | 62 base::TimeDelta time_until_used) const; |
72 | 63 |
73 // Records the time from when a prerender is abandoned to when the user | 64 // Records the time from when a prerender is abandoned to when the user |
74 // navigates to it. This must be called on the UI thread. | 65 // navigates to it. This must be called on the UI thread. |
75 void RecordAbandonTimeUntilUsed(Origin origin, | 66 void RecordAbandonTimeUntilUsed(Origin origin, |
76 base::TimeDelta time_until_used) const; | 67 base::TimeDelta time_until_used) const; |
77 | 68 |
78 // Record a PerSessionCount data point. | 69 // Record a PerSessionCount data point. |
79 void RecordPerSessionCount(Origin origin, int count) const; | 70 void RecordPerSessionCount(Origin origin, int count) const; |
80 | 71 |
81 // Record time between two prerender requests. | 72 // Record time between two prerender requests. |
82 void RecordTimeBetweenPrerenderRequests(Origin origin, | 73 void RecordTimeBetweenPrerenderRequests(Origin origin, |
83 base::TimeDelta time) const; | 74 base::TimeDelta time) const; |
84 | 75 |
85 // Record a final status of a prerendered page in a histogram. | 76 // Record a final status of a prerendered page in a histogram. |
86 void RecordFinalStatus(Origin origin, FinalStatus final_status) const; | 77 void RecordFinalStatus(Origin origin, FinalStatus final_status) const; |
87 | 78 |
88 // To be called when a new prerender is added. | |
89 void RecordPrerender(); | |
90 | |
91 // To be called when a new prerender is started. | 79 // To be called when a new prerender is started. |
92 void RecordPrerenderStarted(Origin origin) const; | 80 void RecordPrerenderStarted(Origin origin) const; |
93 | 81 |
94 // To be called when we know how many prerenders are running after starting | |
95 // a prerender. | |
96 void RecordConcurrency(size_t prerender_count) const; | |
97 | |
98 // Called when we swap in a prerender. | 82 // Called when we swap in a prerender. |
99 void RecordUsedPrerender(Origin origin) const; | 83 void RecordUsedPrerender(Origin origin) const; |
100 | 84 |
101 // Record the time since a page was recently visited. | 85 // Record the time since a page was recently visited. |
102 void RecordTimeSinceLastRecentVisit(Origin origin, | 86 void RecordTimeSinceLastRecentVisit(Origin origin, |
103 base::TimeDelta time) const; | 87 base::TimeDelta time) const; |
104 | 88 |
105 // Record the bytes in the prerender, whether it was used or not, and the | 89 // Record the bytes in the prerender, whether it was used or not, and the |
106 // total number of bytes fetched for this profile since the last call to | 90 // total number of bytes fetched for this profile since the last call to |
107 // RecordBytes. | 91 // RecordBytes. |
(...skipping 14 matching lines...) Expand all Loading... |
122 void RecordPrefetchRedirectCount(Origin origin, | 106 void RecordPrefetchRedirectCount(Origin origin, |
123 bool is_main_resource, | 107 bool is_main_resource, |
124 int redirect_count) const; | 108 int redirect_count) const; |
125 | 109 |
126 // Records the time to first contentful paint with respect to a possible | 110 // Records the time to first contentful paint with respect to a possible |
127 // prefetch of the page. The time to first contentful paint with respect to | 111 // prefetch of the page. The time to first contentful paint with respect to |
128 // the navigation start is recorded (even if the page was prererendered in | 112 // the navigation start is recorded (even if the page was prererendered in |
129 // advance of navigation start). One of several histograms is used, depending | 113 // advance of navigation start). One of several histograms is used, depending |
130 // on whether this URL could have been prefetched before the navigation | 114 // on whether this URL could have been prefetched before the navigation |
131 // leading to the paint. | 115 // leading to the paint. |
132 void RecordPrefetchFirstContentfulPaintTime(Origin origin, | 116 void RecordPrefetchFirstContentfulPaintTime( |
133 bool is_no_store, | 117 Origin origin, |
134 bool was_hidden, | 118 bool is_no_store, |
135 base::TimeDelta time, | 119 bool was_hidden, |
136 base::TimeDelta prefetch_age); | 120 base::TimeDelta time, |
| 121 base::TimeDelta prefetch_age) const; |
137 | 122 |
138 private: | 123 private: |
139 base::TimeTicks GetCurrentTimeTicks() const; | |
140 | |
141 // Returns the time elapsed since the last prerender happened. | |
142 base::TimeDelta GetTimeSinceLastPrerender() const; | |
143 | |
144 // Returns whether the PrerenderManager is currently within the prerender | |
145 // window - effectively, up to 30 seconds after a prerender tag has been | |
146 // observed. | |
147 bool WithinWindow() const; | |
148 | |
149 // The time when we last saw a prerender request coming from a renderer. | |
150 // This is used to record perceived PLT's for a certain amount of time | |
151 // from the point that we last saw a <link rel=prerender> tag. | |
152 base::TimeTicks last_prerender_seen_time_; | |
153 | |
154 // Indicates whether we have recorded page load events after the most | |
155 // recent prerender. These must be initialized to true, so that we don't | |
156 // start recording events before the first prerender occurs. | |
157 bool seen_any_pageload_; | |
158 bool seen_pageload_started_after_prerender_; | |
159 | |
160 base::ThreadChecker thread_checker_; | 124 base::ThreadChecker thread_checker_; |
161 | 125 |
162 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms); | 126 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms); |
163 }; | 127 }; |
164 | 128 |
165 } // namespace prerender | 129 } // namespace prerender |
166 | 130 |
167 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ | 131 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ |
OLD | NEW |