Commit 3c8373a8 authored by xunjieli's avatar xunjieli Committed by Commit bot

Do not create sub MemoryAllocatorDumps in SSLClientSessionCache

SSLClientSessionCache::DumpMemoryStats() creates one
MemoryAllocatorDump for each cache entry. To make the memory dump lighter,
this CL dumps the total size and count and does not create sub dumps.

BUG=669108

Review-Url: https://codereview.chromium.org/2574513002
Cr-Commit-Position: refs/heads/master@{#437981}
parent 65aa8f65
...@@ -98,31 +98,30 @@ void SSLClientSessionCache::DumpMemoryStats( ...@@ -98,31 +98,30 @@ void SSLClientSessionCache::DumpMemoryStats(
return; return;
cache_dump = pmd->CreateAllocatorDump(absolute_name); cache_dump = pmd->CreateAllocatorDump(absolute_name);
base::AutoLock lock(lock_); base::AutoLock lock(lock_);
int total_serialized_cert_size = 0;
int total_cert_count = 0;
for (const auto& pair : cache_) { for (const auto& pair : cache_) {
auto entry = pair.second.get(); auto entry = pair.second.get();
auto cert_chain = entry->x509_chain; auto cert_chain = entry->x509_chain;
size_t cert_count = sk_X509_num(cert_chain); size_t cert_count = sk_X509_num(cert_chain);
base::trace_event::MemoryAllocatorDump* entry_dump = total_cert_count += cert_count;
pmd->CreateAllocatorDump(
base::StringPrintf("%s/entry_%p", absolute_name.c_str(), entry));
int cert_size = 0;
for (size_t i = 0; i < cert_count; ++i) { for (size_t i = 0; i < cert_count; ++i) {
X509* cert = sk_X509_value(cert_chain, i); X509* cert = sk_X509_value(cert_chain, i);
cert_size += i2d_X509(cert, nullptr); total_serialized_cert_size += i2d_X509(cert, nullptr);
}
} }
// This measures the lower bound of the serialized certificate. It doesn't // This measures the lower bound of the serialized certificate. It doesn't
// measure the actual memory used, which is 4x this amount (see // measure the actual memory used, which is 4x this amount (see
// crbug.com/671420 for more details). // crbug.com/671420 for more details).
entry_dump->AddScalar("cert_size", cache_dump->AddScalar("serialized_cert_size",
base::trace_event::MemoryAllocatorDump::kUnitsBytes, base::trace_event::MemoryAllocatorDump::kUnitsBytes,
cert_size); total_serialized_cert_size);
entry_dump->AddScalar("serialized_cert_count", cache_dump->AddScalar("cert_count",
base::trace_event::MemoryAllocatorDump::kUnitsObjects, base::trace_event::MemoryAllocatorDump::kUnitsObjects,
cert_count); total_cert_count);
entry_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, cache_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
base::trace_event::MemoryAllocatorDump::kUnitsBytes, base::trace_event::MemoryAllocatorDump::kUnitsBytes,
cert_size); total_serialized_cert_size);
}
} }
void SSLClientSessionCache::FlushExpiredSessions() { void SSLClientSessionCache::FlushExpiredSessions() {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/memory_allocator_dump.h" #include "base/trace_event/memory_allocator_dump.h"
#include "base/trace_event/process_memory_dump.h" #include "base/trace_event/process_memory_dump.h"
#include "base/trace_event/trace_event_argument.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/boringssl/src/include/openssl/ssl.h" #include "third_party/boringssl/src/include/openssl/ssl.h"
...@@ -325,16 +326,16 @@ TEST(SSLClientSessionCacheTest, TestDumpMemoryStats) { ...@@ -325,16 +326,16 @@ TEST(SSLClientSessionCacheTest, TestDumpMemoryStats) {
new base::trace_event::ProcessMemoryDump(nullptr, dump_args)); new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
cache.DumpMemoryStats(process_memory_dump.get()); cache.DumpMemoryStats(process_memory_dump.get());
const base::trace_event::ProcessMemoryDump::AllocatorDumpsMap& const base::trace_event::MemoryAllocatorDump* dump =
allocator_dumps = process_memory_dump->allocator_dumps(); process_memory_dump->GetAllocatorDump("net/ssl_session_cache");
ASSERT_NE(nullptr, dump);
size_t num_entry_dump = 0; std::unique_ptr<base::Value> raw_attrs =
for (const auto& pair : allocator_dumps) { dump->attributes_for_testing()->ToBaseValue();
const std::string& dump_name = pair.first; base::DictionaryValue* attrs;
if (dump_name.find("net/ssl_session_cache/entry") != std::string::npos) ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs));
num_entry_dump++; ASSERT_TRUE(attrs->HasKey("cert_count"));
} ASSERT_TRUE(attrs->HasKey("serialized_cert_size"));
ASSERT_EQ(3u, num_entry_dump); ASSERT_TRUE(attrs->HasKey(base::trace_event::MemoryAllocatorDump::kNameSize));
} }
} // namespace net } // namespace net
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment