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