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

Unified Diff: components/tracing/common/process_metrics_memory_dump_provider.cc

Issue 2753723003: Fix crash in InvokeOnMemoryDump when tracing (Closed)
Patch Set: be more explicit Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: components/tracing/common/process_metrics_memory_dump_provider.cc
diff --git a/components/tracing/common/process_metrics_memory_dump_provider.cc b/components/tracing/common/process_metrics_memory_dump_provider.cc
index 147e8b33fde1d3f5eaaf2c0879f46cc48e1a9dee..165026a86e573fb98ad4887fcf41b6159b10e936 100644
--- a/components/tracing/common/process_metrics_memory_dump_provider.cc
+++ b/components/tracing/common/process_metrics_memory_dump_provider.cc
@@ -213,6 +213,11 @@ std::unique_ptr<base::ProcessMetrics> CreateProcessMetrics(
// static
uint64_t ProcessMetricsMemoryDumpProvider::rss_bytes_for_testing = 0;
+// static
+using FactoryFunction =
+ std::unique_ptr<ProcessMetricsMemoryDumpProvider> (*)(base::ProcessId);
Primiano Tucci (use gerrit) 2017/03/15 12:44:40 this (the using) seems redudant, as you have alrea
hjd 2017/03/15 14:23:12 Doesn't seem visible here? ../../components/traci
Primiano Tucci (use gerrit) 2017/03/15 15:18:14 well it's because, 1: is private 2: you need the
+FactoryFunction ProcessMetricsMemoryDumpProvider::factory_for_testing = nullptr;
Primiano Tucci (use gerrit) 2017/03/15 12:44:40 this instead is necessary, yup
+
#if defined(OS_LINUX) || defined(OS_ANDROID)
// static
@@ -540,25 +545,41 @@ bool ProcessMetricsMemoryDumpProvider::DumpProcessMemoryMaps(
#endif // defined(OS_MACOSX)
// static
-void ProcessMetricsMemoryDumpProvider::RegisterForProcess(
+std::unique_ptr<ProcessMetricsMemoryDumpProvider>
+ProcessMetricsMemoryDumpProvider::CreateMetricsProvider(
Primiano Tucci (use gerrit) 2017/03/15 12:44:40 since this function is quite small and is used onl
hjd 2017/03/15 14:23:12 Done.
base::ProcessId process) {
+ if (factory_for_testing) {
+ std::unique_ptr<ProcessMetricsMemoryDumpProvider> metrics_provider(
Primiano Tucci (use gerrit) 2017/03/15 12:44:40 just return factory_for_testing(process); should b
hjd 2017/03/15 14:23:12 thanks :)
+ factory_for_testing(process));
+ return metrics_provider;
+ }
std::unique_ptr<ProcessMetricsMemoryDumpProvider> metrics_provider(
new ProcessMetricsMemoryDumpProvider(process));
- base::trace_event::MemoryDumpProvider::Options options;
- options.target_pid = process;
- options.is_fast_polling_supported = true;
- base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
- metrics_provider.get(), "ProcessMemoryMetrics", nullptr, options);
+ return metrics_provider;
Primiano Tucci (use gerrit) 2017/03/15 12:44:40 here instead you can just do: return MakeUnique<PM
hjd 2017/03/15 14:23:12 Hmm, I think it doesn't work because the construct
+}
+
+// static
+void ProcessMetricsMemoryDumpProvider::RegisterForProcess(
+ base::ProcessId process) {
+ std::unique_ptr<ProcessMetricsMemoryDumpProvider> owned_provider =
+ ProcessMetricsMemoryDumpProvider::CreateMetricsProvider(process);
+ ProcessMetricsMemoryDumpProvider* provider = owned_provider.get();
bool did_insert =
g_dump_providers_map.Get()
- .insert(std::make_pair(process, std::move(metrics_provider)))
+ .insert(std::make_pair(process, std::move(owned_provider)))
.second;
if (!did_insert) {
DLOG(ERROR) << "ProcessMetricsMemoryDumpProvider already registered for "
<< (process == base::kNullProcessId
? "current process"
: "process id " + base::IntToString(process));
+ return;
}
+ base::trace_event::MemoryDumpProvider::Options options;
+ options.target_pid = process;
+ options.is_fast_polling_supported = true;
+ base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
+ provider, "ProcessMemoryMetrics", nullptr, options);
}
// static

Powered by Google App Engine
This is Rietveld 408576698