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

Side by Side Diff: net/base/host_resolver_impl.cc

Issue 11065052: [net] Add AsyncDNS.TTL histogram. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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 | Annotate | Revision Log
« net/base/host_cache.h ('K') | « net/base/host_cache.cc ('k') | no next file » | 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/base/host_resolver_impl.h" 5 #include "net/base/host_resolver_impl.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <Winsock2.h> 8 #include <Winsock2.h>
9 #elif defined(OS_POSIX) 9 #elif defined(OS_POSIX)
10 #include <netdb.h> 10 #include <netdb.h>
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 198 }
199 } else { 199 } else {
200 if (speculative) { 200 if (speculative) {
201 DNS_HISTOGRAM("DNS.TotalTime_speculative", duration); 201 DNS_HISTOGRAM("DNS.TotalTime_speculative", duration);
202 } else { 202 } else {
203 DNS_HISTOGRAM("DNS.TotalTime", duration); 203 DNS_HISTOGRAM("DNS.TotalTime", duration);
204 } 204 }
205 } 205 }
206 } 206 }
207 207
208 void RecordTTL(base::TimeDelta ttl) {
209 UMA_HISTOGRAM_CUSTOM_COUNTS("AsyncDNS.TTL", ttl.InSeconds(), 1, 86400, 100);
210 }
211
208 //----------------------------------------------------------------------------- 212 //-----------------------------------------------------------------------------
209 213
210 // Wraps call to SystemHostResolverProc as an instance of HostResolverProc. 214 // Wraps call to SystemHostResolverProc as an instance of HostResolverProc.
211 // TODO(szym): This should probably be declared in host_resolver_proc.h. 215 // TODO(szym): This should probably be declared in host_resolver_proc.h.
212 class CallSystemHostResolverProc : public HostResolverProc { 216 class CallSystemHostResolverProc : public HostResolverProc {
213 public: 217 public:
214 CallSystemHostResolverProc() : HostResolverProc(NULL) {} 218 CallSystemHostResolverProc() : HostResolverProc(NULL) {}
215 virtual int Resolve(const std::string& hostname, 219 virtual int Resolve(const std::string& hostname,
216 AddressFamily address_family, 220 AddressFamily address_family,
217 HostResolverFlags host_resolver_flags, 221 HostResolverFlags host_resolver_flags,
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_PROC_SUCCESS); 1461 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_PROC_SUCCESS);
1458 } 1462 }
1459 UMA_HISTOGRAM_CUSTOM_ENUMERATION("AsyncDNS.ResolveError", 1463 UMA_HISTOGRAM_CUSTOM_ENUMERATION("AsyncDNS.ResolveError",
1460 std::abs(dns_task_error_), 1464 std::abs(dns_task_error_),
1461 GetAllErrorCodesForUma()); 1465 GetAllErrorCodesForUma());
1462 } else { 1466 } else {
1463 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_FAIL); 1467 UmaAsyncDnsResolveStatus(RESOLVE_STATUS_FAIL);
1464 } 1468 }
1465 } 1469 }
1466 1470
1467 base::TimeDelta ttl = base::TimeDelta::FromSeconds( 1471 CompleteRequests(net_error, addr_list, base::TimeDelta::FromSeconds(-1));
cbentzel 2012/10/11 18:27:30 At the point that the kNegativeCacheEntry/kCacheEn
1468 kNegativeCacheEntryTTLSeconds);
1469 if (net_error == OK)
1470 ttl = base::TimeDelta::FromSeconds(kCacheEntryTTLSeconds);
1471
1472 CompleteRequests(net_error, addr_list, ttl);
1473 } 1472 }
1474 1473
1475 void StartDnsTask() { 1474 void StartDnsTask() {
1476 DCHECK(resolver_->HaveDnsConfig()); 1475 DCHECK(resolver_->HaveDnsConfig());
1477 dns_task_.reset(new DnsTask( 1476 dns_task_.reset(new DnsTask(
1478 resolver_->dns_client_.get(), 1477 resolver_->dns_client_.get(),
1479 key_, 1478 key_,
1480 base::Bind(&Job::OnDnsTaskComplete, base::Unretained(this)), 1479 base::Bind(&Job::OnDnsTaskComplete, base::Unretained(this)),
1481 net_log_)); 1480 net_log_));
1482 1481
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 if (!info.allow_cached_response() || !cache_.get()) 1950 if (!info.allow_cached_response() || !cache_.get())
1952 return false; 1951 return false;
1953 1952
1954 const HostCache::Entry* cache_entry = cache_->Lookup( 1953 const HostCache::Entry* cache_entry = cache_->Lookup(
1955 key, base::TimeTicks::Now()); 1954 key, base::TimeTicks::Now());
1956 if (!cache_entry) 1955 if (!cache_entry)
1957 return false; 1956 return false;
1958 1957
1959 *net_error = cache_entry->error; 1958 *net_error = cache_entry->error;
1960 if (*net_error == OK) { 1959 if (*net_error == OK) {
1960 if (cache_entry->original_ttl >= base::TimeDelta())
1961 RecordTTL(cache_entry->original_ttl);
1961 *addresses = cache_entry->addrlist; 1962 *addresses = cache_entry->addrlist;
1962 EnsurePortOnAddressList(info.port(), addresses); 1963 EnsurePortOnAddressList(info.port(), addresses);
1963 } 1964 }
1964 return true; 1965 return true;
1965 } 1966 }
1966 1967
1967 bool HostResolverImpl::ServeFromHosts(const Key& key, 1968 bool HostResolverImpl::ServeFromHosts(const Key& key,
1968 const RequestInfo& info, 1969 const RequestInfo& info,
1969 AddressList* addresses) { 1970 AddressList* addresses) {
1970 DCHECK(addresses); 1971 DCHECK(addresses);
(...skipping 23 matching lines...) Expand all
1994 } 1995 }
1995 1996
1996 *addresses = AddressList::CreateFromIPAddress(it->second, info.port()); 1997 *addresses = AddressList::CreateFromIPAddress(it->second, info.port());
1997 return true; 1998 return true;
1998 } 1999 }
1999 2000
2000 void HostResolverImpl::CacheResult(const Key& key, 2001 void HostResolverImpl::CacheResult(const Key& key,
2001 int net_error, 2002 int net_error,
2002 const AddressList& addr_list, 2003 const AddressList& addr_list,
2003 base::TimeDelta ttl) { 2004 base::TimeDelta ttl) {
2004 if (cache_.get()) 2005 bool have_ttl = (ttl >= base::TimeDelta());
2005 cache_->Set(key, net_error, addr_list, base::TimeTicks::Now(), ttl); 2006 if (!have_ttl) {
2007 if (net_error == OK) {
2008 ttl = base::TimeDelta::FromSeconds(kCacheEntryTTLSeconds);
2009 } else {
2010 ttl = base::TimeDelta::FromSeconds(kNegativeCacheEntryTTLSeconds);
2011 }
2012 }
2013
2014 if (cache_.get()) {
2015 HostCache::Entry* entry = cache_->Set(
2016 key, net_error, addr_list, base::TimeTicks::Now(), ttl);
2017 if (have_ttl) {
2018 RecordTTL(ttl);
2019 entry->original_ttl = ttl;
2020 } else {
2021 entry->original_ttl = base::TimeDelta::FromSeconds(-1);
2022 }
2023 }
2006 } 2024 }
2007 2025
2008 void HostResolverImpl::RemoveJob(Job* job) { 2026 void HostResolverImpl::RemoveJob(Job* job) {
2009 DCHECK(job); 2027 DCHECK(job);
2010 JobMap::iterator it = jobs_.find(job->key()); 2028 JobMap::iterator it = jobs_.find(job->key());
2011 if (it != jobs_.end() && it->second == job) 2029 if (it != jobs_.end() && it->second == job)
2012 jobs_.erase(it); 2030 jobs_.erase(it);
2013 } 2031 }
2014 2032
2015 void HostResolverImpl::DiscardIPv6ProbeJob() { 2033 void HostResolverImpl::DiscardIPv6ProbeJob() {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 // |this| may be deleted inside AbortAllInProgressJobs(). 2164 // |this| may be deleted inside AbortAllInProgressJobs().
2147 if (self) 2165 if (self)
2148 TryServingAllJobsFromHosts(); 2166 TryServingAllJobsFromHosts();
2149 } 2167 }
2150 2168
2151 bool HostResolverImpl::HaveDnsConfig() const { 2169 bool HostResolverImpl::HaveDnsConfig() const {
2152 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); 2170 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL);
2153 } 2171 }
2154 2172
2155 } // namespace net 2173 } // namespace net
OLDNEW
« net/base/host_cache.h ('K') | « net/base/host_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698