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

Side by Side Diff: net/url_request/url_request_context.cc

Issue 2837313002: Add UMA to track the number of live URLRequests. (Closed)
Patch Set: use mutable Created 3 years, 7 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
« no previous file with comments | « net/url_request/url_request_context.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "net/url_request/url_request_context.h" 5 #include "net/url_request/url_request_context.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/trace_event/memory_allocator_dump.h" 16 #include "base/trace_event/memory_allocator_dump.h"
16 #include "base/trace_event/memory_dump_manager.h" 17 #include "base/trace_event/memory_dump_manager.h"
17 #include "base/trace_event/memory_dump_request_args.h" 18 #include "base/trace_event/memory_dump_request_args.h"
18 #include "base/trace_event/process_memory_dump.h" 19 #include "base/trace_event/process_memory_dump.h"
19 #include "net/base/sdch_manager.h" 20 #include "net/base/sdch_manager.h"
20 #include "net/cookies/cookie_store.h" 21 #include "net/cookies/cookie_store.h"
21 #include "net/dns/host_resolver.h" 22 #include "net/dns/host_resolver.h"
(...skipping 19 matching lines...) Expand all
41 transport_security_state_(nullptr), 42 transport_security_state_(nullptr),
42 cert_transparency_verifier_(nullptr), 43 cert_transparency_verifier_(nullptr),
43 ct_policy_enforcer_(nullptr), 44 ct_policy_enforcer_(nullptr),
44 http_transaction_factory_(nullptr), 45 http_transaction_factory_(nullptr),
45 job_factory_(nullptr), 46 job_factory_(nullptr),
46 throttler_manager_(nullptr), 47 throttler_manager_(nullptr),
47 backoff_manager_(nullptr), 48 backoff_manager_(nullptr),
48 sdch_manager_(nullptr), 49 sdch_manager_(nullptr),
49 network_quality_estimator_(nullptr), 50 network_quality_estimator_(nullptr),
50 reporting_service_(nullptr), 51 reporting_service_(nullptr),
51 url_requests_(new std::set<const URLRequest*>),
52 enable_brotli_(false), 52 enable_brotli_(false),
53 check_cleartext_permitted_(false), 53 check_cleartext_permitted_(false),
54 name_(nullptr) { 54 name_(nullptr),
55 largest_outstanding_requests_count_seen_(0) {
55 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 56 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
56 this, "URLRequestContext", base::ThreadTaskRunnerHandle::Get()); 57 this, "URLRequestContext", base::ThreadTaskRunnerHandle::Get());
57 } 58 }
58 59
59 URLRequestContext::~URLRequestContext() { 60 URLRequestContext::~URLRequestContext() {
60 AssertNoURLRequests(); 61 AssertNoURLRequests();
61 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 62 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
62 this); 63 this);
63 } 64 }
64 65
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 NetworkTrafficAnnotationTag traffic_annotation) const { 116 NetworkTrafficAnnotationTag traffic_annotation) const {
116 // |traffic_annotation| is just a tag that is extracted during static 117 // |traffic_annotation| is just a tag that is extracted during static
117 // code analysis and can be ignored here. 118 // code analysis and can be ignored here.
118 return CreateRequest(url, priority, delegate); 119 return CreateRequest(url, priority, delegate);
119 } 120 }
120 121
121 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { 122 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
122 cookie_store_ = cookie_store; 123 cookie_store_ = cookie_store;
123 } 124 }
124 125
126 void URLRequestContext::InsertURLRequest(const URLRequest* request) const {
127 url_requests_.insert(request);
128 if (url_requests_.size() > largest_outstanding_requests_count_seen_) {
129 largest_outstanding_requests_count_seen_ = url_requests_.size();
130 UMA_HISTOGRAM_COUNTS_1M("Net.URLRequestContext.OutstandingRequests",
131 largest_outstanding_requests_count_seen_);
132 }
133 }
134
135 void URLRequestContext::RemoveURLRequest(const URLRequest* request) const {
136 DCHECK_EQ(1u, url_requests_.count(request));
137 url_requests_.erase(request);
138 }
139
125 void URLRequestContext::AssertNoURLRequests() const { 140 void URLRequestContext::AssertNoURLRequests() const {
126 int num_requests = url_requests_->size(); 141 int num_requests = url_requests_.size();
127 if (num_requests != 0) { 142 if (num_requests != 0) {
128 // We're leaking URLRequests :( Dump the URL of the first one and record how 143 // We're leaking URLRequests :( Dump the URL of the first one and record how
129 // many we leaked so we have an idea of how bad it is. 144 // many we leaked so we have an idea of how bad it is.
130 char url_buf[128]; 145 char url_buf[128];
131 const URLRequest* request = *url_requests_->begin(); 146 const URLRequest* request = *url_requests_.begin();
132 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf)); 147 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf));
133 int load_flags = request->load_flags(); 148 int load_flags = request->load_flags();
134 base::debug::Alias(url_buf); 149 base::debug::Alias(url_buf);
135 base::debug::Alias(&num_requests); 150 base::debug::Alias(&num_requests);
136 base::debug::Alias(&load_flags); 151 base::debug::Alias(&load_flags);
137 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: " 152 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: "
138 << request->url().spec().c_str() << "."; 153 << request->url().spec().c_str() << ".";
139 } 154 }
140 } 155 }
141 156
142 bool URLRequestContext::OnMemoryDump( 157 bool URLRequestContext::OnMemoryDump(
143 const base::trace_event::MemoryDumpArgs& args, 158 const base::trace_event::MemoryDumpArgs& args,
144 base::trace_event::ProcessMemoryDump* pmd) { 159 base::trace_event::ProcessMemoryDump* pmd) {
145 if (!name_) 160 if (!name_)
146 name_ = "unknown"; 161 name_ = "unknown";
147 162
148 SSLClientSocketImpl::DumpSSLClientSessionMemoryStats(pmd); 163 SSLClientSocketImpl::DumpSSLClientSessionMemoryStats(pmd);
149 164
150 std::string dump_name = 165 std::string dump_name =
151 base::StringPrintf("net/url_request_context/%s/0x%" PRIxPTR, name_, 166 base::StringPrintf("net/url_request_context/%s/0x%" PRIxPTR, name_,
152 reinterpret_cast<uintptr_t>(this)); 167 reinterpret_cast<uintptr_t>(this));
153 base::trace_event::MemoryAllocatorDump* dump = 168 base::trace_event::MemoryAllocatorDump* dump =
154 pmd->CreateAllocatorDump(dump_name); 169 pmd->CreateAllocatorDump(dump_name);
155 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount, 170 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount,
156 base::trace_event::MemoryAllocatorDump::kUnitsObjects, 171 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
157 url_requests_->size()); 172 url_requests_.size());
158 HttpTransactionFactory* transaction_factory = http_transaction_factory(); 173 HttpTransactionFactory* transaction_factory = http_transaction_factory();
159 if (transaction_factory) { 174 if (transaction_factory) {
160 HttpNetworkSession* network_session = transaction_factory->GetSession(); 175 HttpNetworkSession* network_session = transaction_factory->GetSession();
161 if (network_session) 176 if (network_session)
162 network_session->DumpMemoryStats(pmd, dump->absolute_name()); 177 network_session->DumpMemoryStats(pmd, dump->absolute_name());
163 HttpCache* http_cache = transaction_factory->GetCache(); 178 HttpCache* http_cache = transaction_factory->GetCache();
164 if (http_cache) 179 if (http_cache)
165 http_cache->DumpMemoryStats(pmd, dump->absolute_name()); 180 http_cache->DumpMemoryStats(pmd, dump->absolute_name());
166 } 181 }
167 if (sdch_manager_) 182 if (sdch_manager_)
168 sdch_manager_->DumpMemoryStats(pmd, dump_name); 183 sdch_manager_->DumpMemoryStats(pmd, dump_name);
169 return true; 184 return true;
170 } 185 }
171 186
172 } // namespace net 187 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_context.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698