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

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: temp Created 3 years, 8 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 22 matching lines...) Expand all
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 url_requests_(new std::set<const URLRequest*>),
52 enable_brotli_(false), 53 enable_brotli_(false),
53 check_cleartext_permitted_(false), 54 check_cleartext_permitted_(false),
54 name_(nullptr) { 55 name_(nullptr),
56 largest_outstanding_requests_count_seen_(0) {
55 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 57 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
56 this, "URLRequestContext", base::ThreadTaskRunnerHandle::Get()); 58 this, "URLRequestContext", base::ThreadTaskRunnerHandle::Get());
57 } 59 }
58 60
59 URLRequestContext::~URLRequestContext() { 61 URLRequestContext::~URLRequestContext() {
60 AssertNoURLRequests(); 62 AssertNoURLRequests();
61 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 63 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
62 this); 64 this);
63 } 65 }
64 66
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 NetworkTrafficAnnotationTag traffic_annotation) const { 117 NetworkTrafficAnnotationTag traffic_annotation) const {
116 // |traffic_annotation| is just a tag that is extracted during static 118 // |traffic_annotation| is just a tag that is extracted during static
117 // code analysis and can be ignored here. 119 // code analysis and can be ignored here.
118 return CreateRequest(url, priority, delegate); 120 return CreateRequest(url, priority, delegate);
119 } 121 }
120 122
121 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { 123 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
122 cookie_store_ = cookie_store; 124 cookie_store_ = cookie_store;
123 } 125 }
124 126
127 void URLRequestContext::InsertURLRequest(const URLRequest* request) {
128 url_requests_->insert(request);
129 if (url_requests_->size() > largest_outstanding_requests_count_seen_) {
130 largest_outstanding_requests_count_seen_ = url_requests_->size();
xunjieli 2017/04/25 21:21:20 Matt: sorry, I might be missing something. How do
mmenke 2017/04/25 21:50:48 I assume this doesn't build because InsertURLReque
131 UMA_HISTOGRAM_COUNTS_1M("Net.URLRequestContext.OutstandingRequests",
132 largest_outstanding_requests_count_seen_);
133 }
134 }
135
136 void URLRequestContext::RemoveURLRequest(const URLRequest* request) {
137 DCHECK_EQ(1u, url_requests_->count(request));
138 url_requests_->erase(request);
139 }
140
125 void URLRequestContext::AssertNoURLRequests() const { 141 void URLRequestContext::AssertNoURLRequests() const {
126 int num_requests = url_requests_->size(); 142 int num_requests = url_requests_->size();
127 if (num_requests != 0) { 143 if (num_requests != 0) {
128 // We're leaking URLRequests :( Dump the URL of the first one and record how 144 // 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. 145 // many we leaked so we have an idea of how bad it is.
130 char url_buf[128]; 146 char url_buf[128];
131 const URLRequest* request = *url_requests_->begin(); 147 const URLRequest* request = *url_requests_->begin();
132 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf)); 148 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf));
133 int load_flags = request->load_flags(); 149 int load_flags = request->load_flags();
134 base::debug::Alias(url_buf); 150 base::debug::Alias(url_buf);
(...skipping 28 matching lines...) Expand all
163 HttpCache* http_cache = transaction_factory->GetCache(); 179 HttpCache* http_cache = transaction_factory->GetCache();
164 if (http_cache) 180 if (http_cache)
165 http_cache->DumpMemoryStats(pmd, dump->absolute_name()); 181 http_cache->DumpMemoryStats(pmd, dump->absolute_name());
166 } 182 }
167 if (sdch_manager_) 183 if (sdch_manager_)
168 sdch_manager_->DumpMemoryStats(pmd, dump_name); 184 sdch_manager_->DumpMemoryStats(pmd, dump_name);
169 return true; 185 return true;
170 } 186 }
171 187
172 } // namespace net 188 } // 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