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

Unified Diff: base/trace_event/memory_dump_manager.cc

Issue 2537363003: [memory-infra] Add support for polling memory totals in MemoryDumpManager (Closed)
Patch Set: fix test. Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: base/trace_event/memory_dump_manager.cc
diff --git a/base/trace_event/memory_dump_manager.cc b/base/trace_event/memory_dump_manager.cc
index 5e34147063662d016ddb8ef003eb21928801a03d..b98cf3df545591bb1c10d9200c1364f3ba492526 100644
--- a/base/trace_event/memory_dump_manager.cc
+++ b/base/trace_event/memory_dump_manager.cc
@@ -284,6 +284,12 @@ void MemoryDumpManager::RegisterDumpProviderInternal(
// path for RenderThreadImpl::Init().
if (already_registered)
return;
+
+ if (options.is_fast_polling_supported && dump_thread_) {
Primiano Tucci (use gerrit) 2016/12/15 16:45:01 Can you add a comment here saying: // the list of
ssid 2016/12/16 02:31:54 Done.
+ dump_thread_->task_runner()->PostTask(
+ FROM_HERE, Bind(&MemoryDumpManager::RegisterPollingMDPOnDumpThread,
+ Unretained(this), mdpinfo));
+ }
}
if (heap_profiling_enabled_)
@@ -322,6 +328,7 @@ void MemoryDumpManager::UnregisterDumpProviderInternal(
// - At the end of this function, if no dump is in progress.
// - Either in SetupNextMemoryDump() or InvokeOnMemoryDump() when MDPInfo is
// removed from |pending_dump_providers|.
+ // - When the provider is removed from |mdps_for_fast_polling_|.
DCHECK(!(*mdp_iter)->owned_dump_provider);
(*mdp_iter)->owned_dump_provider = std::move(owned_mdp);
} else if (subtle::NoBarrier_Load(&memory_tracing_enabled_)) {
@@ -340,6 +347,12 @@ void MemoryDumpManager::UnregisterDumpProviderInternal(
<< "unregister itself in a racy way. Please file a crbug.";
}
+ if ((*mdp_iter)->options.is_fast_polling_supported && dump_thread_) {
+ dump_thread_->task_runner()->PostTask(
Primiano Tucci (use gerrit) 2016/12/15 16:45:01 Add a DCHECK(take_mdp_ownership_and_delete_async)
ssid 2016/12/16 02:31:54 Done.
+ FROM_HERE, Bind(&MemoryDumpManager::UnregisterPollingMDPOnDumpThread,
+ Unretained(this), *mdp_iter));
+ }
+
// The MDPInfo instance can still be referenced by the
// |ProcessMemoryDumpAsyncState.pending_dump_providers|. For this reason
// the MDPInfo is flagged as disabled. It will cause InvokeOnMemoryDump()
@@ -349,6 +362,23 @@ void MemoryDumpManager::UnregisterDumpProviderInternal(
dump_providers_.erase(mdp_iter);
}
+void MemoryDumpManager::RegisterPollingMDPOnDumpThread(
+ scoped_refptr<MemoryDumpManager::MemoryDumpProviderInfo> mdpinfo) {
+ DCHECK(!mdpinfo->task_runner);
+ mdpinfo->dump_provider->SetFastMemoryPollingEnabled(true);
+
+ AutoLock lock(lock_);
+ mdps_for_fast_polling_.insert(mdpinfo);
+}
+
+void MemoryDumpManager::UnregisterPollingMDPOnDumpThread(
+ scoped_refptr<MemoryDumpManager::MemoryDumpProviderInfo> mdpinfo) {
+ mdpinfo->dump_provider->SetFastMemoryPollingEnabled(false);
+
+ AutoLock lock(lock_);
+ mdps_for_fast_polling_.erase(mdpinfo);
+}
+
void MemoryDumpManager::RequestGlobalDump(
MemoryDumpType dump_type,
MemoryDumpLevelOfDetail level_of_detail,
@@ -602,6 +632,24 @@ void MemoryDumpManager::InvokeOnMemoryDump(
SetupNextMemoryDump(std::move(pmd_async_state));
}
+void MemoryDumpManager::PollFastMemoryTotal(uint64_t* memory_total) {
+#if DCHECK_IS_ON()
Primiano Tucci (use gerrit) 2016/12/15 16:45:01 plz dcheck section and just add a comment. There i
ssid 2016/12/16 02:31:54 I agree this is the case. But this is the part I s
Primiano Tucci (use gerrit) 2016/12/16 12:34:40 Let's move this discussion to the next CL. There i
+ {
+ AutoLock lock(lock_);
+ DCHECK(dump_thread_->task_runner()->BelongsToCurrentThread());
+ }
+#endif
+ *memory_total = 0;
+ // Note that we call PollFastMemoryTotal even if the dump provider is disabled
+ // (unregistered). This is to avoid taking lock slowing this method.
+ for (const auto& mdpinfo : mdps_for_fast_polling_) {
+ uint64_t value = 0;
+ mdpinfo->dump_provider->PollFastMemoryTotal(&value);
+ *memory_total += value;
+ }
+ return;
+}
+
// static
void MemoryDumpManager::FinalizeDumpAndAddToTrace(
std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) {
@@ -715,6 +763,14 @@ void MemoryDumpManager::OnTraceLogEnabled() {
DCHECK(!dump_thread_);
dump_thread_ = std::move(dump_thread);
+ mdps_for_fast_polling_.clear();
+ for (const auto& mdpinfo : dump_providers_) {
+ if (mdpinfo->options.is_fast_polling_supported) {
+ mdps_for_fast_polling_.insert(mdpinfo);
+ mdpinfo->dump_provider->SetFastMemoryPollingEnabled(true);
Primiano Tucci (use gerrit) 2016/12/15 16:45:01 I think we should do this call only when needed. O
ssid 2016/12/16 02:31:54 I just don't like the idea of session_state_ scann
Primiano Tucci (use gerrit) 2016/12/16 12:34:40 Ok the more I think to this the more I feel that t
+ }
+ }
+
subtle::NoBarrier_Store(&memory_tracing_enabled_, 1);
// TODO(primiano): This is a temporary hack to disable periodic memory dumps
@@ -748,6 +804,15 @@ void MemoryDumpManager::OnTraceLogDisabled() {
periodic_dump_timer_.Stop();
if (dump_thread)
dump_thread->Stop();
+
+ // |mdps_for_fast_polling_| must be cleared only after the dump thread is
+ // stopped (polling tasks are done).
+ {
+ AutoLock lock(lock_);
+ for (const auto& mdpinfo : mdps_for_fast_polling_)
+ mdpinfo->dump_provider->SetFastMemoryPollingEnabled(false);
+ mdps_for_fast_polling_.clear();
+ }
}
bool MemoryDumpManager::IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode) {

Powered by Google App Engine
This is Rietveld 408576698