| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 namespace base { | 35 namespace base { |
| 36 | 36 |
| 37 class SingleThreadTaskRunner; | 37 class SingleThreadTaskRunner; |
| 38 class Thread; | 38 class Thread; |
| 39 | 39 |
| 40 namespace trace_event { | 40 namespace trace_event { |
| 41 | 41 |
| 42 class MemoryDumpManagerDelegate; | 42 class MemoryDumpManagerDelegate; |
| 43 class MemoryDumpProvider; | 43 class MemoryDumpProvider; |
| 44 class MemoryDumpSessionState; | 44 class MemoryDumpSessionState; |
| 45 class MemoryDumpScheduler; | |
| 46 | 45 |
| 47 // This is the interface exposed to the rest of the codebase to deal with | 46 // This is the interface exposed to the rest of the codebase to deal with |
| 48 // memory tracing. The main entry point for clients is represented by | 47 // memory tracing. The main entry point for clients is represented by |
| 49 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). | 48 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). |
| 50 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { | 49 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { |
| 51 public: | 50 public: |
| 52 static const char* const kTraceCategory; | 51 static const char* const kTraceCategory; |
| 53 static const char* const kLogPrefix; | 52 static const char* const kLogPrefix; |
| 54 | 53 |
| 55 // This value is returned as the tracing id of the child processes by | 54 // This value is returned as the tracing id of the child processes by |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. | 160 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. |
| 162 void set_dumper_registrations_ignored_for_testing(bool ignored) { | 161 void set_dumper_registrations_ignored_for_testing(bool ignored) { |
| 163 dumper_registrations_ignored_for_testing_ = ignored; | 162 dumper_registrations_ignored_for_testing_ = ignored; |
| 164 } | 163 } |
| 165 | 164 |
| 166 private: | 165 private: |
| 167 friend std::default_delete<MemoryDumpManager>; // For the testing instance. | 166 friend std::default_delete<MemoryDumpManager>; // For the testing instance. |
| 168 friend struct DefaultSingletonTraits<MemoryDumpManager>; | 167 friend struct DefaultSingletonTraits<MemoryDumpManager>; |
| 169 friend class MemoryDumpManagerDelegate; | 168 friend class MemoryDumpManagerDelegate; |
| 170 friend class MemoryDumpManagerTest; | 169 friend class MemoryDumpManagerTest; |
| 171 friend class MemoryDumpScheduler; | |
| 172 friend class memory_instrumentation::MemoryDumpManagerDelegateImplTest; | 170 friend class memory_instrumentation::MemoryDumpManagerDelegateImplTest; |
| 173 | 171 |
| 174 // Holds the state of a process memory dump that needs to be carried over | 172 // Holds the state of a process memory dump that needs to be carried over |
| 175 // across task runners in order to fulfil an asynchronous CreateProcessDump() | 173 // across task runners in order to fulfil an asynchronous CreateProcessDump() |
| 176 // request. At any time exactly one task runner owns a | 174 // request. At any time exactly one task runner owns a |
| 177 // ProcessMemoryDumpAsyncState. | 175 // ProcessMemoryDumpAsyncState. |
| 178 struct ProcessMemoryDumpAsyncState { | 176 struct ProcessMemoryDumpAsyncState { |
| 179 ProcessMemoryDumpAsyncState( | 177 ProcessMemoryDumpAsyncState( |
| 180 MemoryDumpRequestArgs req_args, | 178 MemoryDumpRequestArgs req_args, |
| 181 const MemoryDumpProviderInfo::OrderedSet& dump_providers, | 179 const MemoryDumpProviderInfo::OrderedSet& dump_providers, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // the MDP while registration. On failure to do so, skips and continues to | 248 // the MDP while registration. On failure to do so, skips and continues to |
| 251 // next MDP. | 249 // next MDP. |
| 252 void SetupNextMemoryDump( | 250 void SetupNextMemoryDump( |
| 253 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); | 251 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); |
| 254 | 252 |
| 255 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at | 253 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at |
| 256 // the end to continue the ProcessMemoryDump. Should be called on the MDP task | 254 // the end to continue the ProcessMemoryDump. Should be called on the MDP task |
| 257 // runner. | 255 // runner. |
| 258 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state); | 256 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state); |
| 259 | 257 |
| 260 // Records a quick total memory usage in |memory_total|. This is used to track | |
| 261 // and detect peaks in the memory usage of the process without having to | |
| 262 // record all data from dump providers. This value is approximate to trade-off | |
| 263 // speed, and not consistent with the rest of the memory-infra metrics. Must | |
| 264 // be called on the dump thread. | |
| 265 // Returns true if |memory_total| was updated by polling at least 1 MDP. | |
| 266 bool PollFastMemoryTotal(uint64_t* memory_total); | |
| 267 | |
| 268 // Helper for RegierDumpProvider* functions. | 258 // Helper for RegierDumpProvider* functions. |
| 269 void RegisterDumpProviderInternal( | 259 void RegisterDumpProviderInternal( |
| 270 MemoryDumpProvider* mdp, | 260 MemoryDumpProvider* mdp, |
| 271 const char* name, | 261 const char* name, |
| 272 scoped_refptr<SequencedTaskRunner> task_runner, | 262 scoped_refptr<SequencedTaskRunner> task_runner, |
| 273 const MemoryDumpProvider::Options& options); | 263 const MemoryDumpProvider::Options& options); |
| 274 | 264 |
| 275 // Helper for the public UnregisterDumpProvider* functions. | 265 // Helper for the public UnregisterDumpProvider* functions. |
| 276 void UnregisterDumpProviderInternal(MemoryDumpProvider* mdp, | 266 void UnregisterDumpProviderInternal(MemoryDumpProvider* mdp, |
| 277 bool take_mdp_ownership_and_delete_async); | 267 bool take_mdp_ownership_and_delete_async); |
| 278 | 268 |
| 279 // Adds / removes provider that supports polling to | 269 // Fills the passed vector with the subset of dump providers which were |
| 280 // |dump_providers_for_polling_|. | 270 // registered with is_fast_polling_supported == true. |
| 281 void RegisterPollingMDPOnDumpThread( | 271 void GetDumpProvidersForPolling( |
| 282 scoped_refptr<MemoryDumpProviderInfo> mdpinfo); | 272 std::vector<scoped_refptr<MemoryDumpProviderInfo>>*); |
| 283 void UnregisterPollingMDPOnDumpThread( | |
| 284 scoped_refptr<MemoryDumpProviderInfo> mdpinfo); | |
| 285 | 273 |
| 286 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by task | 274 // An ordererd set of registered MemoryDumpProviderInfo(s), sorted by task |
| 287 // runner affinity (MDPs belonging to the same task runners are adjacent). | 275 // runner affinity (MDPs belonging to the same task runners are adjacent). |
| 288 MemoryDumpProviderInfo::OrderedSet dump_providers_; | 276 MemoryDumpProviderInfo::OrderedSet dump_providers_; |
| 289 | 277 |
| 290 // A copy of mdpinfo list that support polling. It must be accessed only on | |
| 291 // the dump thread if dump thread exists. | |
| 292 MemoryDumpProviderInfo::OrderedSet dump_providers_for_polling_; | |
| 293 | |
| 294 // Shared among all the PMDs to keep state scoped to the tracing session. | 278 // Shared among all the PMDs to keep state scoped to the tracing session. |
| 295 scoped_refptr<MemoryDumpSessionState> session_state_; | 279 scoped_refptr<MemoryDumpSessionState> session_state_; |
| 296 | 280 |
| 297 // The list of names of dump providers that are blacklisted from strict thread | 281 // The list of names of dump providers that are blacklisted from strict thread |
| 298 // affinity check on unregistration. | 282 // affinity check on unregistration. |
| 299 std::unordered_set<StringPiece, StringPieceHash> | 283 std::unordered_set<StringPiece, StringPieceHash> |
| 300 strict_thread_check_blacklist_; | 284 strict_thread_check_blacklist_; |
| 301 | 285 |
| 302 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; | 286 std::unique_ptr<MemoryDumpManagerDelegate> delegate_; |
| 303 | 287 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 } | 329 } |
| 346 | 330 |
| 347 private: | 331 private: |
| 348 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); | 332 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); |
| 349 }; | 333 }; |
| 350 | 334 |
| 351 } // namespace trace_event | 335 } // namespace trace_event |
| 352 } // namespace base | 336 } // namespace base |
| 353 | 337 |
| 354 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ | 338 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ |
| OLD | NEW |