Skip to content

Commit

Permalink
Make url_request_context dumps include context names
Browse files Browse the repository at this point in the history
Background dumps do not include URLRequestContext's names because
string attributes are not allowed. SlowReports only has background
dumps. Without the name of the context, we don't know where the contexts
come from.

This CL includes the context names in the names for the allocator dumps.

BUG=705053,669108

Review-Url: https://codereview.chromium.org/2772283003
Cr-Commit-Position: refs/heads/master@{#460116}
  • Loading branch information
xunjieli authored and Commit bot committed Mar 28, 2017
1 parent 9c66d5a commit c4da1de
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 27 deletions.
50 changes: 46 additions & 4 deletions base/trace_event/memory_infra_background_whitelist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,52 @@ const char* const kAllocatorDumpNameWhitelist[] = {
"net/http_network_session_0x?/stream_factory",
"net/sdch_manager_0x?",
"net/ssl_session_cache",
"net/url_request_context_0x?",
"net/url_request_context_0x?/http_cache",
"net/url_request_context_0x?/http_network_session",
"net/url_request_context_0x?/sdch_manager",
"net/url_request_context",
"net/url_request_context/app_request",
"net/url_request_context/app_request/0x?",
"net/url_request_context/app_request/0x?/http_cache",
"net/url_request_context/app_request/0x?/http_network_session",
"net/url_request_context/app_request/0x?/sdch_manager",
"net/url_request_context/extensions",
"net/url_request_context/extensions/0x?",
"net/url_request_context/extensions/0x?/http_cache",
"net/url_request_context/extensions/0x?/http_network_session",
"net/url_request_context/extensions/0x?/sdch_manager",
"net/url_request_context/isolated_media",
"net/url_request_context/isolated_media/0x?",
"net/url_request_context/isolated_media/0x?/http_cache",
"net/url_request_context/isolated_media/0x?/http_network_session",
"net/url_request_context/isolated_media/0x?/sdch_manager",
"net/url_request_context/main",
"net/url_request_context/main/0x?",
"net/url_request_context/main/0x?/http_cache",
"net/url_request_context/main/0x?/http_network_session",
"net/url_request_context/main/0x?/sdch_manager",
"net/url_request_context/main_media",
"net/url_request_context/main_media/0x?",
"net/url_request_context/main_media/0x?/http_cache",
"net/url_request_context/main_media/0x?/http_network_session",
"net/url_request_context/main_media/0x?/sdch_manager",
"net/url_request_context/proxy",
"net/url_request_context/proxy/0x?",
"net/url_request_context/proxy/0x?/http_cache",
"net/url_request_context/proxy/0x?/http_network_session",
"net/url_request_context/proxy/0x?/sdch_manager",
"net/url_request_context/safe_browsing",
"net/url_request_context/safe_browsing/0x?",
"net/url_request_context/safe_browsing/0x?/http_cache",
"net/url_request_context/safe_browsing/0x?/http_network_session",
"net/url_request_context/safe_browsing/0x?/sdch_manager",
"net/url_request_context/system",
"net/url_request_context/system/0x?",
"net/url_request_context/system/0x?/http_cache",
"net/url_request_context/system/0x?/http_network_session",
"net/url_request_context/system/0x?/sdch_manager",
"net/url_request_context/unknown",
"net/url_request_context/unknown/0x?",
"net/url_request_context/unknown/0x?/http_cache",
"net/url_request_context/unknown/0x?/http_network_session",
"net/url_request_context/unknown/0x?/sdch_manager",
"web_cache/Image_resources",
"web_cache/CSS stylesheet_resources",
"web_cache/Script_resources",
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/off_the_record_profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ net::URLRequestContext*
OffTheRecordProfileIOData::InitializeMediaRequestContext(
net::URLRequestContext* original_context,
const StoragePartitionDescriptor& partition_descriptor,
const std::string& name) const {
const char* name) const {
NOTREACHED();
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/off_the_record_profile_io_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class OffTheRecordProfileIOData : public ProfileIOData {
net::URLRequestContext* InitializeMediaRequestContext(
net::URLRequestContext* original_context,
const StoragePartitionDescriptor& partition_descriptor,
const std::string& name) const override;
const char* name) const override;
net::URLRequestContext* AcquireMediaRequestContext() const override;
net::URLRequestContext* AcquireIsolatedAppRequestContext(
net::URLRequestContext* main_context,
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/profile_impl_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ net::URLRequestContext* ProfileImplIOData::InitializeAppRequestContext(
net::URLRequestContext* ProfileImplIOData::InitializeMediaRequestContext(
net::URLRequestContext* original_context,
const StoragePartitionDescriptor& partition_descriptor,
const std::string& name) const {
const char* name) const {
// Copy most state from the original context.
MediaRequestContext* context = new MediaRequestContext(name);
context->CopyFrom(original_context);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/profiles/profile_impl_io_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class ProfileImplIOData : public ProfileIOData {
net::URLRequestContext* InitializeMediaRequestContext(
net::URLRequestContext* original_context,
const StoragePartitionDescriptor& partition_descriptor,
const std::string& name) const override;
const char* name) const override;
net::URLRequestContext* AcquireMediaRequestContext() const override;
net::URLRequestContext* AcquireIsolatedAppRequestContext(
net::URLRequestContext* main_context,
Expand Down
3 changes: 1 addition & 2 deletions chrome/browser/profiles/profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
BrowserContext::EnsureResourceContextInitialized(profile);
}

ProfileIOData::MediaRequestContext::MediaRequestContext(
const std::string& name) {
ProfileIOData::MediaRequestContext::MediaRequestContext(const char* name) {
set_name(name);
}

Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/profiles/profile_io_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ProfileIOData {
// |name| is used to describe this context. Currently there are two kinds of
// media request context -- main media request context ("main_meda") and
// isolated app media request context ("isolated_media").
explicit MediaRequestContext(const std::string& name);
explicit MediaRequestContext(const char* name);

void SetHttpTransactionFactory(
std::unique_ptr<net::HttpTransactionFactory> http_factory);
Expand Down Expand Up @@ -492,7 +492,7 @@ class ProfileIOData {
virtual net::URLRequestContext* InitializeMediaRequestContext(
net::URLRequestContext* original_context,
const StoragePartitionDescriptor& details,
const std::string& name) const = 0;
const char* name) const = 0;

// These functions are used to transfer ownership of the lazily initialized
// context from ProfileIOData to the URLRequestContextGetter.
Expand Down
4 changes: 2 additions & 2 deletions net/base/sdch_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,11 @@ TEST_P(SdchManagerMemoryDumpTest, DumpMemoryStats) {
new base::trace_event::ProcessMemoryDump(nullptr, dump_args));

base::trace_event::MemoryAllocatorDump* parent =
pmd->CreateAllocatorDump("net/url_request_context_0x123");
pmd->CreateAllocatorDump("net/url_request_context/main/0x123");
sdch_manager()->DumpMemoryStats(pmd.get(), parent->absolute_name());

const base::trace_event::MemoryAllocatorDump* sub_dump =
pmd->GetAllocatorDump("net/url_request_context_0x123/sdch_manager");
pmd->GetAllocatorDump("net/url_request_context/main/0x123/sdch_manager");
ASSERT_NE(nullptr, sub_dump);
const base::trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump(
base::StringPrintf("net/sdch_manager_0x%" PRIxPTR,
Expand Down
5 changes: 3 additions & 2 deletions net/http/http_cache_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8243,13 +8243,14 @@ TEST_P(HttpCacheMemoryDumpTest, DumpMemoryStats) {
std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump(
new base::trace_event::ProcessMemoryDump(nullptr, dump_args));
base::trace_event::MemoryAllocatorDump* parent_dump =
process_memory_dump->CreateAllocatorDump("net/url_request_context_0x123");
process_memory_dump->CreateAllocatorDump(
"net/url_request_context/main/0x123");
cache.http_cache()->DumpMemoryStats(process_memory_dump.get(),
parent_dump->absolute_name());

const base::trace_event::MemoryAllocatorDump* dump =
process_memory_dump->GetAllocatorDump(
"net/url_request_context_0x123/http_cache");
"net/url_request_context/main/0x123/http_cache");
ASSERT_NE(nullptr, dump);
std::unique_ptr<base::Value> raw_attrs =
dump->attributes_for_testing()->ToBaseValue();
Expand Down
15 changes: 6 additions & 9 deletions net/url_request/url_request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ URLRequestContext::URLRequestContext()
network_quality_estimator_(nullptr),
url_requests_(new std::set<const URLRequest*>),
enable_brotli_(false),
check_cleartext_permitted_(false) {
check_cleartext_permitted_(false),
name_(nullptr) {
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "URLRequestContext", base::ThreadTaskRunnerHandle::Get());
}
Expand Down Expand Up @@ -139,23 +140,19 @@ void URLRequestContext::AssertNoURLRequests() const {
bool URLRequestContext::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) {
if (name_.empty())
if (!name_)
name_ = "unknown";

SSLClientSocketImpl::DumpSSLClientSessionMemoryStats(pmd);

std::string dump_name = base::StringPrintf(
"net/url_request_context_0x%" PRIxPTR, reinterpret_cast<uintptr_t>(this));
std::string dump_name =
base::StringPrintf("net/url_request_context/%s/0x%" PRIxPTR, name_,
reinterpret_cast<uintptr_t>(this));
base::trace_event::MemoryAllocatorDump* dump =
pmd->CreateAllocatorDump(dump_name);
dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount,
base::trace_event::MemoryAllocatorDump::kUnitsObjects,
url_requests_->size());
if (args.level_of_detail !=
base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
dump->AddString("origin",
base::trace_event::MemoryAllocatorDump::kTypeString, name_);
}
HttpTransactionFactory* transaction_factory = http_transaction_factory();
if (transaction_factory) {
HttpNetworkSession* network_session = transaction_factory->GetSession();
Expand Down
4 changes: 2 additions & 2 deletions net/url_request/url_request_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class NET_EXPORT URLRequestContext
// Sets a name for this URLRequestContext. Currently the name is used in
// MemoryDumpProvier to annotate memory usage. The name does not need to be
// unique.
void set_name(const std::string& name) { name_ = name; }
void set_name(const char* name) { name_ = name; }

// MemoryDumpProvider implementation:
bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
Expand Down Expand Up @@ -316,7 +316,7 @@ class NET_EXPORT URLRequestContext
// An optional name which can be set to describe this URLRequestContext.
// Used in MemoryDumpProvier to annotate memory usage. The name does not need
// to be unique.
std::string name_;
const char* name_;

DISALLOW_COPY_AND_ASSIGN(URLRequestContext);
};
Expand Down

0 comments on commit c4da1de

Please sign in to comment.