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 <set> | 5 #include <set> |
6 | 6 |
7 #include "content/browser/loader/resource_scheduler.h" | 7 #include "content/browser/loader/resource_scheduler.h" |
8 | 8 |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "content/common/resource_messages.h" | 13 #include "content/common/resource_messages.h" |
14 #include "content/browser/loader/resource_message_delegate.h" | 14 #include "content/browser/loader/resource_message_delegate.h" |
15 #include "content/public/browser/resource_controller.h" | 15 #include "content/public/browser/resource_controller.h" |
16 #include "content/public/browser/resource_request_info.h" | 16 #include "content/public/browser/resource_request_info.h" |
17 #include "content/public/browser/resource_throttle.h" | 17 #include "content/public/browser/resource_throttle.h" |
18 #include "ipc/ipc_message_macros.h" | 18 #include "ipc/ipc_message_macros.h" |
19 #include "net/base/host_port_pair.h" | 19 #include "net/base/host_port_pair.h" |
20 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
21 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
22 #include "net/http/http_server_properties.h" | 22 #include "net/http/http_server_properties.h" |
23 #include "net/url_request/url_request.h" | 23 #include "net/url_request/url_request.h" |
24 #include "net/url_request/url_request_context.h" | 24 #include "net/url_request/url_request_context.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
| 30 // Post ResourceScheduler histograms of the following forms: |
| 31 // If |histogram_suffix| is NULL or the empty string: |
| 32 // ResourceScheduler.base_name.histogram_name |
| 33 // Else: |
| 34 // ResourceScheduler.base_name.histogram_name.histogram_suffix |
30 void PostHistogram(const char* base_name, | 35 void PostHistogram(const char* base_name, |
31 const char* suffix, | 36 const char* histogram_name, |
| 37 const char* histogram_suffix, |
32 base::TimeDelta time) { | 38 base::TimeDelta time) { |
33 std::string histogram_name = | 39 std::string histogram = |
34 base::StringPrintf("ResourceScheduler.%s.%s", base_name, suffix); | 40 base::StringPrintf("ResourceScheduler.%s.%s", base_name, histogram_name); |
| 41 if (histogram_suffix && histogram_suffix[0] != '\0') |
| 42 histogram = histogram + "." + histogram_suffix; |
35 base::HistogramBase* histogram_counter = base::Histogram::FactoryTimeGet( | 43 base::HistogramBase* histogram_counter = base::Histogram::FactoryTimeGet( |
36 histogram_name, | 44 histogram, base::TimeDelta::FromMilliseconds(1), |
37 base::TimeDelta::FromMilliseconds(1), | 45 base::TimeDelta::FromMinutes(5), 50, |
38 base::TimeDelta::FromMinutes(5), | |
39 50, | |
40 base::Histogram::kUmaTargetedHistogramFlag); | 46 base::Histogram::kUmaTargetedHistogramFlag); |
41 histogram_counter->AddTime(time); | 47 histogram_counter->AddTime(time); |
42 } | 48 } |
43 | 49 |
| 50 // For use with PostHistogram to specify the correct string for histogram |
| 51 // suffixes based on number of Clients. |
| 52 const char* GetNumClientsString(size_t num_clients) { |
| 53 if (num_clients == 1) |
| 54 return "1Client"; |
| 55 else if (num_clients <= 5) |
| 56 return "Max5Clients"; |
| 57 else if (num_clients <= 15) |
| 58 return "Max15Clients"; |
| 59 else if (num_clients <= 30) |
| 60 return "Max30Clients"; |
| 61 return "Over30Clients"; |
| 62 } |
| 63 |
44 } // namespace | 64 } // namespace |
45 | 65 |
46 static const size_t kCoalescedTimerPeriod = 5000; | 66 static const size_t kCoalescedTimerPeriod = 5000; |
47 static const size_t kMaxNumDelayableRequestsPerClient = 10; | 67 static const size_t kMaxNumDelayableRequestsPerClient = 10; |
48 static const size_t kMaxNumDelayableRequestsPerHost = 6; | 68 static const size_t kMaxNumDelayableRequestsPerHost = 6; |
49 static const size_t kMaxNumThrottledRequestsPerClient = 1; | 69 static const size_t kMaxNumThrottledRequestsPerClient = 1; |
50 | 70 |
51 struct ResourceScheduler::RequestPriorityParams { | 71 struct ResourceScheduler::RequestPriorityParams { |
52 RequestPriorityParams() | 72 RequestPriorityParams() |
53 : priority(net::DEFAULT_PRIORITY), | 73 : priority(net::DEFAULT_PRIORITY), |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 current_state == BACKGROUND) { | 195 current_state == BACKGROUND) { |
176 client_state = "Background"; | 196 client_state = "Background"; |
177 } | 197 } |
178 | 198 |
179 base::TimeDelta time_was_deferred = base::TimeDelta::FromMicroseconds(0); | 199 base::TimeDelta time_was_deferred = base::TimeDelta::FromMicroseconds(0); |
180 if (deferred_) { | 200 if (deferred_) { |
181 deferred_ = false; | 201 deferred_ = false; |
182 controller()->Resume(); | 202 controller()->Resume(); |
183 time_was_deferred = time - time_deferred_; | 203 time_was_deferred = time - time_deferred_; |
184 } | 204 } |
185 PostHistogram("RequestTimeDeferred", client_state, time_was_deferred); | 205 PostHistogram("RequestTimeDeferred", client_state, NULL, time_was_deferred); |
186 PostHistogram( | 206 PostHistogram("RequestTimeThrottled", client_state, NULL, |
187 "RequestTimeThrottled", client_state, time - request_->creation_time()); | 207 time - request_->creation_time()); |
188 // TODO(aiolos): Remove one of the above histograms after gaining an | 208 // TODO(aiolos): Remove one of the above histograms after gaining an |
189 // understanding of the difference between them and which one is more | 209 // understanding of the difference between them and which one is more |
190 // interesting. | 210 // interesting. |
191 } | 211 } |
192 | 212 |
193 void set_request_priority_params(const RequestPriorityParams& priority) { | 213 void set_request_priority_params(const RequestPriorityParams& priority) { |
194 priority_ = priority; | 214 priority_ = priority; |
195 } | 215 } |
196 const RequestPriorityParams& get_request_priority_params() const { | 216 const RequestPriorityParams& get_request_priority_params() const { |
197 return priority_; | 217 return priority_; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 return; | 381 return; |
362 } | 382 } |
363 is_loaded_ = is_loaded; | 383 is_loaded_ = is_loaded; |
364 UpdateThrottleState(); | 384 UpdateThrottleState(); |
365 if (!is_loaded_) { | 385 if (!is_loaded_) { |
366 load_started_time_ = base::TimeTicks::Now(); | 386 load_started_time_ = base::TimeTicks::Now(); |
367 last_active_switch_time_ = base::TimeTicks(); | 387 last_active_switch_time_ = base::TimeTicks(); |
368 return; | 388 return; |
369 } | 389 } |
370 base::TimeTicks cur_time = base::TimeTicks::Now(); | 390 base::TimeTicks cur_time = base::TimeTicks::Now(); |
| 391 const char* num_clients = |
| 392 GetNumClientsString(scheduler_->client_map_.size()); |
371 const char* client_catagory = "Other"; | 393 const char* client_catagory = "Other"; |
372 if (last_active_switch_time_.is_null()) { | 394 if (last_active_switch_time_.is_null()) { |
373 client_catagory = is_active() ? "Active" : "Background"; | 395 client_catagory = is_active() ? "Active" : "Background"; |
374 } else if (is_active()) { | 396 } else if (is_active()) { |
375 PostHistogram("ClientLoadedTime", "Other.SwitchedToActive", | 397 base::TimeDelta time_since_active = cur_time - last_active_switch_time_; |
376 cur_time - last_active_switch_time_); | 398 PostHistogram("ClientLoadedTime", "Other.SwitchedToActive", NULL, |
| 399 time_since_active); |
| 400 PostHistogram("ClientLoadedTime", "Other.SwitchedToActive", num_clients, |
| 401 time_since_active); |
377 } | 402 } |
378 PostHistogram("ClientLoadedTime", client_catagory, | 403 base::TimeDelta time_since_load_started = cur_time - load_started_time_; |
379 cur_time - load_started_time_); | 404 PostHistogram("ClientLoadedTime", client_catagory, NULL, |
| 405 time_since_load_started); |
| 406 PostHistogram("ClientLoadedTime", client_catagory, num_clients, |
| 407 time_since_load_started); |
380 // TODO(aiolos): The above histograms will not take main resource load time | 408 // TODO(aiolos): The above histograms will not take main resource load time |
381 // into account with PlzNavigate into account. The ResourceScheduler also | 409 // into account with PlzNavigate into account. The ResourceScheduler also |
382 // will load the main resources without a clients with the current logic. | 410 // will load the main resources without a clients with the current logic. |
383 // Find a way to fix both of these issues. | 411 // Find a way to fix both of these issues. |
384 } | 412 } |
385 | 413 |
386 void SetPaused() { | 414 void SetPaused() { |
387 is_paused_ = true; | 415 is_paused_ = true; |
388 UpdateThrottleState(); | 416 UpdateThrottleState(); |
389 } | 417 } |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 int route_id, | 899 int route_id, |
872 bool is_visible, | 900 bool is_visible, |
873 bool is_audible) { | 901 bool is_audible) { |
874 DCHECK(CalledOnValidThread()); | 902 DCHECK(CalledOnValidThread()); |
875 ClientId client_id = MakeClientId(child_id, route_id); | 903 ClientId client_id = MakeClientId(child_id, route_id); |
876 DCHECK(!ContainsKey(client_map_, client_id)); | 904 DCHECK(!ContainsKey(client_map_, client_id)); |
877 | 905 |
878 Client* client = new Client(this, is_visible, is_audible); | 906 Client* client = new Client(this, is_visible, is_audible); |
879 client_map_[client_id] = client; | 907 client_map_[client_id] = client; |
880 | 908 |
881 // TODO(aiolos): set Client visibility/audibility when signals are added | |
882 // this will UNTHROTTLE Clients as needed | |
883 client->UpdateThrottleState(); | 909 client->UpdateThrottleState(); |
884 } | 910 } |
885 | 911 |
886 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { | 912 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { |
887 DCHECK(CalledOnValidThread()); | 913 DCHECK(CalledOnValidThread()); |
888 ClientId client_id = MakeClientId(child_id, route_id); | 914 ClientId client_id = MakeClientId(child_id, route_id); |
889 DCHECK(ContainsKey(client_map_, client_id)); | 915 DCHECK(ContainsKey(client_map_, client_id)); |
890 ClientMap::iterator it = client_map_.find(client_id); | 916 ClientMap::iterator it = client_map_.find(client_id); |
891 if (it == client_map_.end()) | 917 if (it == client_map_.end()) |
892 return; | 918 return; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 client->ReprioritizeRequest( | 1140 client->ReprioritizeRequest( |
1115 request, old_priority_params, new_priority_params); | 1141 request, old_priority_params, new_priority_params); |
1116 } | 1142 } |
1117 | 1143 |
1118 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 1144 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
1119 int child_id, int route_id) { | 1145 int child_id, int route_id) { |
1120 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 1146 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
1121 } | 1147 } |
1122 | 1148 |
1123 } // namespace content | 1149 } // namespace content |
OLD | NEW |