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

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

Issue 2753723003: Fix crash in InvokeOnMemoryDump when tracing (Closed)
Patch Set: be more explicit 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 #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
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);
52 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest,
53 DoubleRegister);
46 #if defined(OS_MACOSX) 54 #if defined(OS_MACOSX)
47 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, 55 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest,
48 TestMachOReading); 56 TestMachOReading);
49 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, 57 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest,
50 NoDuplicateRegions); 58 NoDuplicateRegions);
51 #elif defined(OS_WIN) 59 #elif defined(OS_WIN)
52 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest, 60 FRIEND_TEST_ALL_PREFIXES(ProcessMetricsMemoryDumpProviderTest,
53 TestWinModuleReading); 61 TestWinModuleReading);
54 #endif 62 #endif
55 63
56 ProcessMetricsMemoryDumpProvider(base::ProcessId process);
57
58 bool DumpProcessTotals(const base::trace_event::MemoryDumpArgs& args, 64 bool DumpProcessTotals(const base::trace_event::MemoryDumpArgs& args,
59 base::trace_event::ProcessMemoryDump* pmd); 65 base::trace_event::ProcessMemoryDump* pmd);
60 bool DumpProcessMemoryMaps(const base::trace_event::MemoryDumpArgs& args, 66 bool DumpProcessMemoryMaps(const base::trace_event::MemoryDumpArgs& args,
61 base::trace_event::ProcessMemoryDump* pmd); 67 base::trace_event::ProcessMemoryDump* pmd);
62 68
63 static uint64_t rss_bytes_for_testing; 69 static uint64_t rss_bytes_for_testing;
70 static FactoryFunction factory_for_testing;
71 static std::unique_ptr<ProcessMetricsMemoryDumpProvider>
72 CreateMetricsProvider(base::ProcessId process);
64 73
65 #if defined(OS_LINUX) || defined(OS_ANDROID) 74 #if defined(OS_LINUX) || defined(OS_ANDROID)
66 static FILE* proc_smaps_for_testing; 75 static FILE* proc_smaps_for_testing;
67 static int fast_polling_statm_fd_for_testing; 76 static int fast_polling_statm_fd_for_testing;
68 77
69 base::ScopedFD fast_polling_statm_fd_; 78 base::ScopedFD fast_polling_statm_fd_;
70 #endif 79 #endif
71 80
72 base::ProcessId process_; 81 base::ProcessId process_;
73 std::unique_ptr<base::ProcessMetrics> process_metrics_; 82 std::unique_ptr<base::ProcessMetrics> process_metrics_;
74 83
75 // The peak may not be resettable on all the processes if the linux kernel is 84 // 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 85 // older than http://bit.ly/reset_rss or only on child processes if yama LSM
77 // sandbox is enabled. 86 // sandbox is enabled.
78 bool is_rss_peak_resettable_; 87 bool is_rss_peak_resettable_;
79 88
80 DISALLOW_COPY_AND_ASSIGN(ProcessMetricsMemoryDumpProvider); 89 DISALLOW_COPY_AND_ASSIGN(ProcessMetricsMemoryDumpProvider);
81 }; 90 };
82 91
83 } // namespace tracing 92 } // namespace tracing
84 93
85 #endif // COMPONENTS_TRACING_COMMON_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_ 94 #endif // COMPONENTS_TRACING_COMMON_PROCESS_MEMORY_METRICS_DUMP_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698