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

Side by Side Diff: net/proxy/proxy_service.cc

Issue 1121823004: Add some basic UMA for proxy service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatting. Created 5 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 | « no previous file | 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/proxy/proxy_service.h" 5 #include "net/proxy/proxy_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/metrics/histogram_macros.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
19 #include "base/time/time.h"
18 #include "base/values.h" 20 #include "base/values.h"
19 #include "net/base/completion_callback.h" 21 #include "net/base/completion_callback.h"
20 #include "net/base/load_flags.h" 22 #include "net/base/load_flags.h"
21 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
22 #include "net/base/net_util.h" 24 #include "net/base/net_util.h"
23 #include "net/log/net_log.h" 25 #include "net/log/net_log.h"
24 #include "net/proxy/dhcp_proxy_script_fetcher.h" 26 #include "net/proxy/dhcp_proxy_script_fetcher.h"
25 #include "net/proxy/multi_threaded_proxy_resolver.h" 27 #include "net/proxy/multi_threaded_proxy_resolver.h"
26 #include "net/proxy/network_delegate_error_observer.h" 28 #include "net/proxy/network_delegate_error_observer.h"
27 #include "net/proxy/proxy_config_service_fixed.h" 29 #include "net/proxy/proxy_config_service_fixed.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 ~UnsetProxyConfigService() override {} 356 ~UnsetProxyConfigService() override {}
355 357
356 void AddObserver(Observer* observer) override {} 358 void AddObserver(Observer* observer) override {}
357 void RemoveObserver(Observer* observer) override {} 359 void RemoveObserver(Observer* observer) override {}
358 ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) override { 360 ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) override {
359 return CONFIG_UNSET; 361 return CONFIG_UNSET;
360 } 362 }
361 }; 363 };
362 #endif 364 #endif
363 365
366 void RecordResolveProxyTime(TimeTicks start_time) {
367 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.ResolveProxyTime",
368 TimeTicks::Now() - start_time,
369 base::TimeDelta::FromMicroseconds(100),
370 base::TimeDelta::FromSeconds(20), 50);
371 }
372
373 void ResolveProxyCallbackHelper(TimeTicks start_time,
374 const CompletionCallback& callback,
375 int result) {
376 RecordResolveProxyTime(start_time);
377 callback.Run(result);
378 }
379
364 } // namespace 380 } // namespace
365 381
366 // ProxyService::InitProxyResolver -------------------------------------------- 382 // ProxyService::InitProxyResolver --------------------------------------------
367 383
368 // This glues together two asynchronous steps: 384 // This glues together two asynchronous steps:
369 // (1) ProxyScriptDecider -- try to fetch/validate a sequence of PAC scripts 385 // (1) ProxyScriptDecider -- try to fetch/validate a sequence of PAC scripts
370 // to figure out what we should configure against. 386 // to figure out what we should configure against.
371 // (2) Feed the fetched PAC script into the ProxyResolver. 387 // (2) Feed the fetched PAC script into the ProxyResolver.
372 // 388 //
373 // InitProxyResolver is a single-use class which encapsulates cancellation as 389 // InitProxyResolver is a single-use class which encapsulates cancellation as
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 bool is_started() const { 836 bool is_started() const {
821 // Note that !! casts to bool. (VS gives a warning otherwise). 837 // Note that !! casts to bool. (VS gives a warning otherwise).
822 return !!resolve_job_; 838 return !!resolve_job_;
823 } 839 }
824 840
825 void StartAndCompleteCheckingForSynchronous() { 841 void StartAndCompleteCheckingForSynchronous() {
826 int rv = service_->TryToCompleteSynchronously(url_, load_flags_, 842 int rv = service_->TryToCompleteSynchronously(url_, load_flags_,
827 network_delegate_, results_); 843 network_delegate_, results_);
828 if (rv == ERR_IO_PENDING) 844 if (rv == ERR_IO_PENDING)
829 rv = Start(); 845 rv = Start();
846 else
847 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript", false);
848
830 if (rv != ERR_IO_PENDING) 849 if (rv != ERR_IO_PENDING)
831 QueryComplete(rv); 850 QueryComplete(rv);
832 } 851 }
833 852
834 void CancelResolveJob() { 853 void CancelResolveJob() {
835 DCHECK(is_started()); 854 DCHECK(is_started());
836 // The request may already be running in the resolver. 855 // The request may already be running in the resolver.
837 resolver()->CancelRequest(resolve_job_); 856 resolver()->CancelRequest(resolve_job_);
838 resolve_job_ = NULL; 857 resolve_job_ = NULL;
839 DCHECK(!is_started()); 858 DCHECK(!is_started());
(...skipping 16 matching lines...) Expand all
856 // Returns true if Cancel() has been called. 875 // Returns true if Cancel() has been called.
857 bool was_cancelled() const { 876 bool was_cancelled() const {
858 return user_callback_.is_null(); 877 return user_callback_.is_null();
859 } 878 }
860 879
861 // Helper to call after ProxyResolver completion (both synchronous and 880 // Helper to call after ProxyResolver completion (both synchronous and
862 // asynchronous). Fixes up the result that is to be returned to user. 881 // asynchronous). Fixes up the result that is to be returned to user.
863 int QueryDidComplete(int result_code) { 882 int QueryDidComplete(int result_code) {
864 DCHECK(!was_cancelled()); 883 DCHECK(!was_cancelled());
865 884
885 TimeTicks now = TimeTicks::Now();
886 if (is_started()) {
887 // The resolve job was completed as a result of calling |GetProxyForURL|.
888 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript", true);
889 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyService.GetProxyUsingScriptTime",
890 now - proxy_resolve_start_time_,
891 base::TimeDelta::FromMicroseconds(100),
892 base::TimeDelta::FromSeconds(20), 50);
893 }
894
866 // Clear |resolve_job_| so is_started() returns false while 895 // Clear |resolve_job_| so is_started() returns false while
867 // DidFinishResolvingProxy() runs. 896 // DidFinishResolvingProxy() runs.
868 resolve_job_ = nullptr; 897 resolve_job_ = nullptr;
869 898
870 // Note that DidFinishResolvingProxy might modify |results_|. 899 // Note that DidFinishResolvingProxy might modify |results_|.
871 int rv = service_->DidFinishResolvingProxy(url_, load_flags_, 900 int rv = service_->DidFinishResolvingProxy(url_, load_flags_,
872 network_delegate_, results_, 901 network_delegate_, results_,
873 result_code, net_log_); 902 result_code, net_log_);
874 903
875 // Make a note in the results which configuration was in use at the 904 // Make a note in the results which configuration was in use at the
876 // time of the resolve. 905 // time of the resolve.
877 results_->config_id_ = config_id_; 906 results_->config_id_ = config_id_;
878 results_->config_source_ = config_source_; 907 results_->config_source_ = config_source_;
879 results_->did_use_pac_script_ = true; 908 results_->did_use_pac_script_ = true;
880 results_->proxy_resolve_start_time_ = proxy_resolve_start_time_; 909 results_->proxy_resolve_start_time_ = proxy_resolve_start_time_;
881 results_->proxy_resolve_end_time_ = TimeTicks::Now(); 910 results_->proxy_resolve_end_time_ = now;
882 911
883 // Reset the state associated with in-progress-resolve. 912 // Reset the state associated with in-progress-resolve.
884 config_id_ = ProxyConfig::kInvalidConfigID; 913 config_id_ = ProxyConfig::kInvalidConfigID;
885 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN; 914 config_source_ = PROXY_CONFIG_SOURCE_UNKNOWN;
886 915
887 return rv; 916 return rv;
888 } 917 }
889 918
890 BoundNetLog* net_log() { return &net_log_; } 919 BoundNetLog* net_log() { return &net_log_; }
891 920
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 1069
1041 int ProxyService::ResolveProxyHelper(const GURL& raw_url, 1070 int ProxyService::ResolveProxyHelper(const GURL& raw_url,
1042 int load_flags, 1071 int load_flags,
1043 ProxyInfo* result, 1072 ProxyInfo* result,
1044 const CompletionCallback& callback, 1073 const CompletionCallback& callback,
1045 PacRequest** pac_request, 1074 PacRequest** pac_request,
1046 NetworkDelegate* network_delegate, 1075 NetworkDelegate* network_delegate,
1047 const BoundNetLog& net_log) { 1076 const BoundNetLog& net_log) {
1048 DCHECK(CalledOnValidThread()); 1077 DCHECK(CalledOnValidThread());
1049 1078
1079 TimeTicks start_time = TimeTicks::Now();
1050 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); 1080 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE);
1051 1081
1052 // Notify our polling-based dependencies that a resolve is taking place. 1082 // Notify our polling-based dependencies that a resolve is taking place.
1053 // This way they can schedule their polls in response to network activity. 1083 // This way they can schedule their polls in response to network activity.
1054 config_service_->OnLazyPoll(); 1084 config_service_->OnLazyPoll();
1055 if (script_poller_.get()) 1085 if (script_poller_.get())
1056 script_poller_->OnLazyPoll(); 1086 script_poller_->OnLazyPoll();
1057 1087
1058 if (current_state_ == STATE_NONE) 1088 if (current_state_ == STATE_NONE)
1059 ApplyProxyConfigIfAvailable(); 1089 ApplyProxyConfigIfAvailable();
1060 1090
1061 // Strip away any reference fragments and the username/password, as they 1091 // Strip away any reference fragments and the username/password, as they
1062 // are not relevant to proxy resolution. 1092 // are not relevant to proxy resolution.
1063 GURL url = SimplifyUrlForRequest(raw_url); 1093 GURL url = SimplifyUrlForRequest(raw_url);
1064 1094
1065 // Check if the request can be completed right away. (This is the case when 1095 // Check if the request can be completed right away. (This is the case when
1066 // using a direct connection for example). 1096 // using a direct connection for example).
1067 int rv = TryToCompleteSynchronously(url, load_flags, 1097 int rv = TryToCompleteSynchronously(url, load_flags,
1068 network_delegate, result); 1098 network_delegate, result);
1069 if (rv != ERR_IO_PENDING) 1099 if (rv != ERR_IO_PENDING) {
1070 return DidFinishResolvingProxy(url, load_flags, network_delegate, 1100 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript", false);
eroman 2015/05/08 21:12:39 This is split between multiple locations. Please p
Anand Mistry (off Chromium) 2015/05/11 07:40:35 Done.
1071 result, rv, net_log); 1101 rv = DidFinishResolvingProxy(url, load_flags, network_delegate, result, rv,
1102 net_log);
1103 RecordResolveProxyTime(start_time);
1104 return rv;
1105 }
1072 1106
1073 if (callback.is_null()) 1107 if (callback.is_null()) {
1108 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ResolvedUsingScript", false);
eroman 2015/05/08 21:12:39 Remove the logging here. If there was no callback
Anand Mistry (off Chromium) 2015/05/11 07:40:35 Done.
1109 RecordResolveProxyTime(start_time);
1074 return ERR_IO_PENDING; 1110 return ERR_IO_PENDING;
1111 }
1075 1112
1076 scoped_refptr<PacRequest> req( 1113 scoped_refptr<PacRequest> req(new PacRequest(
1077 new PacRequest(this, url, load_flags, network_delegate, 1114 this, url, load_flags, network_delegate, result,
1078 result, callback, net_log)); 1115 base::Bind(&ResolveProxyCallbackHelper, start_time, callback), net_log));
1079 1116
1080 if (current_state_ == STATE_READY) { 1117 if (current_state_ == STATE_READY) {
1081 // Start the resolve request. 1118 // Start the resolve request.
1082 rv = req->Start(); 1119 rv = req->Start();
1083 if (rv != ERR_IO_PENDING) 1120 if (rv != ERR_IO_PENDING) {
1121 RecordResolveProxyTime(start_time);
1084 return req->QueryDidComplete(rv); 1122 return req->QueryDidComplete(rv);
1123 }
1085 } else { 1124 } else {
1086 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); 1125 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC);
1087 } 1126 }
1088 1127
1089 DCHECK_EQ(ERR_IO_PENDING, rv); 1128 DCHECK_EQ(ERR_IO_PENDING, rv);
1090 DCHECK(!ContainsPendingRequest(req.get())); 1129 DCHECK(!ContainsPendingRequest(req.get()));
1091 pending_requests_.push_back(req); 1130 pending_requests_.push_back(req);
1092 1131
1093 // Completion will be notified through |callback|, unless the caller cancels 1132 // Completion will be notified through |callback|, unless the caller cancels
1094 // the request using |pac_request|. 1133 // the request using |pac_request|.
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 pending_requests_.begin(), pending_requests_.end(), req); 1411 pending_requests_.begin(), pending_requests_.end(), req);
1373 pending_requests_.erase(it); 1412 pending_requests_.erase(it);
1374 } 1413 }
1375 1414
1376 int ProxyService::DidFinishResolvingProxy(const GURL& url, 1415 int ProxyService::DidFinishResolvingProxy(const GURL& url,
1377 int load_flags, 1416 int load_flags,
1378 NetworkDelegate* network_delegate, 1417 NetworkDelegate* network_delegate,
1379 ProxyInfo* result, 1418 ProxyInfo* result,
1380 int result_code, 1419 int result_code,
1381 const BoundNetLog& net_log) { 1420 const BoundNetLog& net_log) {
1421 // This function "fixes" the result code, so make sure script terminated
1422 // errors are tracked.
1423 UMA_HISTOGRAM_BOOLEAN("Net.ProxyService.ScriptTerminated",
1424 result_code == ERR_PAC_SCRIPT_TERMINATED);
1425
1382 // Log the result of the proxy resolution. 1426 // Log the result of the proxy resolution.
1383 if (result_code == OK) { 1427 if (result_code == OK) {
1384 // Allow the network delegate to interpose on the resolution decision, 1428 // Allow the network delegate to interpose on the resolution decision,
1385 // possibly modifying the ProxyInfo. 1429 // possibly modifying the ProxyInfo.
1386 if (network_delegate) 1430 if (network_delegate)
1387 network_delegate->NotifyResolveProxy(url, load_flags, *this, result); 1431 network_delegate->NotifyResolveProxy(url, load_flags, *this, result);
1388 1432
1389 // When logging all events is enabled, dump the proxy list. 1433 // When logging all events is enabled, dump the proxy list.
1390 if (net_log.GetCaptureMode().enabled()) { 1434 if (net_log.GetCaptureMode().enabled()) {
1391 net_log.AddEvent( 1435 net_log.AddEvent(
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 State previous_state = ResetProxyConfig(false); 1682 State previous_state = ResetProxyConfig(false);
1639 if (previous_state != STATE_NONE) 1683 if (previous_state != STATE_NONE)
1640 ApplyProxyConfigIfAvailable(); 1684 ApplyProxyConfigIfAvailable();
1641 } 1685 }
1642 1686
1643 void ProxyService::OnDNSChanged() { 1687 void ProxyService::OnDNSChanged() {
1644 OnIPAddressChanged(); 1688 OnIPAddressChanged();
1645 } 1689 }
1646 1690
1647 } // namespace net 1691 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698