OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ssl/ssl_client_session_cache.h" | 5 #include "net/ssl/ssl_client_session_cache.h" |
6 | 6 |
7 #include <unordered_set> | |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/memory/memory_coordinator_client_registry.h" | 10 #include "base/memory/memory_coordinator_client_registry.h" |
10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
11 #include "base/time/clock.h" | 12 #include "base/time/clock.h" |
12 #include "base/time/default_clock.h" | 13 #include "base/time/default_clock.h" |
13 #include "base/trace_event/process_memory_dump.h" | 14 #include "base/trace_event/process_memory_dump.h" |
14 #include "net/cert/x509_util_openssl.h" | 15 #include "net/cert/x509_util_openssl.h" |
15 #include "third_party/boringssl/src/include/openssl/ssl.h" | 16 #include "third_party/boringssl/src/include/openssl/ssl.h" |
16 #include "third_party/boringssl/src/include/openssl/x509.h" | 17 #include "third_party/boringssl/src/include/openssl/x509.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 std::string absolute_name = "net/ssl_session_cache"; | 116 std::string absolute_name = "net/ssl_session_cache"; |
116 base::trace_event::MemoryAllocatorDump* cache_dump = | 117 base::trace_event::MemoryAllocatorDump* cache_dump = |
117 pmd->GetAllocatorDump(absolute_name); | 118 pmd->GetAllocatorDump(absolute_name); |
118 // This method can be reached from different URLRequestContexts. Since this is | 119 // This method can be reached from different URLRequestContexts. Since this is |
119 // a singleton, only log memory stats once. | 120 // a singleton, only log memory stats once. |
120 // TODO(xunjieli): Change this once crbug.com/458365 is fixed. | 121 // TODO(xunjieli): Change this once crbug.com/458365 is fixed. |
121 if (cache_dump) | 122 if (cache_dump) |
122 return; | 123 return; |
123 cache_dump = pmd->CreateAllocatorDump(absolute_name); | 124 cache_dump = pmd->CreateAllocatorDump(absolute_name); |
124 base::AutoLock lock(lock_); | 125 base::AutoLock lock(lock_); |
125 size_t total_serialized_cert_size = 0; | 126 size_t total_cert_size = 0; |
127 size_t undeduped_cert_size = 0; | |
126 size_t total_cert_count = 0; | 128 size_t total_cert_count = 0; |
129 std::unordered_set<const CRYPTO_BUFFER*> crypto_buffer_set; | |
DmitrySkiba
2017/02/17 22:02:58
I'm worried that this will slow things down. We've
davidben
2017/02/17 22:09:46
In the session cache, I would expect it to not do
xunjieli
2017/02/17 22:22:01
I don't think we can know the factor of total numb
| |
127 for (const auto& pair : cache_) { | 130 for (const auto& pair : cache_) { |
128 const SSL_SESSION* session = pair.second.session.get(); | 131 const SSL_SESSION* session = pair.second.session.get(); |
129 size_t cert_count = sk_CRYPTO_BUFFER_num(session->certs); | 132 size_t cert_count = sk_CRYPTO_BUFFER_num(session->certs); |
130 total_cert_count += cert_count; | 133 total_cert_count += cert_count; |
131 for (size_t i = 0; i < cert_count; ++i) { | 134 for (size_t i = 0; i < cert_count; ++i) { |
132 const CRYPTO_BUFFER* cert = sk_CRYPTO_BUFFER_value(session->certs, i); | 135 const CRYPTO_BUFFER* cert = sk_CRYPTO_BUFFER_value(session->certs, i); |
133 total_serialized_cert_size += CRYPTO_BUFFER_len(cert); | 136 // TODO(xunjieli): The multipler is added to account for the difference |
137 // between the serialized form and real cert allocation. Remove after | |
138 // crbug.com/671420 is done. | |
139 size_t cert_size = 4 * CRYPTO_BUFFER_len(cert); | |
140 undeduped_cert_size += cert_size; | |
141 if (crypto_buffer_set.find(cert) != crypto_buffer_set.end()) | |
142 continue; | |
143 total_cert_size += cert_size; | |
144 crypto_buffer_set.insert(cert); | |
134 } | 145 } |
135 } | 146 } |
136 // This measures the lower bound of the serialized certificate. It doesn't | 147 // This measures the lower bound of the serialized certificate. It doesn't |
137 // measure the actual memory used, which is 4x this amount (see | 148 // measure the actual memory used, which is 4x this amount (see |
138 // crbug.com/671420 for more details). | 149 // crbug.com/671420 for more details). |
139 cache_dump->AddScalar("serialized_cert_size", | 150 cache_dump->AddScalar("cert_size", |
140 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 151 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
141 total_serialized_cert_size); | 152 total_cert_size); |
153 cache_dump->AddScalar("undeduped_cert_size", | |
154 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
155 undeduped_cert_size); | |
142 cache_dump->AddScalar("cert_count", | 156 cache_dump->AddScalar("cert_count", |
143 base::trace_event::MemoryAllocatorDump::kUnitsObjects, | 157 base::trace_event::MemoryAllocatorDump::kUnitsObjects, |
144 total_cert_count); | 158 total_cert_count); |
145 cache_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 159 cache_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
146 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 160 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
147 total_serialized_cert_size); | 161 total_cert_size); |
148 } | 162 } |
149 | 163 |
150 SSLClientSessionCache::Entry::Entry() : lookups(0) {} | 164 SSLClientSessionCache::Entry::Entry() : lookups(0) {} |
151 SSLClientSessionCache::Entry::Entry(Entry&&) = default; | 165 SSLClientSessionCache::Entry::Entry(Entry&&) = default; |
152 SSLClientSessionCache::Entry::~Entry() = default; | 166 SSLClientSessionCache::Entry::~Entry() = default; |
153 | 167 |
154 void SSLClientSessionCache::FlushExpiredSessions() { | 168 void SSLClientSessionCache::FlushExpiredSessions() { |
155 time_t now = clock_->Now().ToTimeT(); | 169 time_t now = clock_->Now().ToTimeT(); |
156 auto iter = cache_.begin(); | 170 auto iter = cache_.begin(); |
157 while (iter != cache_.end()) { | 171 while (iter != cache_.end()) { |
(...skipping 17 matching lines...) Expand all Loading... | |
175 Flush(); | 189 Flush(); |
176 break; | 190 break; |
177 } | 191 } |
178 } | 192 } |
179 | 193 |
180 void SSLClientSessionCache::OnPurgeMemory() { | 194 void SSLClientSessionCache::OnPurgeMemory() { |
181 Flush(); | 195 Flush(); |
182 } | 196 } |
183 | 197 |
184 } // namespace net | 198 } // namespace net |
OLD | NEW |