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

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: jwd@ comments 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 static bool did_init = false; 66 static bool did_init = false;
67 if (did_init) 67 if (did_init)
68 return; 68 return;
69 did_init = true; 69 did_init = true;
70 70
71 GetNumericArg("resource-buffer-size", &kBufferSize); 71 GetNumericArg("resource-buffer-size", &kBufferSize);
72 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize); 72 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize);
73 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize); 73 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize);
74 } 74 }
75 75
76 // This enum is used for logging a histogram and should not be reordered.
77 enum ExpectedContentSizeResult {
78 EQ_RESPONSE_BODY = 0,
79 EQ_RESPONSE_BODY_GT_EQ_BUFFER_SIZE = 1,
80 GT_EQ_BUFFER_SIZE = 2,
81 LT_RESPONSE_BODY = 3,
82 GT_RESPONSE_BODY = 4,
83 UNKNOWN = 5,
84 EXPECTED_CONTENT_MAX,
85 };
86
76 } // namespace 87 } // namespace
77 88
78 // Used when kOptimizeLoadingIPCForSmallResources is enabled. 89 // Used when kOptimizeLoadingIPCForSmallResources is enabled.
79 // The instance hooks the buffer allocation of AsyncResourceHandler, and 90 // The instance hooks the buffer allocation of AsyncResourceHandler, and
80 // determine if we should use SharedMemory or should inline the data into 91 // determine if we should use SharedMemory or should inline the data into
81 // the IPC message. 92 // the IPC message.
82 class AsyncResourceHandler::InliningHelper { 93 class AsyncResourceHandler::InliningHelper {
83 public: 94 public:
84 95
85 InliningHelper() {} 96 InliningHelper() {}
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 public: 196 public:
186 DependentIOBuffer(ResourceBuffer* backing, char* memory) 197 DependentIOBuffer(ResourceBuffer* backing, char* memory)
187 : net::WrappedIOBuffer(memory), 198 : net::WrappedIOBuffer(memory),
188 backing_(backing) { 199 backing_(backing) {
189 } 200 }
190 private: 201 private:
191 ~DependentIOBuffer() override {} 202 ~DependentIOBuffer() override {}
192 scoped_refptr<ResourceBuffer> backing_; 203 scoped_refptr<ResourceBuffer> backing_;
193 }; 204 };
194 205
195 AsyncResourceHandler::AsyncResourceHandler( 206 AsyncResourceHandler::AsyncResourceHandler(net::URLRequest* request,
196 net::URLRequest* request, 207 ResourceDispatcherHostImpl* rdh)
197 ResourceDispatcherHostImpl* rdh)
198 : ResourceHandler(request), 208 : ResourceHandler(request),
199 ResourceMessageDelegate(request), 209 ResourceMessageDelegate(request),
200 rdh_(rdh), 210 rdh_(rdh),
201 pending_data_count_(0), 211 pending_data_count_(0),
202 allocation_size_(0), 212 allocation_size_(0),
213 total_read_body_bytes_(0),
203 did_defer_(false), 214 did_defer_(false),
204 has_checked_for_sufficient_resources_(false), 215 has_checked_for_sufficient_resources_(false),
205 sent_received_response_msg_(false), 216 sent_received_response_msg_(false),
206 sent_data_buffer_msg_(false), 217 sent_data_buffer_msg_(false),
207 inlining_helper_(new InliningHelper), 218 inlining_helper_(new InliningHelper),
208 reported_transfer_size_(0) { 219 reported_transfer_size_(0) {
209 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); 220 DCHECK(GetRequestInfo()->requester_info()->IsRenderer());
210 InitializeResourceBufferConstants(); 221 InitializeResourceBufferConstants();
211 } 222 }
212 223
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 first_chunk_read_ = true; 400 first_chunk_read_ = true;
390 401
391 // Return early if InliningHelper handled the received data. 402 // Return early if InliningHelper handled the received data.
392 if (inlining_helper_->SendInlinedDataIfApplicable( 403 if (inlining_helper_->SendInlinedDataIfApplicable(
393 bytes_read, encoded_data_length, filter, 404 bytes_read, encoded_data_length, filter,
394 GetRequestID())) 405 GetRequestID()))
395 return true; 406 return true;
396 407
397 buffer_->ShrinkLastAllocation(bytes_read); 408 buffer_->ShrinkLastAllocation(bytes_read);
398 409
410 total_read_body_bytes_ += bytes_read;
411
399 if (!sent_data_buffer_msg_) { 412 if (!sent_data_buffer_msg_) {
400 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( 413 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle(
401 buffer_->GetSharedMemory().handle()); 414 buffer_->GetSharedMemory().handle());
402 if (!base::SharedMemory::IsHandleValid(handle)) 415 if (!base::SharedMemory::IsHandleValid(handle))
403 return false; 416 return false;
404 filter->Send(new ResourceMsg_SetDataBuffer( 417 filter->Send(new ResourceMsg_SetDataBuffer(
405 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), 418 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(),
406 filter->peer_pid())); 419 filter->peer_pid()));
407 sent_data_buffer_msg_ = true; 420 sent_data_buffer_msg_ = true;
408 } 421 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 UMA_HISTOGRAM_CUSTOM_COUNTS( 558 UMA_HISTOGRAM_CUSTOM_COUNTS(
546 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", 559 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB",
547 elapsed_time, 1, 100000, 100); 560 elapsed_time, 1, 100000, 100);
548 } else { 561 } else {
549 UMA_HISTOGRAM_CUSTOM_COUNTS( 562 UMA_HISTOGRAM_CUSTOM_COUNTS(
550 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", 563 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB",
551 elapsed_time, 1, 100000, 100); 564 elapsed_time, 1, 100000, 100);
552 } 565 }
553 566
554 inlining_helper_->RecordHistogram(elapsed_time); 567 inlining_helper_->RecordHistogram(elapsed_time);
568
569 // Record if content size was known in advance.
570 int64_t expected_content_size = request()->GetExpectedContentSize();
571 ExpectedContentSizeResult expected_content_size_result =
572 ExpectedContentSizeResult::UNKNOWN;
573 if (expected_content_size >= 0) {
574 // Compare response body size to expected content size.
575 if (expected_content_size == total_read_body_bytes_ &&
576 expected_content_size >= kBufferSize) {
577 expected_content_size_result =
578 ExpectedContentSizeResult::EQ_RESPONSE_BODY_GT_EQ_BUFFER_SIZE;
579 } else if (expected_content_size >= kBufferSize) {
580 expected_content_size_result =
581 ExpectedContentSizeResult::GT_EQ_BUFFER_SIZE;
582 } else if (expected_content_size == total_read_body_bytes_) {
583 expected_content_size_result =
584 ExpectedContentSizeResult::EQ_RESPONSE_BODY;
585 } else if (expected_content_size < total_read_body_bytes_) {
586 expected_content_size_result =
587 ExpectedContentSizeResult::LT_RESPONSE_BODY;
588 } else {
589 expected_content_size_result =
590 ExpectedContentSizeResult::GT_RESPONSE_BODY;
591 }
592 }
593 UMA_HISTOGRAM_ENUMERATION("Net.ResourceLoader.ExpectedContentSizeResult",
594 expected_content_size_result,
595 ExpectedContentSizeResult::EXPECTED_CONTENT_MAX);
555 } 596 }
556 597
557 void AsyncResourceHandler::SendUploadProgress( 598 void AsyncResourceHandler::SendUploadProgress(
558 const net::UploadProgress& progress) { 599 const net::UploadProgress& progress) {
559 ResourceMessageFilter* filter = GetFilter(); 600 ResourceMessageFilter* filter = GetFilter();
560 if (!filter) 601 if (!filter)
561 return; 602 return;
562 filter->Send(new ResourceMsg_UploadProgress( 603 filter->Send(new ResourceMsg_UploadProgress(
563 GetRequestID(), progress.position(), progress.size())); 604 GetRequestID(), progress.position(), progress.size()));
564 } 605 }
565 606
566 } // namespace content 607 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698