Chromium Code Reviews| 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 "content/browser/loader/resource_scheduler.h" | 5 #include "content/browser/loader/resource_scheduler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 bool is_async) | 220 bool is_async) |
| 221 : client_id_(client_id), | 221 : client_id_(client_id), |
| 222 request_(request), | 222 request_(request), |
| 223 ready_(false), | 223 ready_(false), |
| 224 deferred_(false), | 224 deferred_(false), |
| 225 is_async_(is_async), | 225 is_async_(is_async), |
| 226 attributes_(kAttributeNone), | 226 attributes_(kAttributeNone), |
| 227 scheduler_(scheduler), | 227 scheduler_(scheduler), |
| 228 priority_(priority), | 228 priority_(priority), |
| 229 fifo_ordering_(0), | 229 fifo_ordering_(0), |
| 230 delayable_requests_in_flight_(0u), | |
| 230 host_port_pair_(net::HostPortPair::FromURL(request->url())), | 231 host_port_pair_(net::HostPortPair::FromURL(request->url())), |
| 231 weak_ptr_factory_(this) { | 232 weak_ptr_factory_(this) { |
| 232 DCHECK(!request_->GetUserData(kUserDataKey)); | 233 DCHECK(!request_->GetUserData(kUserDataKey)); |
| 233 request_->SetUserData(kUserDataKey, base::MakeUnique<UnownedPointer>(this)); | 234 request_->SetUserData(kUserDataKey, base::MakeUnique<UnownedPointer>(this)); |
| 234 } | 235 } |
| 235 | 236 |
| 236 ~ScheduledResourceRequest() override { | 237 ~ScheduledResourceRequest() override { |
| 238 if ((attributes_ & kAttributeLayoutBlocking) == kAttributeLayoutBlocking) { | |
| 239 UMA_HISTOGRAM_COUNTS_100( | |
| 240 "ResourceScheduler.PeakDelayableRequestsInFlight.LayoutBlocking", | |
| 241 delayable_requests_in_flight_); | |
| 242 } | |
| 243 if (!((attributes_ & kAttributeDelayable) == kAttributeDelayable)) { | |
| 244 UMA_HISTOGRAM_COUNTS_100( | |
| 245 "ResourceScheduler.PeakDelayableRequestsInFlight.NonDelayable", | |
| 246 delayable_requests_in_flight_); | |
| 247 } | |
| 237 request_->RemoveUserData(kUserDataKey); | 248 request_->RemoveUserData(kUserDataKey); |
| 238 scheduler_->RemoveRequest(this); | 249 scheduler_->RemoveRequest(this); |
| 239 } | 250 } |
| 240 | 251 |
| 241 static ScheduledResourceRequest* ForRequest(net::URLRequest* request) { | 252 static ScheduledResourceRequest* ForRequest(net::URLRequest* request) { |
| 242 UnownedPointer* pointer = | 253 UnownedPointer* pointer = |
| 243 static_cast<UnownedPointer*>(request->GetUserData(kUserDataKey)); | 254 static_cast<UnownedPointer*>(request->GetUserData(kUserDataKey)); |
| 244 return pointer ? pointer->get() : nullptr; | 255 return pointer ? pointer->get() : nullptr; |
| 245 } | 256 } |
| 246 | 257 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 267 START_SYNC)); | 278 START_SYNC)); |
| 268 return; | 279 return; |
| 269 } | 280 } |
| 270 deferred_ = false; | 281 deferred_ = false; |
| 271 Resume(); | 282 Resume(); |
| 272 } | 283 } |
| 273 | 284 |
| 274 ready_ = true; | 285 ready_ = true; |
| 275 } | 286 } |
| 276 | 287 |
| 288 void UpdateDelayableRequestsInFlight(size_t delayable_requests_in_flight) { | |
| 289 delayable_requests_in_flight_ = | |
| 290 std::max(delayable_requests_in_flight_, delayable_requests_in_flight); | |
| 291 } | |
| 292 | |
| 277 void set_request_priority_params(const RequestPriorityParams& priority) { | 293 void set_request_priority_params(const RequestPriorityParams& priority) { |
| 278 priority_ = priority; | 294 priority_ = priority; |
| 279 } | 295 } |
| 280 const RequestPriorityParams& get_request_priority_params() const { | 296 const RequestPriorityParams& get_request_priority_params() const { |
| 281 return priority_; | 297 return priority_; |
| 282 } | 298 } |
| 283 const ClientId& client_id() const { return client_id_; } | 299 const ClientId& client_id() const { return client_id_; } |
| 284 net::URLRequest* url_request() { return request_; } | 300 net::URLRequest* url_request() { return request_; } |
| 285 const net::URLRequest* url_request() const { return request_; } | 301 const net::URLRequest* url_request() const { return request_; } |
| 286 bool is_async() const { return is_async_; } | 302 bool is_async() const { return is_async_; } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 | 337 |
| 322 const ClientId client_id_; | 338 const ClientId client_id_; |
| 323 net::URLRequest* request_; | 339 net::URLRequest* request_; |
| 324 bool ready_; | 340 bool ready_; |
| 325 bool deferred_; | 341 bool deferred_; |
| 326 bool is_async_; | 342 bool is_async_; |
| 327 RequestAttributes attributes_; | 343 RequestAttributes attributes_; |
| 328 ResourceScheduler* scheduler_; | 344 ResourceScheduler* scheduler_; |
| 329 RequestPriorityParams priority_; | 345 RequestPriorityParams priority_; |
| 330 uint32_t fifo_ordering_; | 346 uint32_t fifo_ordering_; |
| 347 | |
| 348 // True if a delayable request was in-flight at the same when |this| was | |
| 349 // in-flight. | |
|
Randy Smith (Not in Mondays)
2017/05/21 21:43:56
I think the comment's out of date? Sounds like it
tbansal1
2017/05/25 01:07:46
Thanks. Fixed.
| |
| 350 size_t delayable_requests_in_flight_; | |
| 331 // Cached to excessive recomputation in ShouldKeepSearching. | 351 // Cached to excessive recomputation in ShouldKeepSearching. |
| 332 const net::HostPortPair host_port_pair_; | 352 const net::HostPortPair host_port_pair_; |
| 333 | 353 |
| 334 base::WeakPtrFactory<ResourceScheduler::ScheduledResourceRequest> | 354 base::WeakPtrFactory<ResourceScheduler::ScheduledResourceRequest> |
| 335 weak_ptr_factory_; | 355 weak_ptr_factory_; |
| 336 | 356 |
| 337 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); | 357 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); |
| 338 }; | 358 }; |
| 339 | 359 |
| 340 const void* const ResourceScheduler::ScheduledResourceRequest::kUserDataKey = | 360 const void* const ResourceScheduler::ScheduledResourceRequest::kUserDataKey = |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 } | 507 } |
| 488 | 508 |
| 489 private: | 509 private: |
| 490 enum ShouldStartReqResult { | 510 enum ShouldStartReqResult { |
| 491 DO_NOT_START_REQUEST_AND_STOP_SEARCHING, | 511 DO_NOT_START_REQUEST_AND_STOP_SEARCHING, |
| 492 DO_NOT_START_REQUEST_AND_KEEP_SEARCHING, | 512 DO_NOT_START_REQUEST_AND_KEEP_SEARCHING, |
| 493 START_REQUEST, | 513 START_REQUEST, |
| 494 YIELD_SCHEDULER | 514 YIELD_SCHEDULER |
| 495 }; | 515 }; |
| 496 | 516 |
| 517 // Records the metrics related to number of requests in flight. | |
| 518 void RecordRequestCountMetrics() const { | |
| 519 UMA_HISTOGRAM_COUNTS_100("ResourceScheduler.RequestsCount.All", | |
| 520 in_flight_requests_.size()); | |
| 521 UMA_HISTOGRAM_COUNTS_100("ResourceScheduler.RequestsCount.Delayable", | |
| 522 in_flight_delayable_count_); | |
| 523 | |
| 524 size_t non_delayable_in_flight_count = | |
| 525 in_flight_requests_.size() - in_flight_delayable_count_; | |
| 526 | |
| 527 UMA_HISTOGRAM_COUNTS_100("ResourceScheduler.RequestsCount.NonDelayable", | |
| 528 non_delayable_in_flight_count); | |
|
Randy Smith (Not in Mondays)
2017/05/21 21:43:56
I don't have strong objections, but histograms do
tbansal1
2017/05/25 01:07:46
I am not sure if this is duplicate of some other h
Randy Smith (Not in Mondays)
2017/05/25 17:40:12
Good point, though it's possible with some serious
tbansal1
2017/05/31 06:31:21
Yes, for now I think it is useful to record the di
| |
| 529 UMA_HISTOGRAM_COUNTS_100( | |
| 530 "ResourceScheduler.RequestsCount.TotalLayoutBlocking", | |
| 531 total_layout_blocking_count_); | |
| 532 | |
| 533 if (total_layout_blocking_count_ > 0) { | |
| 534 UMA_HISTOGRAM_COUNTS_100( | |
| 535 "ResourceScheduler.RequestsCount.DelayableWhenLayoutBlocking", | |
| 536 in_flight_delayable_count_); | |
| 537 } | |
| 538 | |
| 539 if (non_delayable_in_flight_count > 0) { | |
| 540 UMA_HISTOGRAM_COUNTS_100( | |
| 541 "ResourceScheduler.RequestsCount.DelayableWhenNonDelayable", | |
| 542 in_flight_delayable_count_); | |
| 543 } | |
| 544 } | |
| 545 | |
| 497 void InsertInFlightRequest(ScheduledResourceRequest* request) { | 546 void InsertInFlightRequest(ScheduledResourceRequest* request) { |
| 498 in_flight_requests_.insert(request); | 547 in_flight_requests_.insert(request); |
| 499 SetRequestAttributes(request, DetermineRequestAttributes(request)); | 548 SetRequestAttributes(request, DetermineRequestAttributes(request)); |
| 549 RecordRequestCountMetrics(); | |
|
Randy Smith (Not in Mondays)
2017/05/21 21:43:56
I remain uncertain that you're going to get good s
tbansal1
2017/05/25 01:07:46
I agree with the spirit of this concern. The goal
Randy Smith (Not in Mondays)
2017/05/25 17:40:12
My problem is that I'm not a statistician, though
tbansal1
2017/05/31 06:31:21
Done.
| |
| 550 | |
| 551 if (RequestAttributesAreSet(request->attributes(), kAttributeDelayable)) { | |
| 552 // Notify all in-flight with the new count of in-flight delayable | |
| 553 // requests. | |
| 554 for (RequestSet::const_iterator it = in_flight_requests_.begin(); | |
| 555 it != in_flight_requests_.end(); ++it) { | |
| 556 (*it)->UpdateDelayableRequestsInFlight(in_flight_delayable_count_); | |
| 557 } | |
| 558 } | |
| 559 | |
| 560 if (RequestAttributesAreSet(request->attributes(), | |
| 561 kAttributeLayoutBlocking) || | |
| 562 !RequestAttributesAreSet(request->attributes(), kAttributeDelayable)) { | |
| 563 // |request| is either a layout blocking or a non-delayable request. | |
| 564 request->UpdateDelayableRequestsInFlight(in_flight_delayable_count_); | |
| 565 } | |
| 500 } | 566 } |
| 501 | 567 |
| 502 void EraseInFlightRequest(ScheduledResourceRequest* request) { | 568 void EraseInFlightRequest(ScheduledResourceRequest* request) { |
| 503 size_t erased = in_flight_requests_.erase(request); | 569 size_t erased = in_flight_requests_.erase(request); |
| 504 DCHECK_EQ(1u, erased); | 570 DCHECK_EQ(1u, erased); |
| 505 // Clear any special state that we were tracking for this request. | 571 // Clear any special state that we were tracking for this request. |
| 506 SetRequestAttributes(request, kAttributeNone); | 572 SetRequestAttributes(request, kAttributeNone); |
| 573 RecordRequestCountMetrics(); | |
| 507 } | 574 } |
| 508 | 575 |
| 509 void ClearInFlightRequests() { | 576 void ClearInFlightRequests() { |
| 510 in_flight_requests_.clear(); | 577 in_flight_requests_.clear(); |
| 511 in_flight_delayable_count_ = 0; | 578 in_flight_delayable_count_ = 0; |
| 512 total_layout_blocking_count_ = 0; | 579 total_layout_blocking_count_ = 0; |
| 580 RecordRequestCountMetrics(); | |
| 513 } | 581 } |
| 514 | 582 |
| 515 size_t CountRequestsWithAttributes( | 583 size_t CountRequestsWithAttributes( |
| 516 const RequestAttributes attributes, | 584 const RequestAttributes attributes, |
| 517 ScheduledResourceRequest* current_request) { | 585 ScheduledResourceRequest* current_request) { |
| 518 size_t matching_request_count = 0; | 586 size_t matching_request_count = 0; |
| 519 for (RequestSet::const_iterator it = in_flight_requests_.begin(); | 587 for (RequestSet::const_iterator it = in_flight_requests_.begin(); |
| 520 it != in_flight_requests_.end(); ++it) { | 588 it != in_flight_requests_.end(); ++it) { |
| 521 if (RequestAttributesAreSet((*it)->attributes(), attributes)) | 589 if (RequestAttributesAreSet((*it)->attributes(), attributes)) |
| 522 matching_request_count++; | 590 matching_request_count++; |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 } | 1161 } |
| 1094 ReprioritizeRequest(request, new_priority, current_intra_priority); | 1162 ReprioritizeRequest(request, new_priority, current_intra_priority); |
| 1095 } | 1163 } |
| 1096 | 1164 |
| 1097 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 1165 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 1098 int child_id, int route_id) { | 1166 int child_id, int route_id) { |
| 1099 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 1167 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 1100 } | 1168 } |
| 1101 | 1169 |
| 1102 } // namespace content | 1170 } // namespace content |
| OLD | NEW |