| 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_PROVIDER_H_ | 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ |
| 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ | 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 11 #include "base/trace_event/memory_dump_request_args.h" | 11 #include "base/trace_event/memory_dump_request_args.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 namespace trace_event { | 14 namespace trace_event { |
| 15 | 15 |
| 16 class ProcessMemoryDump; | 16 class ProcessMemoryDump; |
| 17 | 17 |
| 18 // Args passed to OnMemoryDump(). This is to avoid rewriting all the subclasses | 18 // Args passed to OnMemoryDump(). This is to avoid rewriting all the subclasses |
| 19 // in the codebase when extending the MemoryDumpProvider API. | 19 // in the codebase when extending the MemoryDumpProvider API. |
| 20 struct MemoryDumpArgs { | 20 struct MemoryDumpArgs { |
| 21 MemoryDumpLevelOfDetail level_of_detail; | 21 MemoryDumpLevelOfDetail level_of_detail; |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 // The contract interface that memory dump providers must implement. | 24 // The contract interface that memory dump providers must implement. |
| 25 class BASE_EXPORT MemoryDumpProvider { | 25 class BASE_EXPORT MemoryDumpProvider { |
| 26 public: | 26 public: |
| 27 // Optional arguments for MemoryDumpManager::RegisterDumpProvider(). | 27 // Optional arguments for MemoryDumpManager::RegisterDumpProvider(). |
| 28 struct Options { | 28 struct Options { |
| 29 Options() : target_pid(kNullProcessId) {} | 29 Options() |
| 30 explicit Options(ProcessId target_pid) : target_pid(target_pid) {} | 30 : target_pid(kNullProcessId), |
| 31 dumps_on_single_thread_task_runner(false) {} |
| 31 | 32 |
| 32 // If the dump provider generates dumps on behalf of another process, | 33 // If the dump provider generates dumps on behalf of another process, |
| 33 // |target_process| contains the pid of that process. | 34 // |target_pid| contains the pid of that process. |
| 34 // The default value is kNullProcessId, which means that the dump provider | 35 // The default value is kNullProcessId, which means that the dump provider |
| 35 // generates dumps for the current process. | 36 // generates dumps for the current process. |
| 36 ProcessId target_pid; | 37 ProcessId target_pid; |
| 38 |
| 39 // |dumps_on_single_thread_task_runner| is true if the dump provider runs on |
| 40 // a SingleThreadTaskRunner, which is usually the case. It is faster to run |
| 41 // all providers that run on the same thread together without thread hops. |
| 42 bool dumps_on_single_thread_task_runner; |
| 37 }; | 43 }; |
| 38 | 44 |
| 39 virtual ~MemoryDumpProvider() {} | 45 virtual ~MemoryDumpProvider() {} |
| 40 | 46 |
| 41 // Called by the MemoryDumpManager when generating memory dumps. | 47 // Called by the MemoryDumpManager when generating memory dumps. |
| 42 // The |args| specify if the embedder should generate light/heavy dumps on | 48 // The |args| specify if the embedder should generate light/heavy dumps on |
| 43 // dump requests. The embedder should return true if the |pmd| was | 49 // dump requests. The embedder should return true if the |pmd| was |
| 44 // successfully populated, false if something went wrong and the dump should | 50 // successfully populated, false if something went wrong and the dump should |
| 45 // be considered invalid. | 51 // be considered invalid. |
| 46 // (Note, the MemoryDumpManager has a fail-safe logic which will disable the | 52 // (Note, the MemoryDumpManager has a fail-safe logic which will disable the |
| 47 // MemoryDumpProvider for the entire trace session if it fails consistently). | 53 // MemoryDumpProvider for the entire trace session if it fails consistently). |
| 48 virtual bool OnMemoryDump(const MemoryDumpArgs& args, | 54 virtual bool OnMemoryDump(const MemoryDumpArgs& args, |
| 49 ProcessMemoryDump* pmd) = 0; | 55 ProcessMemoryDump* pmd) = 0; |
| 50 | 56 |
| 51 // Called by the MemoryDumpManager when an allocator should start or stop | 57 // Called by the MemoryDumpManager when an allocator should start or stop |
| 52 // collecting extensive allocation data, if supported. | 58 // collecting extensive allocation data, if supported. |
| 53 virtual void OnHeapProfilingEnabled(bool enabled) {} | 59 virtual void OnHeapProfilingEnabled(bool enabled) {} |
| 54 | 60 |
| 55 protected: | 61 protected: |
| 56 MemoryDumpProvider() {} | 62 MemoryDumpProvider() {} |
| 57 | 63 |
| 58 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProvider); | 64 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProvider); |
| 59 }; | 65 }; |
| 60 | 66 |
| 61 } // namespace trace_event | 67 } // namespace trace_event |
| 62 } // namespace base | 68 } // namespace base |
| 63 | 69 |
| 64 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ | 70 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ |
| OLD | NEW |