| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_TRACING_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ | |
| 6 #define COMPONENTS_TRACING_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/gtest_prod_util.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/process/process_handle.h" | |
| 13 #include "base/trace_event/memory_dump_provider.h" | |
| 14 #include "build/build_config.h" | |
| 15 #include "components/tracing/tracing_export.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class ProcessMetrics; | |
| 19 } | |
| 20 | |
| 21 namespace tracing { | |
| 22 | |
| 23 // Dump provider which collects process-wide memory stats. | |
| 24 class TRACING_EXPORT ProcessMetricsMemoryDumpProvider | |
| 25 : public base::trace_event::MemoryDumpProvider { | |
| 26 public: | |
| 27 // Pass base::kNullProcessId to register for current process. | |
| 28 static void RegisterForProcess(base::ProcessId process); | |
| 29 static void UnregisterForProcess(base::ProcessId process); | |
| 30 | |
| 31 ~ProcessMetricsMemoryDumpProvider() override; | |
| 32 | |
| 33 // MemoryDumpProvider implementation. | |
| 34 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | |
| 35 base::trace_event::ProcessMemoryDump* pmd) override; | |
| 36 | |
| 37 private: | |
| 38 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, | |
| 39 ParseProcSmaps); | |
| 40 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, DumpRSS); | |
| 41 | |
| 42 ProcessMetricsMemoryDumpProvider(base::ProcessId process); | |
| 43 | |
| 44 bool DumpProcessTotals(const base::trace_event::MemoryDumpArgs& args, | |
| 45 base::trace_event::ProcessMemoryDump* pmd); | |
| 46 bool DumpProcessMemoryMaps(const base::trace_event::MemoryDumpArgs& args, | |
| 47 base::trace_event::ProcessMemoryDump* pmd); | |
| 48 | |
| 49 static uint64_t rss_bytes_for_testing; | |
| 50 | |
| 51 #if defined(OS_LINUX) || defined(OS_ANDROID) | |
| 52 static FILE* proc_smaps_for_testing; | |
| 53 #endif | |
| 54 | |
| 55 base::ProcessId process_; | |
| 56 std::unique_ptr<base::ProcessMetrics> process_metrics_; | |
| 57 | |
| 58 // The peak may not be resettable on all the processes if the linux kernel is | |
| 59 // older than http://bit.ly/reset_rss or only on child processes if yama LSM | |
| 60 // sandbox is enabled. | |
| 61 bool is_rss_peak_resettable_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(ProcessMetricsMemoryDumpProvider); | |
| 64 }; | |
| 65 | |
| 66 } // namespace tracing | |
| 67 | |
| 68 #endif // COMPONENTS_TRACING_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ | |
| OLD | NEW |