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 #include "chrome/browser/net/cache_stats.h" | 5 #include "chrome/browser/net/cache_stats.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/resource_request_info.h" | 18 #include "content/public/browser/resource_request_info.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
21 | 21 |
22 using content::BrowserThread; | 22 using content::BrowserThread; |
23 using content::RenderViewHost; | 23 using content::RenderViewHost; |
24 using content::ResourceRequestInfo; | 24 using content::ResourceRequestInfo; |
25 using std::string; | |
25 | 26 |
26 #if defined(COMPILER_GCC) | 27 #if defined(COMPILER_GCC) |
27 | 28 |
28 namespace BASE_HASH_NAMESPACE { | 29 namespace BASE_HASH_NAMESPACE { |
29 template <> | 30 template <> |
30 struct hash<const net::URLRequest*> { | 31 struct hash<const net::URLRequest*> { |
31 std::size_t operator()(const net::URLRequest* value) const { | 32 std::size_t operator()(const net::URLRequest* value) const { |
32 return reinterpret_cast<std::size_t>(value); | 33 return reinterpret_cast<std::size_t>(value); |
33 } | 34 } |
34 }; | 35 }; |
(...skipping 30 matching lines...) Expand all Loading... | |
65 4000, | 66 4000, |
66 5000, | 67 5000, |
67 7500, | 68 7500, |
68 10000, | 69 10000, |
69 15000, | 70 15000, |
70 20000 | 71 20000 |
71 }; | 72 }; |
72 | 73 |
73 static int kTabLoadStatsAutoCleanupTimeoutSeconds = 30; | 74 static int kTabLoadStatsAutoCleanupTimeoutSeconds = 30; |
74 | 75 |
76 const char* kRequestStatusNames[] = { | |
77 "CacheWait", | |
78 "NetworkWait", | |
79 "Active", | |
80 "None", | |
81 "Max" | |
82 }; | |
83 | |
84 COMPILE_ASSERT(arraysize(kRequestStatusNames) == | |
85 chrome_browser_net::CacheStats::REQUEST_STATUS_MAX + 1, | |
86 CacheStats_RequestStatus_names_mismatch); | |
87 | |
88 const char* kHistogramTypeNames[] = { | |
89 "FinalAggregate", | |
90 "FinalCumulative", | |
91 "FinalCumulativePercentage", | |
92 "IntermediateAggregate", | |
93 "IntermediateCumulative", | |
94 "IntermediateCumulativePercentage", | |
95 "Max" | |
96 }; | |
97 | |
98 COMPILE_ASSERT(arraysize(kHistogramTypeNames) == | |
99 chrome_browser_net::CacheStats::HISTOGRAM_MAX + 1, | |
100 CacheStats_HistogramType_names_mismatch); | |
101 | |
75 } // namespace | 102 } // namespace |
76 | 103 |
77 namespace chrome_browser_net { | 104 namespace chrome_browser_net { |
78 | 105 |
79 // Helper struct keeping stats about the page load progress & cache usage | 106 // Helper struct keeping stats about the page load progress & cache usage |
80 // stats during the pageload so far for a given RenderView, identified | 107 // stats during the pageload so far for a given RenderView, identified |
81 // by a pair of process id and route id. | 108 // by a pair of process id and route id. |
82 struct CacheStats::TabLoadStats { | 109 struct CacheStats::TabLoadStats { |
110 | |
111 // Stores the time taken by all requests while they have a certain | |
112 // RequestStatus. | |
113 struct PerStatusStats { | |
114 PerStatusStats() | |
115 : num_active(0) { | |
116 } | |
117 | |
118 void UpdateTotalTimes() { | |
119 base::TimeTicks now = base::TimeTicks::Now(); | |
120 if (num_active > 0) { | |
121 total_time += now - last_update_time; | |
122 total_cumulative_time += | |
123 (now - last_update_time) * static_cast<int64>(num_active); | |
124 } | |
125 last_update_time = now; | |
126 } | |
127 | |
128 void ResetTimes() { | |
129 last_update_time = base::TimeTicks::Now(); | |
130 total_time = base::TimeDelta(); | |
131 total_cumulative_time = base::TimeDelta(); | |
132 } | |
133 | |
134 int num_active; | |
135 base::TimeTicks last_update_time; | |
136 base::TimeDelta total_time; | |
137 base::TimeDelta total_cumulative_time; | |
138 }; | |
139 | |
83 TabLoadStats(std::pair<int, int> render_view_id, CacheStats* owner) | 140 TabLoadStats(std::pair<int, int> render_view_id, CacheStats* owner) |
84 : render_view_id(render_view_id), | 141 : render_view_id(render_view_id), |
85 num_active(0), | |
86 spinner_started(false), | 142 spinner_started(false), |
87 next_timer_index(0), | 143 next_timer_index(0), |
88 timer(false, false) { | 144 timer(false, false) { |
89 // Initialize the timer to do an automatic cleanup. If a pageload is | 145 // Initialize the timer to do an automatic cleanup. If a pageload is |
90 // started for the TabLoadStats within that timeframe, CacheStats | 146 // started for the TabLoadStats within that timeframe, CacheStats |
91 // will start using the timer, thereby cancelling the cleanup. | 147 // will start using the timer, thereby cancelling the cleanup. |
92 // Once CacheStats starts the timer, the object is guaranteed to be | 148 // Once CacheStats starts the timer, the object is guaranteed to be |
93 // destroyed eventually, so there is no more need for automatic cleanup at | 149 // destroyed eventually, so there is no more need for automatic cleanup at |
94 // that point. | 150 // that point. |
95 timer.Start(FROM_HERE, | 151 timer.Start(FROM_HERE, |
96 base::TimeDelta::FromSeconds( | 152 base::TimeDelta::FromSeconds( |
97 kTabLoadStatsAutoCleanupTimeoutSeconds), | 153 kTabLoadStatsAutoCleanupTimeoutSeconds), |
98 base::Bind(&CacheStats::RemoveTabLoadStats, | 154 base::Bind(&CacheStats::RemoveTabLoadStats, |
99 base::Unretained(owner), | 155 base::Unretained(owner), |
100 render_view_id)); | 156 render_view_id)); |
101 } | 157 } |
102 | 158 |
103 std::pair<int, int> render_view_id; | 159 std::pair<int, int> render_view_id; |
104 int num_active; | 160 PerStatusStats per_status_stats[REQUEST_STATUS_MAX]; |
105 bool spinner_started; | 161 bool spinner_started; |
106 base::TimeTicks load_start_time; | 162 base::TimeTicks load_start_time; |
107 base::TimeTicks cache_start_time; | |
108 base::TimeDelta cache_total_time; | |
109 int next_timer_index; | 163 int next_timer_index; |
110 base::Timer timer; | 164 base::Timer timer; |
111 // URLRequest's for which there are outstanding cache transactions. | 165 // Currently active URLRequests. |
112 base::hash_set<const net::URLRequest*> active_requests; | 166 base::hash_map<const net::URLRequest*, RequestStatus> active_requests; |
113 }; | 167 }; |
114 | 168 |
115 CacheStatsTabHelper::CacheStatsTabHelper(TabContents* tab) | 169 CacheStatsTabHelper::CacheStatsTabHelper(TabContents* tab) |
116 : content::WebContentsObserver(tab->web_contents()), | 170 : content::WebContentsObserver(tab->web_contents()), |
117 cache_stats_(NULL) { | 171 cache_stats_(NULL) { |
118 is_otr_profile_ = tab->profile()->IsOffTheRecord(); | 172 is_otr_profile_ = tab->profile()->IsOffTheRecord(); |
119 } | 173 } |
120 | 174 |
121 CacheStatsTabHelper::~CacheStatsTabHelper() { | 175 CacheStatsTabHelper::~CacheStatsTabHelper() { |
122 } | 176 } |
(...skipping 25 matching lines...) Expand all Loading... | |
148 int route_id = render_view_host->GetRoutingID(); | 202 int route_id = render_view_host->GetRoutingID(); |
149 BrowserThread::PostTask( | 203 BrowserThread::PostTask( |
150 BrowserThread::IO, FROM_HERE, | 204 BrowserThread::IO, FROM_HERE, |
151 base::Bind(&CallCacheStatsTabEventOnIOThread, | 205 base::Bind(&CallCacheStatsTabEventOnIOThread, |
152 std::pair<int, int>(process_id, route_id), | 206 std::pair<int, int>(process_id, route_id), |
153 event, | 207 event, |
154 base::Unretained(g_browser_process->io_thread()))); | 208 base::Unretained(g_browser_process->io_thread()))); |
155 } | 209 } |
156 | 210 |
157 CacheStats::CacheStats() { | 211 CacheStats::CacheStats() { |
158 for (int i = 0; | 212 for (int status = REQUEST_STATUS_CACHE_WAIT; |
159 i < static_cast<int>(arraysize(kStatsCollectionTimesMs)); | 213 status <= REQUEST_STATUS_ACTIVE; |
160 i++) { | 214 status++) { |
161 final_histograms_.push_back( | 215 for (int histogram_type = HISTOGRAM_FINAL_AGGREGATE; |
162 base::LinearHistogram::FactoryGet( | 216 histogram_type < HISTOGRAM_MAX; |
163 "CacheStats.FractionCacheUseFinalPLT_" + | 217 histogram_type++) { |
164 base::IntToString(kStatsCollectionTimesMs[i]), | 218 for (int i = 0; |
165 0, 101, 102, base::Histogram::kUmaTargetedHistogramFlag)); | 219 i < static_cast<int>(arraysize(kStatsCollectionTimesMs)); |
166 intermediate_histograms_.push_back( | 220 i++) { |
167 base::LinearHistogram::FactoryGet( | 221 string histogram_name = string("CacheStats.Fraction_") + |
168 "CacheStats.FractionCacheUseIntermediatePLT_" + | 222 string(kRequestStatusNames[status]) + string("_") + |
169 base::IntToString(kStatsCollectionTimesMs[i]), | 223 string(kHistogramTypeNames[histogram_type]) + string("_") + |
170 0, 101, 102, base::Histogram::kUmaTargetedHistogramFlag)); | 224 base::IntToString(kStatsCollectionTimesMs[i]); |
225 if (histogram_type != HISTOGRAM_FINAL_CUMULATIVE_PERCENTAGE && | |
226 histogram_type != HISTOGRAM_INTERMEDIATE_CUMULATIVE_PERCENTAGE) { | |
227 histograms_[status][histogram_type].push_back( | |
228 base::LinearHistogram::FactoryGet( | |
229 histogram_name, | |
230 0, 101, 102, base::Histogram::kUmaTargetedHistogramFlag)); | |
231 } else { | |
232 histograms_[status][histogram_type].push_back( | |
233 base::Histogram::FactoryGet( | |
234 histogram_name, | |
235 0, 10000, 500, base::Histogram::kUmaTargetedHistogramFlag)); | |
rvargas (doing something else)
2012/08/16 01:18:40
What I really want is still a linear, 100 bucket h
tburkard
2012/08/16 22:37:43
I'm not sure I understand -- you want absolute tim
rvargas (doing something else)
2012/08/17 02:36:36
No, I don't want absolute times.
What I want is s
tburkard
2012/08/17 20:21:00
I think what you are talking about is just what th
rvargas (doing something else)
2012/08/17 22:05:00
So we have 6 types of histograms, and four(*) of t
tburkard
2012/08/17 22:39:56
First, there was an error in the code, I had inten
| |
236 } | |
237 } | |
238 DCHECK_EQ(histograms_[status][histogram_type].size(), | |
239 arraysize(kStatsCollectionTimesMs)); | |
240 } | |
171 } | 241 } |
172 DCHECK_EQ(final_histograms_.size(), arraysize(kStatsCollectionTimesMs)); | |
173 DCHECK_EQ(intermediate_histograms_.size(), | |
174 arraysize(kStatsCollectionTimesMs)); | |
175 } | 242 } |
176 | 243 |
177 CacheStats::~CacheStats() { | 244 CacheStats::~CacheStats() { |
178 STLDeleteValues(&tab_load_stats_); | 245 STLDeleteValues(&tab_load_stats_); |
179 } | 246 } |
180 | 247 |
181 CacheStats::TabLoadStats* CacheStats::GetTabLoadStats( | 248 CacheStats::TabLoadStats* CacheStats::GetTabLoadStats( |
182 std::pair<int, int> render_view_id) { | 249 std::pair<int, int> render_view_id) { |
183 TabLoadStatsMap::const_iterator it = tab_load_stats_.find(render_view_id); | 250 TabLoadStatsMap::const_iterator it = tab_load_stats_.find(render_view_id); |
184 if (it != tab_load_stats_.end()) | 251 if (it != tab_load_stats_.end()) |
185 return it->second; | 252 return it->second; |
186 TabLoadStats* new_tab_load_stats = new TabLoadStats(render_view_id, this); | 253 TabLoadStats* new_tab_load_stats = new TabLoadStats(render_view_id, this); |
187 tab_load_stats_[render_view_id] = new_tab_load_stats; | 254 tab_load_stats_[render_view_id] = new_tab_load_stats; |
188 return new_tab_load_stats; | 255 return new_tab_load_stats; |
189 } | 256 } |
190 | 257 |
191 void CacheStats::RemoveTabLoadStats(std::pair<int, int> render_view_id) { | 258 void CacheStats::RemoveTabLoadStats(std::pair<int, int> render_view_id) { |
192 TabLoadStatsMap::iterator it = tab_load_stats_.find(render_view_id); | 259 TabLoadStatsMap::iterator it = tab_load_stats_.find(render_view_id); |
193 if (it != tab_load_stats_.end()) { | 260 if (it != tab_load_stats_.end()) { |
194 delete it->second; | 261 delete it->second; |
195 tab_load_stats_.erase(it); | 262 tab_load_stats_.erase(it); |
196 } | 263 } |
197 } | 264 } |
198 | 265 |
199 void CacheStats::OnCacheWaitStateChange( | 266 void CacheStats::OnRequestWaitStateChange( |
200 const net::URLRequest& request, | 267 const net::URLRequest& request, |
201 net::NetworkDelegate::CacheWaitState state) { | 268 net::NetworkDelegate::RequestWaitState state) { |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
203 if (main_request_contexts_.count(request.context()) < 1) | 270 if (main_request_contexts_.count(request.context()) < 1) |
204 return; | 271 return; |
205 int process_id, route_id; | 272 int process_id, route_id; |
206 if (!GetRenderView(request, &process_id, &route_id)) | 273 if (!GetRenderView(request, &process_id, &route_id)) |
207 return; | 274 return; |
208 TabLoadStats* stats = | 275 TabLoadStats* stats = |
209 GetTabLoadStats(std::pair<int, int>(process_id, route_id)); | 276 GetTabLoadStats(std::pair<int, int>(process_id, route_id)); |
210 bool newly_started = false; | 277 RequestStatus old_status = REQUEST_STATUS_NONE; |
211 bool newly_finished = false; | 278 if (stats->active_requests.count(&request) > 0) |
279 old_status = stats->active_requests[&request]; | |
280 RequestStatus new_status = REQUEST_STATUS_NONE; | |
212 switch (state) { | 281 switch (state) { |
213 case net::NetworkDelegate::CACHE_WAIT_STATE_START: | 282 case net::NetworkDelegate::REQUEST_WAIT_STATE_CACHE_START: |
214 DCHECK(stats->active_requests.count(&request) == 0); | 283 DCHECK(old_status == REQUEST_STATUS_NONE || |
215 newly_started = true; | 284 old_status == REQUEST_STATUS_ACTIVE); |
rvargas (doing something else)
2012/08/16 01:18:40
I don't think we need both of these states.
The w
tburkard
2012/08/16 22:37:43
I think it works fine the way it is. In the case
| |
216 stats->active_requests.insert(&request); | 285 new_status = REQUEST_STATUS_CACHE_WAIT; |
217 break; | 286 break; |
218 case net::NetworkDelegate::CACHE_WAIT_STATE_FINISH: | 287 case net::NetworkDelegate::REQUEST_WAIT_STATE_CACHE_FINISH: |
219 if (stats->active_requests.count(&request) > 0) { | 288 DCHECK(old_status == REQUEST_STATUS_NONE || |
220 stats->active_requests.erase(&request); | 289 old_status == REQUEST_STATUS_CACHE_WAIT); |
221 newly_finished = true; | 290 new_status = REQUEST_STATUS_ACTIVE; |
222 } | |
223 break; | 291 break; |
224 case net::NetworkDelegate::CACHE_WAIT_STATE_RESET: | 292 case net::NetworkDelegate::REQUEST_WAIT_STATE_NETWORK_START: |
225 if (stats->active_requests.count(&request) > 0) { | 293 DCHECK(old_status == REQUEST_STATUS_NONE || |
226 stats->active_requests.erase(&request); | 294 old_status == REQUEST_STATUS_ACTIVE); |
227 newly_finished = true; | 295 new_status = REQUEST_STATUS_NETWORK_WAIT; |
228 } | 296 break; |
297 case net::NetworkDelegate::REQUEST_WAIT_STATE_NETWORK_FINISH: | |
298 DCHECK(old_status == REQUEST_STATUS_NONE || | |
299 old_status == REQUEST_STATUS_NETWORK_WAIT); | |
300 new_status = REQUEST_STATUS_ACTIVE; | |
301 break; | |
302 case net::NetworkDelegate::REQUEST_WAIT_STATE_RESET: | |
303 new_status = REQUEST_STATUS_NONE; | |
229 break; | 304 break; |
230 } | 305 } |
231 DCHECK_GE(stats->num_active, 0); | 306 if (old_status == new_status) |
232 if (newly_started) { | 307 return; |
233 DCHECK(!newly_finished); | 308 if (old_status != REQUEST_STATUS_NONE) { |
234 if (stats->num_active == 0) { | 309 TabLoadStats::PerStatusStats* status_stats = |
235 stats->cache_start_time = base::TimeTicks::Now(); | 310 &(stats->per_status_stats[old_status]); |
236 } | 311 DCHECK_GE(status_stats->num_active, 0); |
237 stats->num_active++; | 312 status_stats->UpdateTotalTimes(); |
313 if (status_stats->num_active > 0) | |
314 status_stats->num_active--; | |
315 DCHECK_GE(status_stats->num_active, 0); | |
238 } | 316 } |
239 if (newly_finished) { | 317 if (new_status != REQUEST_STATUS_NONE) { |
240 DCHECK(!newly_started); | 318 TabLoadStats::PerStatusStats* status_stats = |
241 if (stats->num_active == 1) { | 319 &(stats->per_status_stats[new_status]); |
242 stats->cache_total_time += | 320 DCHECK_GE(status_stats->num_active, 0); |
243 base::TimeTicks::Now() - stats->cache_start_time; | 321 status_stats->UpdateTotalTimes(); |
244 } | 322 status_stats->num_active++; |
245 stats->num_active--; | 323 DCHECK_GE(status_stats->num_active, 0); |
324 stats->active_requests[&request] = new_status; | |
325 } else { | |
326 stats->active_requests.erase(&request); | |
246 } | 327 } |
247 DCHECK_GE(stats->num_active, 0); | |
248 } | 328 } |
249 | 329 |
250 void CacheStats::OnTabEvent(std::pair<int, int> render_view_id, | 330 void CacheStats::OnTabEvent(std::pair<int, int> render_view_id, |
251 TabEvent event) { | 331 TabEvent event) { |
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
253 TabLoadStats* stats = GetTabLoadStats(render_view_id); | 333 TabLoadStats* stats = GetTabLoadStats(render_view_id); |
254 if (event == SPINNER_START) { | 334 if (event == SPINNER_START) { |
255 stats->spinner_started = true; | 335 stats->spinner_started = true; |
256 stats->cache_total_time = base::TimeDelta(); | 336 for (int status = REQUEST_STATUS_CACHE_WAIT; |
257 stats->cache_start_time = base::TimeTicks::Now(); | 337 status <= REQUEST_STATUS_ACTIVE; status++) { |
258 stats->load_start_time = base::TimeTicks::Now(); | 338 stats->per_status_stats[status].ResetTimes(); |
339 } | |
259 stats->next_timer_index = 0; | 340 stats->next_timer_index = 0; |
260 ScheduleTimer(stats); | 341 ScheduleTimer(stats); |
261 } else { | 342 } else { |
262 DCHECK_EQ(event, SPINNER_STOP); | 343 DCHECK_EQ(event, SPINNER_STOP); |
263 if (stats->spinner_started) { | 344 if (stats->spinner_started) { |
264 stats->spinner_started = false; | 345 stats->spinner_started = false; |
265 base::TimeDelta load_time = | 346 base::TimeDelta load_time = |
266 base::TimeTicks::Now() - stats->load_start_time; | 347 base::TimeTicks::Now() - stats->load_start_time; |
267 if (stats->num_active > 1) | 348 RecordHistograms(load_time, stats, true); |
268 stats->cache_total_time += | |
269 base::TimeTicks::Now() - stats->cache_start_time; | |
270 RecordCacheFractionHistogram(load_time, stats->cache_total_time, true, | |
271 stats->next_timer_index); | |
272 } | 349 } |
273 RemoveTabLoadStats(render_view_id); | 350 RemoveTabLoadStats(render_view_id); |
274 } | 351 } |
275 } | 352 } |
276 | 353 |
277 void CacheStats::ScheduleTimer(TabLoadStats* stats) { | 354 void CacheStats::ScheduleTimer(TabLoadStats* stats) { |
278 int timer_index = stats->next_timer_index; | 355 int timer_index = stats->next_timer_index; |
279 DCHECK(timer_index >= 0 && | 356 DCHECK(timer_index >= 0 && |
280 timer_index < static_cast<int>(arraysize(kStatsCollectionTimesMs))); | 357 timer_index < static_cast<int>(arraysize(kStatsCollectionTimesMs))); |
281 base::TimeDelta delta = | 358 base::TimeDelta delta = |
(...skipping 10 matching lines...) Expand all Loading... | |
292 stats->timer.Start(FROM_HERE, | 369 stats->timer.Start(FROM_HERE, |
293 delta, | 370 delta, |
294 base::Bind(&CacheStats::TimerCallback, | 371 base::Bind(&CacheStats::TimerCallback, |
295 base::Unretained(this), | 372 base::Unretained(this), |
296 base::Unretained(stats))); | 373 base::Unretained(stats))); |
297 } | 374 } |
298 | 375 |
299 void CacheStats::TimerCallback(TabLoadStats* stats) { | 376 void CacheStats::TimerCallback(TabLoadStats* stats) { |
300 DCHECK(stats->spinner_started); | 377 DCHECK(stats->spinner_started); |
301 base::TimeDelta load_time = base::TimeTicks::Now() - stats->load_start_time; | 378 base::TimeDelta load_time = base::TimeTicks::Now() - stats->load_start_time; |
302 base::TimeDelta cache_time = stats->cache_total_time; | 379 RecordHistograms(load_time, stats, false); |
303 if (stats->num_active > 1) | |
304 cache_time += base::TimeTicks::Now() - stats->cache_start_time; | |
305 RecordCacheFractionHistogram(load_time, cache_time, false, | |
306 stats->next_timer_index); | |
307 stats->next_timer_index++; | 380 stats->next_timer_index++; |
308 if (stats->next_timer_index < | 381 if (stats->next_timer_index < |
309 static_cast<int>(arraysize(kStatsCollectionTimesMs))) { | 382 static_cast<int>(arraysize(kStatsCollectionTimesMs))) { |
310 ScheduleTimer(stats); | 383 ScheduleTimer(stats); |
311 } else { | 384 } else { |
312 RemoveTabLoadStats(stats->render_view_id); | 385 RemoveTabLoadStats(stats->render_view_id); |
313 } | 386 } |
314 } | 387 } |
315 | 388 |
316 void CacheStats::RecordCacheFractionHistogram(base::TimeDelta elapsed, | 389 void CacheStats::RecordHistograms(base::TimeDelta elapsed, |
317 base::TimeDelta cache_time, | 390 TabLoadStats* stats, |
318 bool is_load_done, | 391 bool is_load_done) { |
319 int timer_index) { | 392 int timer_index = stats->next_timer_index; |
320 DCHECK(timer_index >= 0 && | 393 DCHECK(timer_index >= 0 && |
321 timer_index < static_cast<int>(arraysize(kStatsCollectionTimesMs))); | 394 timer_index < static_cast<int>(arraysize(kStatsCollectionTimesMs))); |
322 | 395 |
323 if (elapsed.InMilliseconds() <= 0) | 396 if (elapsed.InMilliseconds() <= 0) |
324 return; | 397 return; |
325 | 398 |
326 int64 cache_fraction_percentage = | 399 base::TimeDelta total_cumulative; |
327 100 * cache_time.InMilliseconds() / elapsed.InMilliseconds(); | 400 for (int status_int = REQUEST_STATUS_CACHE_WAIT; |
401 status_int <= REQUEST_STATUS_ACTIVE; | |
402 status_int++) { | |
403 RequestStatus status = static_cast<RequestStatus>(status_int); | |
404 total_cumulative += stats->per_status_stats[status].total_cumulative_time; | |
405 } | |
328 | 406 |
329 DCHECK(cache_fraction_percentage >= 0 && cache_fraction_percentage <= 100); | 407 for (int status_int = REQUEST_STATUS_CACHE_WAIT; |
408 status_int <= REQUEST_STATUS_ACTIVE; | |
409 status_int++) { | |
410 RequestStatus status = static_cast<RequestStatus>(status_int); | |
411 TabLoadStats::PerStatusStats* status_stats = | |
412 &(stats->per_status_stats[status]); | |
330 | 413 |
331 if (is_load_done) { | 414 int64 fraction_percentage = 100 * |
332 final_histograms_[timer_index]->Add(cache_fraction_percentage); | 415 status_stats->total_time.InMilliseconds() / elapsed.InMilliseconds(); |
333 } else { | 416 DCHECK(fraction_percentage >= 0 && fraction_percentage <= 100); |
334 intermediate_histograms_[timer_index]->Add(cache_fraction_percentage); | 417 if (is_load_done) { |
418 histograms_[status][HISTOGRAM_FINAL_AGGREGATE][timer_index]->Add( | |
419 fraction_percentage); | |
420 } else { | |
421 histograms_[status][HISTOGRAM_INTERMEDIATE_AGGREGATE][timer_index]->Add( | |
422 fraction_percentage); | |
423 } | |
424 | |
425 fraction_percentage = 100 * | |
rvargas (doing something else)
2012/08/17 22:05:00
Can we just eliminate these 60 histograms?
tburkard
2012/08/17 22:39:56
Done.
| |
426 status_stats->total_cumulative_time.InMilliseconds() / | |
427 elapsed.InMilliseconds(); | |
428 DCHECK(fraction_percentage >= 0); | |
429 if (is_load_done) { | |
430 histograms_[status][HISTOGRAM_FINAL_CUMULATIVE][timer_index]->Add( | |
431 fraction_percentage); | |
432 } else { | |
433 histograms_[status][HISTOGRAM_INTERMEDIATE_CUMULATIVE][timer_index]->Add( | |
434 fraction_percentage); | |
435 } | |
436 | |
437 if (total_cumulative.InMilliseconds() > 0) { | |
438 fraction_percentage = 100 * | |
439 status_stats->total_cumulative_time.InMilliseconds() / | |
440 total_cumulative.InMilliseconds(); | |
441 DCHECK(fraction_percentage >= 0 && fraction_percentage <= 100); | |
442 if (is_load_done) { | |
443 histograms_[status][HISTOGRAM_FINAL_CUMULATIVE_PERCENTAGE] | |
444 [timer_index]->Add(fraction_percentage); | |
445 } else { | |
446 histograms_[status][HISTOGRAM_INTERMEDIATE_CUMULATIVE_PERCENTAGE] | |
447 [timer_index]->Add(fraction_percentage); | |
448 } | |
449 } | |
335 } | 450 } |
336 } | 451 } |
337 | 452 |
338 void CacheStats::RegisterURLRequestContext( | 453 void CacheStats::RegisterURLRequestContext( |
339 const net::URLRequestContext* context, | 454 const net::URLRequestContext* context, |
340 ChromeURLRequestContext::ContextType type) { | 455 ChromeURLRequestContext::ContextType type) { |
341 if (type == ChromeURLRequestContext::CONTEXT_TYPE_MAIN) | 456 if (type == ChromeURLRequestContext::CONTEXT_TYPE_MAIN) |
342 main_request_contexts_.insert(context); | 457 main_request_contexts_.insert(context); |
343 } | 458 } |
344 | 459 |
345 void CacheStats::UnregisterURLRequestContext( | 460 void CacheStats::UnregisterURLRequestContext( |
346 const net::URLRequestContext* context) { | 461 const net::URLRequestContext* context) { |
347 main_request_contexts_.erase(context); | 462 main_request_contexts_.erase(context); |
348 } | 463 } |
349 | 464 |
350 } // namespace chrome_browser_net | 465 } // namespace chrome_browser_net |
OLD | NEW |