OLD | NEW |
---|---|
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 Loading... | |
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 using FactoryFunction = | |
218 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
| |
219 FactoryFunction ProcessMetricsMemoryDumpProvider::factory_for_testing = nullptr; | |
Primiano Tucci (use gerrit)
2017/03/15 12:44:40
this instead is necessary, yup
| |
220 | |
216 #if defined(OS_LINUX) || defined(OS_ANDROID) | 221 #if defined(OS_LINUX) || defined(OS_ANDROID) |
217 | 222 |
218 // static | 223 // static |
219 FILE* ProcessMetricsMemoryDumpProvider::proc_smaps_for_testing = nullptr; | 224 FILE* ProcessMetricsMemoryDumpProvider::proc_smaps_for_testing = nullptr; |
220 | 225 |
221 // static | 226 // static |
222 int ProcessMetricsMemoryDumpProvider::fast_polling_statm_fd_for_testing = -1; | 227 int ProcessMetricsMemoryDumpProvider::fast_polling_statm_fd_for_testing = -1; |
223 | 228 |
224 bool ProcessMetricsMemoryDumpProvider::DumpProcessMemoryMaps( | 229 bool ProcessMetricsMemoryDumpProvider::DumpProcessMemoryMaps( |
225 const base::trace_event::MemoryDumpArgs& args, | 230 const base::trace_event::MemoryDumpArgs& args, |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 for (VMRegion& region : dyld_regions) { | 538 for (VMRegion& region : dyld_regions) { |
534 pmd->process_mmaps()->AddVMRegion(region); | 539 pmd->process_mmaps()->AddVMRegion(region); |
535 } | 540 } |
536 | 541 |
537 pmd->set_has_process_mmaps(); | 542 pmd->set_has_process_mmaps(); |
538 return true; | 543 return true; |
539 } | 544 } |
540 #endif // defined(OS_MACOSX) | 545 #endif // defined(OS_MACOSX) |
541 | 546 |
542 // static | 547 // static |
548 std::unique_ptr<ProcessMetricsMemoryDumpProvider> | |
549 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.
| |
550 base::ProcessId process) { | |
551 if (factory_for_testing) { | |
552 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 :)
| |
553 factory_for_testing(process)); | |
554 return metrics_provider; | |
555 } | |
556 std::unique_ptr<ProcessMetricsMemoryDumpProvider> metrics_provider( | |
557 new ProcessMetricsMemoryDumpProvider(process)); | |
558 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
| |
559 } | |
560 | |
561 // static | |
543 void ProcessMetricsMemoryDumpProvider::RegisterForProcess( | 562 void ProcessMetricsMemoryDumpProvider::RegisterForProcess( |
544 base::ProcessId process) { | 563 base::ProcessId process) { |
545 std::unique_ptr<ProcessMetricsMemoryDumpProvider> metrics_provider( | 564 std::unique_ptr<ProcessMetricsMemoryDumpProvider> owned_provider = |
546 new ProcessMetricsMemoryDumpProvider(process)); | 565 ProcessMetricsMemoryDumpProvider::CreateMetricsProvider(process); |
547 base::trace_event::MemoryDumpProvider::Options options; | 566 ProcessMetricsMemoryDumpProvider* provider = owned_provider.get(); |
548 options.target_pid = process; | |
549 options.is_fast_polling_supported = true; | |
550 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
551 metrics_provider.get(), "ProcessMemoryMetrics", nullptr, options); | |
552 bool did_insert = | 567 bool did_insert = |
553 g_dump_providers_map.Get() | 568 g_dump_providers_map.Get() |
554 .insert(std::make_pair(process, std::move(metrics_provider))) | 569 .insert(std::make_pair(process, std::move(owned_provider))) |
555 .second; | 570 .second; |
556 if (!did_insert) { | 571 if (!did_insert) { |
557 DLOG(ERROR) << "ProcessMetricsMemoryDumpProvider already registered for " | 572 DLOG(ERROR) << "ProcessMetricsMemoryDumpProvider already registered for " |
558 << (process == base::kNullProcessId | 573 << (process == base::kNullProcessId |
559 ? "current process" | 574 ? "current process" |
560 : "process id " + base::IntToString(process)); | 575 : "process id " + base::IntToString(process)); |
576 return; | |
561 } | 577 } |
578 base::trace_event::MemoryDumpProvider::Options options; | |
579 options.target_pid = process; | |
580 options.is_fast_polling_supported = true; | |
581 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
582 provider, "ProcessMemoryMetrics", nullptr, options); | |
562 } | 583 } |
563 | 584 |
564 // static | 585 // static |
565 void ProcessMetricsMemoryDumpProvider::UnregisterForProcess( | 586 void ProcessMetricsMemoryDumpProvider::UnregisterForProcess( |
566 base::ProcessId process) { | 587 base::ProcessId process) { |
567 auto iter = g_dump_providers_map.Get().find(process); | 588 auto iter = g_dump_providers_map.Get().find(process); |
568 if (iter == g_dump_providers_map.Get().end()) | 589 if (iter == g_dump_providers_map.Get().end()) |
569 return; | 590 return; |
570 base::trace_event::MemoryDumpManager::GetInstance() | 591 base::trace_event::MemoryDumpManager::GetInstance() |
571 ->UnregisterAndDeleteDumpProviderSoon(std::move(iter->second)); | 592 ->UnregisterAndDeleteDumpProviderSoon(std::move(iter->second)); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 #endif | 713 #endif |
693 } | 714 } |
694 | 715 |
695 void ProcessMetricsMemoryDumpProvider::SuspendFastMemoryPolling() { | 716 void ProcessMetricsMemoryDumpProvider::SuspendFastMemoryPolling() { |
696 #if defined(OS_LINUX) || defined(OS_ANDROID) | 717 #if defined(OS_LINUX) || defined(OS_ANDROID) |
697 fast_polling_statm_fd_.reset(); | 718 fast_polling_statm_fd_.reset(); |
698 #endif | 719 #endif |
699 } | 720 } |
700 | 721 |
701 } // namespace tracing | 722 } // namespace tracing |
OLD | NEW |