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

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

Issue 2624123002: Add UMA histograms to AsyncResourceHandler to track content size. (Closed)
Patch Set: Created 3 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 "content/browser/loader/async_resource_handler.h" 5 #include "content/browser/loader/async_resource_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 static bool did_init = false; 65 static bool did_init = false;
66 if (did_init) 66 if (did_init)
67 return; 67 return;
68 did_init = true; 68 did_init = true;
69 69
70 GetNumericArg("resource-buffer-size", &kBufferSize); 70 GetNumericArg("resource-buffer-size", &kBufferSize);
71 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize); 71 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize);
72 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize); 72 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize);
73 } 73 }
74 74
75 enum ExpectedContentSize {
mmenke 2017/01/11 20:25:19 "enum class" should generally be preferred to just
maksims (do not use this acc) 2017/01/12 09:03:03 invalid operands to binary expression ('content::(
mmenke 2017/01/12 18:04:10 Ah, right, good point.
76 CORRESPONDS_TO_RESPONSE_BODY = 0,
mmenke 2017/01/11 20:25:20 EQ_RESPONSE_BODY?
maksims (do not use this acc) 2017/01/13 12:05:18 Done.
77 LT_RESPONSE_BODY = 1,
78 MT_RESPONSE_BODY = 2,
79 EXPECTED_CONTENT_SIZE,
mmenke 2017/01/11 20:25:19 nit: EXPECTED_CONTENT_MAX is more common
maksims (do not use this acc) 2017/01/13 12:05:17 Done.
80 };
81
75 } // namespace 82 } // namespace
76 83
77 // Used when kOptimizeLoadingIPCForSmallResources is enabled. 84 // Used when kOptimizeLoadingIPCForSmallResources is enabled.
78 // The instance hooks the buffer allocation of AsyncResourceHandler, and 85 // The instance hooks the buffer allocation of AsyncResourceHandler, and
79 // determine if we should use SharedMemory or should inline the data into 86 // determine if we should use SharedMemory or should inline the data into
80 // the IPC message. 87 // the IPC message.
81 class AsyncResourceHandler::InliningHelper { 88 class AsyncResourceHandler::InliningHelper {
82 public: 89 public:
83 90
84 InliningHelper() {} 91 InliningHelper() {}
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 }; 199 };
193 200
194 AsyncResourceHandler::AsyncResourceHandler( 201 AsyncResourceHandler::AsyncResourceHandler(
195 net::URLRequest* request, 202 net::URLRequest* request,
196 ResourceDispatcherHostImpl* rdh) 203 ResourceDispatcherHostImpl* rdh)
197 : ResourceHandler(request), 204 : ResourceHandler(request),
198 ResourceMessageDelegate(request), 205 ResourceMessageDelegate(request),
199 rdh_(rdh), 206 rdh_(rdh),
200 pending_data_count_(0), 207 pending_data_count_(0),
201 allocation_size_(0), 208 allocation_size_(0),
209 total_read_bytes_(0),
202 did_defer_(false), 210 did_defer_(false),
203 has_checked_for_sufficient_resources_(false), 211 has_checked_for_sufficient_resources_(false),
204 sent_received_response_msg_(false), 212 sent_received_response_msg_(false),
205 sent_data_buffer_msg_(false), 213 sent_data_buffer_msg_(false),
206 inlining_helper_(new InliningHelper), 214 inlining_helper_(new InliningHelper),
207 reported_transfer_size_(0) { 215 reported_transfer_size_(0) {
208 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); 216 DCHECK(GetRequestInfo()->requester_info()->IsRenderer());
209 InitializeResourceBufferConstants(); 217 InitializeResourceBufferConstants();
210 } 218 }
211 219
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 first_chunk_read_ = true; 396 first_chunk_read_ = true;
389 397
390 // Return early if InliningHelper handled the received data. 398 // Return early if InliningHelper handled the received data.
391 if (inlining_helper_->SendInlinedDataIfApplicable( 399 if (inlining_helper_->SendInlinedDataIfApplicable(
392 bytes_read, encoded_data_length, filter, 400 bytes_read, encoded_data_length, filter,
393 GetRequestID())) 401 GetRequestID()))
394 return true; 402 return true;
395 403
396 buffer_->ShrinkLastAllocation(bytes_read); 404 buffer_->ShrinkLastAllocation(bytes_read);
397 405
406 total_read_bytes_ += bytes_read;
407
398 if (!sent_data_buffer_msg_) { 408 if (!sent_data_buffer_msg_) {
399 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( 409 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle(
400 buffer_->GetSharedMemory().handle()); 410 buffer_->GetSharedMemory().handle());
401 if (!base::SharedMemory::IsHandleValid(handle)) 411 if (!base::SharedMemory::IsHandleValid(handle))
402 return false; 412 return false;
403 filter->Send(new ResourceMsg_SetDataBuffer( 413 filter->Send(new ResourceMsg_SetDataBuffer(
404 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), 414 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(),
405 filter->peer_pid())); 415 filter->peer_pid()));
406 sent_data_buffer_msg_ = true; 416 sent_data_buffer_msg_ = true;
407 } 417 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 UMA_HISTOGRAM_CUSTOM_COUNTS( 554 UMA_HISTOGRAM_CUSTOM_COUNTS(
545 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", 555 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB",
546 elapsed_time, 1, 100000, 100); 556 elapsed_time, 1, 100000, 100);
547 } else { 557 } else {
548 UMA_HISTOGRAM_CUSTOM_COUNTS( 558 UMA_HISTOGRAM_CUSTOM_COUNTS(
549 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", 559 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB",
550 elapsed_time, 1, 100000, 100); 560 elapsed_time, 1, 100000, 100);
551 } 561 }
552 562
553 inlining_helper_->RecordHistogram(elapsed_time); 563 inlining_helper_->RecordHistogram(elapsed_time);
564
565 // Record if content size is known in advance.
mmenke 2017/01/11 20:25:20 nit: is -> was (Since this is recorded at the end
maksims (do not use this acc) 2017/01/13 12:05:18 Done.
566 int64_t expected_content_size = request()->GetExpectedContentSize();
567 if (expected_content_size > 0) {
mmenke 2017/01/11 20:25:19 nit: >= 0 (We use -1 to mean unknown, 0 means the
maksims (do not use this acc) 2017/01/13 12:05:17 Done.
568 UMA_HISTOGRAM_BOOLEAN(
569 "Net.ResourceLoader.ExpectedContentSize.IsKnown",
570 true);
571 // Compare response body size to expected content size.
572 if (expected_content_size == total_read_bytes_) {
mmenke 2017/01/11 20:25:19 Should we separate out those where expected_conten
maksims (do not use this acc) 2017/01/12 09:03:02 Do you think I should add another enum entry, whic
mmenke 2017/01/12 18:04:10 I'm fine with that. I'm not sure how much it gets
maksims (do not use this acc) 2017/01/13 12:05:17 Done.
573 UMA_HISTOGRAM_ENUMERATION(
mmenke 2017/01/11 20:25:19 These UMA_HISTOGRAM_ENUMERATION are deceivingly ex
maksims (do not use this acc) 2017/01/13 12:05:18 I see. Do you think I should use something else?
mmenke 2017/01/13 16:01:36 No, but you should only have one instance of "UMA_
574 "Net.ResourceLoader.ExpectedContentSize.CorrespondsBodySize",
575 ExpectedContentSize::CORRESPONDS_TO_RESPONSE_BODY,
576 ExpectedContentSize::EXPECTED_CONTENT_SIZE);
577 } else if (expected_content_size < total_read_bytes_) {
578 UMA_HISTOGRAM_ENUMERATION(
579 "Net.ResourceLoader.ExpectedContentSize.CorrespondsBodySize",
580 ExpectedContentSize::LT_RESPONSE_BODY,
581 ExpectedContentSize::EXPECTED_CONTENT_SIZE);
582 } else {
583 UMA_HISTOGRAM_ENUMERATION(
584 "Net.ResourceLoader.ExpectedContentSize.CorrespondsBodySize",
585 ExpectedContentSize::MT_RESPONSE_BODY,
586 ExpectedContentSize::EXPECTED_CONTENT_SIZE);
587 }
588 } else {
589 UMA_HISTOGRAM_BOOLEAN(
590 "Net.ResourceLoader.ExpectedContentSize.IsKnown",
591 false);
mmenke 2017/01/11 20:25:19 Do we really need two histograms? Seems like we c
maksims (do not use this acc) 2017/01/12 09:03:03 sounds reasonable.
maksims (do not use this acc) 2017/01/13 12:05:17 Done.
592 }
593
594 // Record how many times total size of read body is less or more/eq than
595 // buffer.
596 UMA_HISTOGRAM_BOOLEAN(
597 "Net.ResourceLoader.TotalBodySize.LT_AsyncHandlerBufferSize",
598 total_read_bytes_ < kBufferSize);
mmenke 2017/01/11 20:25:20 I don't think we need this - can just add up the v
maksims (do not use this acc) 2017/01/12 09:03:02 But we'll loose data, which tells us how accurate
mmenke 2017/01/12 18:04:10 Sorry, I wasn't clear. I mean keep them as separa
599 total_read_bytes_ = 0;
554 } 600 }
555 601
556 void AsyncResourceHandler::SendUploadProgress(int64_t current_position, 602 void AsyncResourceHandler::SendUploadProgress(int64_t current_position,
557 int64_t total_size) { 603 int64_t total_size) {
558 ResourceMessageFilter* filter = GetFilter(); 604 ResourceMessageFilter* filter = GetFilter();
559 if (!filter) 605 if (!filter)
560 return; 606 return;
561 filter->Send(new ResourceMsg_UploadProgress( 607 filter->Send(new ResourceMsg_UploadProgress(
562 GetRequestID(), current_position, total_size)); 608 GetRequestID(), current_position, total_size));
563 } 609 }
564 610
565 } // namespace content 611 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698