| 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 "base/trace_event/process_memory_totals_dump_provider.h" | 5 #include "base/trace_event/process_memory_totals_dump_provider.h" |
| 6 | 6 |
| 7 #include "base/process/process_metrics.h" | 7 #include "base/process/process_metrics.h" |
| 8 #include "base/trace_event/process_memory_dump.h" | 8 #include "base/trace_event/process_memory_dump.h" |
| 9 #include "base/trace_event/process_memory_totals.h" | 9 #include "base/trace_event/process_memory_totals.h" |
| 10 | 10 |
| 11 #if defined(OS_LINUX) || defined(OS_ANDROID) | 11 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 12 #include <fcntl.h> | 12 #include <fcntl.h> |
| 13 | 13 |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 bool kernel_supports_rss_peak_reset = true; | 17 bool kernel_supports_rss_peak_reset = true; |
| 18 const char kClearPeakRssCommand[] = "5"; | 18 const char kClearPeakRssCommand[] = "5"; |
| 19 } | 19 } |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 namespace trace_event { | 23 namespace trace_event { |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; | 26 uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; |
| 27 | 27 |
| 28 namespace { | |
| 29 | |
| 30 ProcessMetrics* CreateProcessMetricsForCurrentProcess() { | |
| 31 #if !defined(OS_MACOSX) || defined(OS_IOS) | |
| 32 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle()); | |
| 33 #else | |
| 34 return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL); | |
| 35 #endif | |
| 36 } | |
| 37 } // namespace | |
| 38 | |
| 39 // static | 28 // static |
| 40 ProcessMemoryTotalsDumpProvider* | 29 ProcessMemoryTotalsDumpProvider* |
| 41 ProcessMemoryTotalsDumpProvider::GetInstance() { | 30 ProcessMemoryTotalsDumpProvider::GetInstance() { |
| 42 return Singleton< | 31 return Singleton< |
| 43 ProcessMemoryTotalsDumpProvider, | 32 ProcessMemoryTotalsDumpProvider, |
| 44 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get(); | 33 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get(); |
| 45 } | 34 } |
| 46 | 35 |
| 47 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider() | 36 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider() |
| 48 : process_metrics_(CreateProcessMetricsForCurrentProcess()) { | 37 : process_metrics_(ProcessMetrics::CreateCurrentProcessMetrics()) {} |
| 49 } | |
| 50 | 38 |
| 51 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() { | 39 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() { |
| 52 } | 40 } |
| 53 | 41 |
| 54 // Called at trace dump point time. Creates a snapshot the memory counters for | 42 // Called at trace dump point time. Creates a snapshot the memory counters for |
| 55 // the current process. | 43 // the current process. |
| 56 bool ProcessMemoryTotalsDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, | 44 bool ProcessMemoryTotalsDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, |
| 57 ProcessMemoryDump* pmd) { | 45 ProcessMemoryDump* pmd) { |
| 58 const uint64 rss_bytes = rss_bytes_for_testing | 46 const uint64 rss_bytes = rss_bytes_for_testing |
| 59 ? rss_bytes_for_testing | 47 ? rss_bytes_for_testing |
| (...skipping 25 matching lines...) Expand all Loading... |
| 85 pmd->process_totals()->set_peak_resident_set_bytes(peak_rss_bytes); | 73 pmd->process_totals()->set_peak_resident_set_bytes(peak_rss_bytes); |
| 86 pmd->set_has_process_totals(); | 74 pmd->set_has_process_totals(); |
| 87 return true; | 75 return true; |
| 88 } | 76 } |
| 89 | 77 |
| 90 return false; | 78 return false; |
| 91 } | 79 } |
| 92 | 80 |
| 93 } // namespace trace_event | 81 } // namespace trace_event |
| 94 } // namespace base | 82 } // namespace base |
| OLD | NEW |