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

Side by Side Diff: components/tracing/common/process_metrics_memory_dump_provider.cc

Issue 2753723003: Fix crash in InvokeOnMemoryDump when tracing (Closed)
Patch Set: dont run test on mac or windows 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 unified diff | Download patch
OLDNEW
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 "components/tracing/common/process_metrics_memory_dump_provider.h" 5 #include "components/tracing/common/process_metrics_memory_dump_provider.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 NOTREACHED(); 206 NOTREACHED();
207 return std::unique_ptr<base::ProcessMetrics>(); 207 return std::unique_ptr<base::ProcessMetrics>();
208 #endif // defined(OS_LINUX) || defined(OS_ANDROID) 208 #endif // defined(OS_LINUX) || defined(OS_ANDROID)
209 } 209 }
210 210
211 } // namespace 211 } // namespace
212 212
213 // static 213 // static
214 uint64_t ProcessMetricsMemoryDumpProvider::rss_bytes_for_testing = 0; 214 uint64_t ProcessMetricsMemoryDumpProvider::rss_bytes_for_testing = 0;
215 215
216 // static
217 ProcessMetricsMemoryDumpProvider::FactoryFunction
218 ProcessMetricsMemoryDumpProvider::factory_for_testing = nullptr;
219
216 #if defined(OS_LINUX) || defined(OS_ANDROID) 220 #if defined(OS_LINUX) || defined(OS_ANDROID)
217 221
218 // static 222 // static
219 FILE* ProcessMetricsMemoryDumpProvider::proc_smaps_for_testing = nullptr; 223 FILE* ProcessMetricsMemoryDumpProvider::proc_smaps_for_testing = nullptr;
220 224
221 // static 225 // static
222 int ProcessMetricsMemoryDumpProvider::fast_polling_statm_fd_for_testing = -1; 226 int ProcessMetricsMemoryDumpProvider::fast_polling_statm_fd_for_testing = -1;
223 227
224 bool ProcessMetricsMemoryDumpProvider::DumpProcessMemoryMaps( 228 bool ProcessMetricsMemoryDumpProvider::DumpProcessMemoryMaps(
225 const base::trace_event::MemoryDumpArgs& args, 229 const base::trace_event::MemoryDumpArgs& args,
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 } 539 }
536 540
537 pmd->set_has_process_mmaps(); 541 pmd->set_has_process_mmaps();
538 return true; 542 return true;
539 } 543 }
540 #endif // defined(OS_MACOSX) 544 #endif // defined(OS_MACOSX)
541 545
542 // static 546 // static
543 void ProcessMetricsMemoryDumpProvider::RegisterForProcess( 547 void ProcessMetricsMemoryDumpProvider::RegisterForProcess(
544 base::ProcessId process) { 548 base::ProcessId process) {
545 std::unique_ptr<ProcessMetricsMemoryDumpProvider> metrics_provider( 549 std::unique_ptr<ProcessMetricsMemoryDumpProvider> owned_provider;
546 new ProcessMetricsMemoryDumpProvider(process)); 550 if (factory_for_testing) {
547 base::trace_event::MemoryDumpProvider::Options options; 551 owned_provider = factory_for_testing(process);
548 options.target_pid = process; 552 } else {
549 options.is_fast_polling_supported = true; 553 owned_provider = std::unique_ptr<ProcessMetricsMemoryDumpProvider>(
550 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 554 new ProcessMetricsMemoryDumpProvider(process));
551 metrics_provider.get(), "ProcessMemoryMetrics", nullptr, options); 555 }
556
557 ProcessMetricsMemoryDumpProvider* provider = owned_provider.get();
552 bool did_insert = 558 bool did_insert =
553 g_dump_providers_map.Get() 559 g_dump_providers_map.Get()
554 .insert(std::make_pair(process, std::move(metrics_provider))) 560 .insert(std::make_pair(process, std::move(owned_provider)))
555 .second; 561 .second;
556 if (!did_insert) { 562 if (!did_insert) {
557 DLOG(ERROR) << "ProcessMetricsMemoryDumpProvider already registered for " 563 DLOG(ERROR) << "ProcessMetricsMemoryDumpProvider already registered for "
558 << (process == base::kNullProcessId 564 << (process == base::kNullProcessId
559 ? "current process" 565 ? "current process"
560 : "process id " + base::IntToString(process)); 566 : "process id " + base::IntToString(process));
567 return;
561 } 568 }
569 base::trace_event::MemoryDumpProvider::Options options;
570 options.target_pid = process;
571 options.is_fast_polling_supported = true;
572 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
573 provider, "ProcessMemoryMetrics", nullptr, options);
562 } 574 }
563 575
564 // static 576 // static
565 void ProcessMetricsMemoryDumpProvider::UnregisterForProcess( 577 void ProcessMetricsMemoryDumpProvider::UnregisterForProcess(
566 base::ProcessId process) { 578 base::ProcessId process) {
567 auto iter = g_dump_providers_map.Get().find(process); 579 auto iter = g_dump_providers_map.Get().find(process);
568 if (iter == g_dump_providers_map.Get().end()) 580 if (iter == g_dump_providers_map.Get().end())
569 return; 581 return;
570 base::trace_event::MemoryDumpManager::GetInstance() 582 base::trace_event::MemoryDumpManager::GetInstance()
571 ->UnregisterAndDeleteDumpProviderSoon(std::move(iter->second)); 583 ->UnregisterAndDeleteDumpProviderSoon(std::move(iter->second));
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 #endif 704 #endif
693 } 705 }
694 706
695 void ProcessMetricsMemoryDumpProvider::SuspendFastMemoryPolling() { 707 void ProcessMetricsMemoryDumpProvider::SuspendFastMemoryPolling() {
696 #if defined(OS_LINUX) || defined(OS_ANDROID) 708 #if defined(OS_LINUX) || defined(OS_ANDROID)
697 fast_polling_statm_fd_.reset(); 709 fast_polling_statm_fd_.reset();
698 #endif 710 #endif
699 } 711 }
700 712
701 } // namespace tracing 713 } // namespace tracing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698