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 BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
6 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 class MemoryDumpManagerDelegate; | 29 class MemoryDumpManagerDelegate; |
30 class MemoryDumpProvider; | 30 class MemoryDumpProvider; |
31 class ProcessMemoryDump; | 31 class ProcessMemoryDump; |
32 class MemoryDumpSessionState; | 32 class MemoryDumpSessionState; |
33 | 33 |
34 // This is the interface exposed to the rest of the codebase to deal with | 34 // This is the interface exposed to the rest of the codebase to deal with |
35 // memory tracing. The main entry point for clients is represented by | 35 // memory tracing. The main entry point for clients is represented by |
36 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). | 36 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
37 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { | 37 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
38 public: | 38 public: |
39 static const int kInvalidTracingProcessId = -1; | |
39 static const char* const kTraceCategoryForTesting; | 40 static const char* const kTraceCategoryForTesting; |
40 | 41 |
41 static MemoryDumpManager* GetInstance(); | 42 static MemoryDumpManager* GetInstance(); |
42 | 43 |
43 // Invoked once per process to register the TraceLog observer. | 44 // Invoked once per process to register the TraceLog observer. |
44 void Initialize(); | 45 void Initialize(); |
45 | 46 |
46 // See the lifetime and thread-safety requirements on the delegate below in | 47 // See the lifetime and thread-safety requirements on the delegate below in |
47 // the |MemoryDumpManagerDelegate| docstring. | 48 // the |MemoryDumpManagerDelegate| docstring. |
48 void SetDelegate(MemoryDumpManagerDelegate* delegate); | 49 void SetDelegate(MemoryDumpManagerDelegate* delegate); |
(...skipping 25 matching lines...) Expand all Loading... | |
74 void OnTraceLogEnabled() override; | 75 void OnTraceLogEnabled() override; |
75 void OnTraceLogDisabled() override; | 76 void OnTraceLogDisabled() override; |
76 | 77 |
77 // Returns the MemoryDumpSessionState object, which is shared by all the | 78 // Returns the MemoryDumpSessionState object, which is shared by all the |
78 // ProcessMemoryDump and MemoryAllocatorDump instances through all the tracing | 79 // ProcessMemoryDump and MemoryAllocatorDump instances through all the tracing |
79 // session lifetime. | 80 // session lifetime. |
80 const scoped_refptr<MemoryDumpSessionState>& session_state() const { | 81 const scoped_refptr<MemoryDumpSessionState>& session_state() const { |
81 return session_state_; | 82 return session_state_; |
82 } | 83 } |
83 | 84 |
85 // This is used by browser to hash child id to get the tracing_process_id | |
Primiano Tucci (use gerrit)
2015/06/24 09:31:00
Add the following comment here
// Derives a traci
| |
86 // for child. | |
87 static int ChildProcessIdToTracingProcessId(int child_id); | |
88 | |
89 int tracing_process_id() const { | |
Primiano Tucci (use gerrit)
2015/06/24 09:31:00
Add a comment saying:
// Returns a unique id for
| |
90 // This cannot be requested out of scope of a trace. | |
91 DCHECK_NE(tracing_process_id_, kInvalidTracingProcessId); | |
92 return tracing_process_id_; | |
93 } | |
94 | |
84 private: | 95 private: |
85 // Descriptor struct used to hold information about registered MDPs. It is | 96 // Descriptor struct used to hold information about registered MDPs. It is |
86 // deliberately copyable, in order to allow to be used as hash_map value. | 97 // deliberately copyable, in order to allow to be used as hash_map value. |
87 struct MemoryDumpProviderInfo { | 98 struct MemoryDumpProviderInfo { |
88 MemoryDumpProviderInfo( | 99 MemoryDumpProviderInfo( |
89 const scoped_refptr<SingleThreadTaskRunner>& task_runner); | 100 const scoped_refptr<SingleThreadTaskRunner>& task_runner); |
90 ~MemoryDumpProviderInfo(); | 101 ~MemoryDumpProviderInfo(); |
91 | 102 |
92 scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional. | 103 scoped_refptr<SingleThreadTaskRunner> task_runner; // Optional. |
93 int consecutive_failures; // Number of times the provider failed (to | 104 int consecutive_failures; // Number of times the provider failed (to |
(...skipping 20 matching lines...) Expand all Loading... | |
114 // thread on which CreateProcessDump() was called. | 125 // thread on which CreateProcessDump() was called. |
115 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 126 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
116 const MemoryDumpCallback& callback); | 127 const MemoryDumpCallback& callback); |
117 | 128 |
118 bool InvokeDumpProviderLocked(MemoryDumpProvider* mdp, | 129 bool InvokeDumpProviderLocked(MemoryDumpProvider* mdp, |
119 ProcessMemoryDump* pmd); | 130 ProcessMemoryDump* pmd); |
120 void ContinueAsyncProcessDump( | 131 void ContinueAsyncProcessDump( |
121 MemoryDumpProvider* mdp, | 132 MemoryDumpProvider* mdp, |
122 scoped_refptr<ProcessMemoryDumpHolder> pmd_holder); | 133 scoped_refptr<ProcessMemoryDumpHolder> pmd_holder); |
123 | 134 |
135 // Pass kInvalidTracingProcessId for invalidating the id. | |
136 void set_tracing_process_id(int id) { | |
137 DCHECK(tracing_process_id_ == kInvalidTracingProcessId || | |
138 id == kInvalidTracingProcessId); | |
139 tracing_process_id_ = id; | |
140 } | |
141 | |
124 hash_map<MemoryDumpProvider*, MemoryDumpProviderInfo> dump_providers_; | 142 hash_map<MemoryDumpProvider*, MemoryDumpProviderInfo> dump_providers_; |
125 | 143 |
126 // Shared among all the PMDs to keep state scoped to the tracing session. | 144 // Shared among all the PMDs to keep state scoped to the tracing session. |
127 scoped_refptr<MemoryDumpSessionState> session_state_; | 145 scoped_refptr<MemoryDumpSessionState> session_state_; |
128 | 146 |
129 MemoryDumpManagerDelegate* delegate_; // Not owned. | 147 MemoryDumpManagerDelegate* delegate_; // Not owned. |
130 | 148 |
131 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| | 149 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| |
132 // to guard against disabling logging while dumping on another thread. | 150 // to guard against disabling logging while dumping on another thread. |
133 Lock lock_; | 151 Lock lock_; |
134 | 152 |
135 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty | 153 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty |
136 // dump_providers_enabled_ list) when tracing is not enabled. | 154 // dump_providers_enabled_ list) when tracing is not enabled. |
137 subtle::AtomicWord memory_tracing_enabled_; | 155 subtle::AtomicWord memory_tracing_enabled_; |
138 | 156 |
139 // For time-triggered periodic dumps. | 157 // For time-triggered periodic dumps. |
140 RepeatingTimer<MemoryDumpManager> periodic_dump_timer_; | 158 RepeatingTimer<MemoryDumpManager> periodic_dump_timer_; |
141 | 159 |
160 // The unique id of the child process. This is created only for tracing and is | |
161 // expected to be valid only when tracing is enabled. | |
162 int tracing_process_id_; | |
163 | |
142 // Skips the auto-registration of the core dumpers during Initialize(). | 164 // Skips the auto-registration of the core dumpers during Initialize(). |
143 bool skip_core_dumpers_auto_registration_for_testing_; | 165 bool skip_core_dumpers_auto_registration_for_testing_; |
144 | 166 |
145 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); | 167 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManager); |
146 }; | 168 }; |
147 | 169 |
148 // The delegate is supposed to be long lived (read: a Singleton) and thread | 170 // The delegate is supposed to be long lived (read: a Singleton) and thread |
149 // safe (i.e. should expect calls from any thread and handle thread hopping). | 171 // safe (i.e. should expect calls from any thread and handle thread hopping). |
150 class BASE_EXPORT MemoryDumpManagerDelegate { | 172 class BASE_EXPORT MemoryDumpManagerDelegate { |
151 public: | 173 public: |
152 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, | 174 virtual void RequestGlobalMemoryDump(const MemoryDumpRequestArgs& args, |
153 const MemoryDumpCallback& callback) = 0; | 175 const MemoryDumpCallback& callback) = 0; |
154 | 176 |
155 // Determines whether the MemoryDumpManager instance should be the master | 177 // Determines whether the MemoryDumpManager instance should be the master |
156 // (the ones which initiates and coordinates the multiprocess dumps) or not. | 178 // (the ones which initiates and coordinates the multiprocess dumps) or not. |
157 virtual bool IsCoordinatorProcess() const = 0; | 179 virtual bool IsCoordinatorProcess() const = 0; |
158 | 180 |
159 protected: | 181 protected: |
160 MemoryDumpManagerDelegate() {} | 182 MemoryDumpManagerDelegate() {} |
161 virtual ~MemoryDumpManagerDelegate() {} | 183 virtual ~MemoryDumpManagerDelegate() {} |
162 | 184 |
163 void CreateProcessDump(const MemoryDumpRequestArgs& args, | 185 void CreateProcessDump(const MemoryDumpRequestArgs& args, |
164 const MemoryDumpCallback& callback) { | 186 const MemoryDumpCallback& callback) { |
165 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); | 187 MemoryDumpManager::GetInstance()->CreateProcessDump(args, callback); |
166 } | 188 } |
167 | 189 |
190 void set_tracing_process_id(int id) { | |
191 MemoryDumpManager::GetInstance()->set_tracing_process_id(id); | |
192 } | |
193 | |
168 private: | 194 private: |
169 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 195 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
170 }; | 196 }; |
171 | 197 |
172 } // namespace trace_event | 198 } // namespace trace_event |
173 } // namespace base | 199 } // namespace base |
174 | 200 |
175 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 201 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
OLD | NEW |