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 #ifndef COMPONENTS_TRACING_COMMON_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ | 5 #ifndef COMPONENTS_TRACING_COMMON_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ |
6 #define COMPONENTS_TRACING_COMMON_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ | 6 #define COMPONENTS_TRACING_COMMON_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/files/scoped_file.h" | 10 #include "base/files/scoped_file.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 static void UnregisterForProcess(base::ProcessId process); | 30 static void UnregisterForProcess(base::ProcessId process); |
31 | 31 |
32 ~ProcessMetricsMemoryDumpProvider() override; | 32 ~ProcessMetricsMemoryDumpProvider() override; |
33 | 33 |
34 // MemoryDumpProvider implementation. | 34 // MemoryDumpProvider implementation. |
35 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 35 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
36 base::trace_event::ProcessMemoryDump* pmd) override; | 36 base::trace_event::ProcessMemoryDump* pmd) override; |
37 void PollFastMemoryTotal(uint64_t* memory_total) override; | 37 void PollFastMemoryTotal(uint64_t* memory_total) override; |
38 void SuspendFastMemoryPolling() override; | 38 void SuspendFastMemoryPolling() override; |
39 | 39 |
| 40 protected: |
| 41 ProcessMetricsMemoryDumpProvider(base::ProcessId process); |
| 42 |
40 private: | 43 private: |
| 44 using FactoryFunction = |
| 45 std::unique_ptr<ProcessMetricsMemoryDumpProvider> (*)(base::ProcessId); |
| 46 |
41 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, | 47 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, |
42 ParseProcSmaps); | 48 ParseProcSmaps); |
43 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, DumpRSS); | 49 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, DumpRSS); |
44 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, | 50 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, |
45 TestPollFastMemoryTotal); | 51 TestPollFastMemoryTotal); |
46 #if defined(OS_MACOSX) | 52 #if defined(OS_MACOSX) |
47 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, | 53 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, |
48 TestMachOReading); | 54 TestMachOReading); |
49 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, | 55 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, |
50 NoDuplicateRegions); | 56 NoDuplicateRegions); |
51 #elif defined(OS_WIN) | 57 #elif defined(OS_WIN) |
52 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, | 58 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, |
53 TestWinModuleReading); | 59 TestWinModuleReading); |
| 60 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
| 61 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, |
| 62 DoubleRegister); |
54 #endif | 63 #endif |
55 | 64 |
56 ProcessMetricsMemoryDumpProvider(base::ProcessId process); | |
57 | |
58 bool DumpProcessTotals(const base::trace_event::MemoryDumpArgs& args, | 65 bool DumpProcessTotals(const base::trace_event::MemoryDumpArgs& args, |
59 base::trace_event::ProcessMemoryDump* pmd); | 66 base::trace_event::ProcessMemoryDump* pmd); |
60 bool DumpProcessMemoryMaps(const base::trace_event::MemoryDumpArgs& args, | 67 bool DumpProcessMemoryMaps(const base::trace_event::MemoryDumpArgs& args, |
61 base::trace_event::ProcessMemoryDump* pmd); | 68 base::trace_event::ProcessMemoryDump* pmd); |
62 | 69 |
63 static uint64_t rss_bytes_for_testing; | 70 static uint64_t rss_bytes_for_testing; |
| 71 static FactoryFunction factory_for_testing; |
64 | 72 |
65 #if defined(OS_LINUX) || defined(OS_ANDROID) | 73 #if defined(OS_LINUX) || defined(OS_ANDROID) |
66 static FILE* proc_smaps_for_testing; | 74 static FILE* proc_smaps_for_testing; |
67 static int fast_polling_statm_fd_for_testing; | 75 static int fast_polling_statm_fd_for_testing; |
68 | 76 |
69 base::ScopedFD fast_polling_statm_fd_; | 77 base::ScopedFD fast_polling_statm_fd_; |
70 #endif | 78 #endif |
71 | 79 |
72 base::ProcessId process_; | 80 base::ProcessId process_; |
73 std::unique_ptr<base::ProcessMetrics> process_metrics_; | 81 std::unique_ptr<base::ProcessMetrics> process_metrics_; |
74 | 82 |
75 // The peak may not be resettable on all the processes if the linux kernel is | 83 // The peak may not be resettable on all the processes if the linux kernel is |
76 // older than http://bit.ly/reset_rss or only on child processes if yama LSM | 84 // older than http://bit.ly/reset_rss or only on child processes if yama LSM |
77 // sandbox is enabled. | 85 // sandbox is enabled. |
78 bool is_rss_peak_resettable_; | 86 bool is_rss_peak_resettable_; |
79 | 87 |
80 DISALLOW_COPY_AND_ASSIGN(ProcessMetricsMemoryDumpProvider); | 88 DISALLOW_COPY_AND_ASSIGN(ProcessMetricsMemoryDumpProvider); |
81 }; | 89 }; |
82 | 90 |
83 } // namespace tracing | 91 } // namespace tracing |
84 | 92 |
85 #endif // COMPONENTS_TRACING_COMMON_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ | 93 #endif // COMPONENTS_TRACING_COMMON_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ |
OLD | NEW |