Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: content/browser/loader/resource_scheduler.cc

Issue 782903002: Breakdown ClientLoadedTime histograms into buckets based on number of clients. Fix RequestTimeThrot… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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:
mmenke 2015/01/06 19:30:03 nit: |histogram_suffix|
aiolos (Not reviewing) 2015/01/07 22:28:15 Done.
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,
Ilya Sherman 2015/01/06 02:19:14 I meant, why not pass the strings as "const std::s
aiolos (Not reviewing) 2015/01/07 22:28:15 Matt: you wanted const char* for the suffix in oth
mmenke 2015/01/07 22:32:42 I generally think the fewer strings we make the be
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,
37 base::TimeDelta::FromMilliseconds(1), 45 base::TimeDelta::FromMilliseconds(1),
38 base::TimeDelta::FromMinutes(5), 46 base::TimeDelta::FromMinutes(5),
39 50, 47 50,
40 base::Histogram::kUmaTargetedHistogramFlag); 48 base::Histogram::kUmaTargetedHistogramFlag);
41 histogram_counter->AddTime(time); 49 histogram_counter->AddTime(time);
42 } 50 }
43 51
52 // For use with PostHistogram to specify the correct string for histogram
53 // suffixes based on number of Clients.
54 const char* GetNumClientsString(size_t num_clients) {
55 if (num_clients == 1)
56 return "1Client";
57 else if (num_clients <= 5)
58 return "Max5Clients";
59 else if (num_clients <= 15)
60 return "Max15Clients";
61 else if (num_clients <= 30)
62 return "Max30Clients";
63 return "Over30Clients";
64 }
65
44 } // namespace 66 } // namespace
45 67
46 static const size_t kCoalescedTimerPeriod = 5000; 68 static const size_t kCoalescedTimerPeriod = 5000;
47 static const size_t kMaxNumDelayableRequestsPerClient = 10; 69 static const size_t kMaxNumDelayableRequestsPerClient = 10;
48 static const size_t kMaxNumDelayableRequestsPerHost = 6; 70 static const size_t kMaxNumDelayableRequestsPerHost = 6;
49 static const size_t kMaxNumThrottledRequestsPerClient = 1; 71 static const size_t kMaxNumThrottledRequestsPerClient = 1;
50 72
51 struct ResourceScheduler::RequestPriorityParams { 73 struct ResourceScheduler::RequestPriorityParams {
52 RequestPriorityParams() 74 RequestPriorityParams()
53 : priority(net::DEFAULT_PRIORITY), 75 : priority(net::DEFAULT_PRIORITY),
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 current_state == BACKGROUND) { 197 current_state == BACKGROUND) {
176 client_state = "Background"; 198 client_state = "Background";
177 } 199 }
178 200
179 base::TimeDelta time_was_deferred = base::TimeDelta::FromMicroseconds(0); 201 base::TimeDelta time_was_deferred = base::TimeDelta::FromMicroseconds(0);
180 if (deferred_) { 202 if (deferred_) {
181 deferred_ = false; 203 deferred_ = false;
182 controller()->Resume(); 204 controller()->Resume();
183 time_was_deferred = time - time_deferred_; 205 time_was_deferred = time - time_deferred_;
184 } 206 }
185 PostHistogram("RequestTimeDeferred", client_state, time_was_deferred); 207 PostHistogram("RequestTimeDeferred", client_state, NULL, time_was_deferred);
186 PostHistogram( 208 PostHistogram("RequestTimeThrottled", client_state, NULL,
187 "RequestTimeThrottled", client_state, time - request_->creation_time()); 209 time - request_->creation_time());
188 // TODO(aiolos): Remove one of the above histograms after gaining an 210 // TODO(aiolos): Remove one of the above histograms after gaining an
189 // understanding of the difference between them and which one is more 211 // understanding of the difference between them and which one is more
190 // interesting. 212 // interesting.
191 } 213 }
192 214
193 void set_request_priority_params(const RequestPriorityParams& priority) { 215 void set_request_priority_params(const RequestPriorityParams& priority) {
194 priority_ = priority; 216 priority_ = priority;
195 } 217 }
196 const RequestPriorityParams& get_request_priority_params() const { 218 const RequestPriorityParams& get_request_priority_params() const {
197 return priority_; 219 return priority_;
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 return; 383 return;
362 } 384 }
363 is_loaded_ = is_loaded; 385 is_loaded_ = is_loaded;
364 UpdateThrottleState(); 386 UpdateThrottleState();
365 if (!is_loaded_) { 387 if (!is_loaded_) {
366 load_started_time_ = base::TimeTicks::Now(); 388 load_started_time_ = base::TimeTicks::Now();
367 last_active_switch_time_ = base::TimeTicks(); 389 last_active_switch_time_ = base::TimeTicks();
368 return; 390 return;
369 } 391 }
370 base::TimeTicks cur_time = base::TimeTicks::Now(); 392 base::TimeTicks cur_time = base::TimeTicks::Now();
393 const char* num_clients = GetNumClientsString(scheduler_->GetNumClients());
371 const char* client_catagory = "Other"; 394 const char* client_catagory = "Other";
372 if (last_active_switch_time_.is_null()) { 395 if (last_active_switch_time_.is_null()) {
373 client_catagory = is_active() ? "Active" : "Background"; 396 client_catagory = is_active() ? "Active" : "Background";
374 } else if (is_active()) { 397 } else if (is_active()) {
375 PostHistogram("ClientLoadedTime", "Other.SwitchedToActive", 398 base::TimeDelta time_since_active = cur_time - last_active_switch_time_;
376 cur_time - last_active_switch_time_); 399 PostHistogram("ClientLoadedTime", "Other.SwitchedToActive", NULL,
400 time_since_active);
401 PostHistogram("ClientLoadedTime", "Other.SwitchedToActive", num_clients,
402 time_since_active);
377 } 403 }
378 PostHistogram("ClientLoadedTime", client_catagory, 404 base::TimeDelta time_since_load_started = cur_time - load_started_time_;
379 cur_time - load_started_time_); 405 PostHistogram("ClientLoadedTime", client_catagory, NULL,
406 time_since_load_started);
407 PostHistogram("ClientLoadedTime", client_catagory, num_clients,
408 time_since_load_started);
380 // TODO(aiolos): The above histograms will not take main resource load time 409 // TODO(aiolos): The above histograms will not take main resource load time
381 // into account with PlzNavigate into account. The ResourceScheduler also 410 // into account with PlzNavigate into account. The ResourceScheduler also
382 // will load the main resources without a clients with the current logic. 411 // will load the main resources without a clients with the current logic.
383 // Find a way to fix both of these issues. 412 // Find a way to fix both of these issues.
384 } 413 }
385 414
386 void SetPaused() { 415 void SetPaused() {
387 is_paused_ = true; 416 is_paused_ = true;
388 UpdateThrottleState(); 417 UpdateThrottleState();
389 } 418 }
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 int route_id, 900 int route_id,
872 bool is_visible, 901 bool is_visible,
873 bool is_audible) { 902 bool is_audible) {
874 DCHECK(CalledOnValidThread()); 903 DCHECK(CalledOnValidThread());
875 ClientId client_id = MakeClientId(child_id, route_id); 904 ClientId client_id = MakeClientId(child_id, route_id);
876 DCHECK(!ContainsKey(client_map_, client_id)); 905 DCHECK(!ContainsKey(client_map_, client_id));
877 906
878 Client* client = new Client(this, is_visible, is_audible); 907 Client* client = new Client(this, is_visible, is_audible);
879 client_map_[client_id] = client; 908 client_map_[client_id] = client;
880 909
881 // TODO(aiolos): set Client visibility/audibility when signals are added
882 // this will UNTHROTTLE Clients as needed
883 client->UpdateThrottleState(); 910 client->UpdateThrottleState();
884 } 911 }
885 912
886 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { 913 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) {
887 DCHECK(CalledOnValidThread()); 914 DCHECK(CalledOnValidThread());
888 ClientId client_id = MakeClientId(child_id, route_id); 915 ClientId client_id = MakeClientId(child_id, route_id);
889 DCHECK(ContainsKey(client_map_, client_id)); 916 DCHECK(ContainsKey(client_map_, client_id));
890 ClientMap::iterator it = client_map_.find(client_id); 917 ClientMap::iterator it = client_map_.find(client_id);
891 if (it == client_map_.end()) 918 if (it == client_map_.end())
892 return; 919 return;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 1018
992 void ResourceScheduler::DecrementActiveClientsLoading() { 1019 void ResourceScheduler::DecrementActiveClientsLoading() {
993 DCHECK_NE(0u, active_clients_loading_); 1020 DCHECK_NE(0u, active_clients_loading_);
994 --active_clients_loading_; 1021 --active_clients_loading_;
995 DCHECK_EQ(active_clients_loading_, CountActiveClientsLoading()); 1022 DCHECK_EQ(active_clients_loading_, CountActiveClientsLoading());
996 if (active_clients_loading_ == 0) { 1023 if (active_clients_loading_ == 0) {
997 OnLoadingActiveClientsStateChangedForAllClients(); 1024 OnLoadingActiveClientsStateChangedForAllClients();
998 } 1025 }
999 } 1026 }
1000 1027
1028 size_t ResourceScheduler::GetNumClients() const {
1029 return client_map_.size();
1030 }
1031
1001 void ResourceScheduler::IncrementActiveClientsLoading() { 1032 void ResourceScheduler::IncrementActiveClientsLoading() {
1002 ++active_clients_loading_; 1033 ++active_clients_loading_;
1003 DCHECK_EQ(active_clients_loading_, CountActiveClientsLoading()); 1034 DCHECK_EQ(active_clients_loading_, CountActiveClientsLoading());
1004 if (active_clients_loading_ == 1) { 1035 if (active_clients_loading_ == 1) {
1005 OnLoadingActiveClientsStateChangedForAllClients(); 1036 OnLoadingActiveClientsStateChangedForAllClients();
1006 } 1037 }
1007 } 1038 }
1008 1039
1009 void ResourceScheduler::OnLoadingActiveClientsStateChangedForAllClients() { 1040 void ResourceScheduler::OnLoadingActiveClientsStateChangedForAllClients() {
1010 ClientMap::iterator client_it = client_map_.begin(); 1041 ClientMap::iterator client_it = client_map_.begin();
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 client->ReprioritizeRequest( 1145 client->ReprioritizeRequest(
1115 request, old_priority_params, new_priority_params); 1146 request, old_priority_params, new_priority_params);
1116 } 1147 }
1117 1148
1118 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( 1149 ResourceScheduler::ClientId ResourceScheduler::MakeClientId(
1119 int child_id, int route_id) { 1150 int child_id, int route_id) {
1120 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; 1151 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id;
1121 } 1152 }
1122 1153
1123 } // namespace content 1154 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698