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

Side by Side Diff: net/socket/ssl_client_socket_impl.cc

Issue 2623803002: Avoid creating MemoryAllocatorDump for individual sockets (Closed)
Patch Set: self review 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 "net/socket/ssl_client_socket_impl.h" 5 #include "net/socket/ssl_client_socket_impl.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/feature_list.h" 15 #include "base/feature_list.h"
16 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
19 #include "base/metrics/field_trial.h" 19 #include "base/metrics/field_trial.h"
20 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
21 #include "base/metrics/sparse_histogram.h" 21 #include "base/metrics/sparse_histogram.h"
22 #include "base/profiler/scoped_tracker.h" 22 #include "base/profiler/scoped_tracker.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "base/synchronization/lock.h" 26 #include "base/synchronization/lock.h"
27 #include "base/threading/thread_local.h" 27 #include "base/threading/thread_local.h"
28 #include "base/trace_event/memory_allocator_dump.h"
29 #include "base/trace_event/process_memory_dump.h" 28 #include "base/trace_event/process_memory_dump.h"
30 #include "base/trace_event/trace_event.h" 29 #include "base/trace_event/trace_event.h"
31 #include "base/values.h" 30 #include "base/values.h"
32 #include "crypto/ec_private_key.h" 31 #include "crypto/ec_private_key.h"
33 #include "crypto/openssl_util.h" 32 #include "crypto/openssl_util.h"
34 #include "net/base/ip_address.h" 33 #include "net/base/ip_address.h"
35 #include "net/base/net_errors.h" 34 #include "net/base/net_errors.h"
36 #include "net/base/trace_constants.h" 35 #include "net/base/trace_constants.h"
37 #include "net/cert/cert_verifier.h" 36 #include "net/cert/cert_verifier.h"
38 #include "net/cert/ct_ev_whitelist.h" 37 #include "net/cert/ct_ev_whitelist.h"
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 796 }
798 797
799 void SSLClientSocketImpl::GetConnectionAttempts(ConnectionAttempts* out) const { 798 void SSLClientSocketImpl::GetConnectionAttempts(ConnectionAttempts* out) const {
800 out->clear(); 799 out->clear();
801 } 800 }
802 801
803 int64_t SSLClientSocketImpl::GetTotalReceivedBytes() const { 802 int64_t SSLClientSocketImpl::GetTotalReceivedBytes() const {
804 return transport_->socket()->GetTotalReceivedBytes(); 803 return transport_->socket()->GetTotalReceivedBytes();
805 } 804 }
806 805
807 void SSLClientSocketImpl::DumpMemoryStats( 806 void SSLClientSocketImpl::DumpMemoryStats(SocketMemoryStats* stats) const {
808 base::trace_event::ProcessMemoryDump* pmd, 807 if (transport_adapter_)
809 const std::string& parent_dump_absolute_name) const { 808 stats->buffer_size = transport_adapter_->GetAllocationSize();
810 size_t total_size = 0; 809 if (server_cert_chain_) {
811 base::trace_event::MemoryAllocatorDump* socket_dump = 810 for (size_t i = 0; i < server_cert_chain_->size(); ++i) {
812 pmd->CreateAllocatorDump(base::StringPrintf( 811 X509* cert = server_cert_chain_->Get(i);
813 "%s/ssl_socket_%p", parent_dump_absolute_name.c_str(), this)); 812 // This measures the lower bound of the serialized certificate. It doesn't
814 if (transport_adapter_) { 813 // measure the actual memory used, which is 4x this amount (see
815 size_t bio_buffers_size = transport_adapter_->GetAllocationSize(); 814 // crbug.com/671420 for more details).
816 socket_dump->AddScalar("buffer_size", 815 stats->serialized_cert_size += i2d_X509(cert, nullptr);
817 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 816 }
818 bio_buffers_size); 817 stats->cert_count = server_cert_chain_->size();
eroman 2017/01/11 02:19:58 What is the expected contract for |stats| -- assig
xunjieli 2017/01/11 20:05:07 Done. Opted for the assignment way throughout.
819 total_size += bio_buffers_size;
820 } 818 }
821 size_t total_cert_size = 0; 819 stats->total_size = stats->buffer_size + stats->serialized_cert_size;
822 size_t certs_count = 0;
823 if (server_cert_chain_) {
824 certs_count = server_cert_chain_->size();
825 for (size_t i = 0; i < certs_count; ++i) {
826 X509* cert = server_cert_chain_->Get(i);
827 total_cert_size += i2d_X509(cert, nullptr);
828 }
829 }
830 total_size += total_cert_size;
831 // This measures the lower bound of the serialized certificate. It doesn't
832 // measure the actual memory used, which is 4x this amount (see
833 // crbug.com/671420 for more details).
834 socket_dump->AddScalar("serialized_cert_size",
835 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
836 total_cert_size);
837 socket_dump->AddScalar("cert_count",
838 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
839 certs_count);
840 socket_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
841 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
842 total_size);
843 } 820 }
844 821
845 // static 822 // static
846 void SSLClientSocketImpl::DumpSSLClientSessionMemoryStats( 823 void SSLClientSocketImpl::DumpSSLClientSessionMemoryStats(
847 base::trace_event::ProcessMemoryDump* pmd) { 824 base::trace_event::ProcessMemoryDump* pmd) {
848 SSLContext::GetInstance()->session_cache()->DumpMemoryStats(pmd); 825 SSLContext::GetInstance()->session_cache()->DumpMemoryStats(pmd);
849 } 826 }
850 827
851 int SSLClientSocketImpl::Read(IOBuffer* buf, 828 int SSLClientSocketImpl::Read(IOBuffer* buf,
852 int buf_len, 829 int buf_len,
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED && 2035 if (ERR_GET_REASON(info->error_code) == SSL_R_TLSV1_ALERT_ACCESS_DENIED &&
2059 !certificate_requested_) { 2036 !certificate_requested_) {
2060 net_error = ERR_SSL_PROTOCOL_ERROR; 2037 net_error = ERR_SSL_PROTOCOL_ERROR;
2061 } 2038 }
2062 } 2039 }
2063 2040
2064 return net_error; 2041 return net_error;
2065 } 2042 }
2066 2043
2067 } // namespace net 2044 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698