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 is_fast_polling_supported(false) {} 27 28 // If the dump provider generates dumps on behalf of another process, 29 // |target_pid| contains the pid of that process. 30 // The default value is kNullProcessId, which means that the dump provider 31 // generates dumps for the current process. 32 ProcessId target_pid; 33 34 // |dumps_on_single_thread_task_runner| is true if the dump provider runs on 35 // a SingleThreadTaskRunner, which is usually the case. It is faster to run 36 // all providers that run on the same thread together without thread hops. 37 bool dumps_on_single_thread_task_runner; 38 39 // Set to true if the dump provider implementation supports high frequency 40 // polling. Only providers running without task runner affinity are 41 // supported. 42 bool is_fast_polling_supported; 43 }; 44 ~MemoryDumpProvider()45 virtual ~MemoryDumpProvider() {} 46 47 // Called by the MemoryDumpManager when generating memory dumps. 48 // The |args| specify if the embedder should generate light/heavy dumps on 49 // dump requests. The embedder should return true if the |pmd| was 50 // successfully populated, false if something went wrong and the dump should 51 // be considered invalid. 52 // (Note, the MemoryDumpManager has a fail-safe logic which will disable the 53 // MemoryDumpProvider for the entire trace session if it fails consistently). 54 virtual bool OnMemoryDump(const MemoryDumpArgs& args, 55 ProcessMemoryDump* pmd) = 0; 56 57 // Called by the MemoryDumpManager when an allocator should start or stop 58 // collecting extensive allocation data, if supported. OnHeapProfilingEnabled(bool enabled)59 virtual void OnHeapProfilingEnabled(bool enabled) {} 60 61 // Quickly record the total memory usage in |memory_total|. This method will 62 // be called only when the dump provider registration has 63 // |is_fast_polling_supported| set to true. This method is used for polling at 64 // high frequency for detecting peaks. See comment on 65 // |is_fast_polling_supported| option if you need to override this method. PollFastMemoryTotal(uint64_t * memory_total)66 virtual void PollFastMemoryTotal(uint64_t* memory_total) {} 67 68 // Indicates that fast memory polling is not going to be used in the near 69 // future and the MDP can tear down any resource kept around for fast memory 70 // polling. SuspendFastMemoryPolling()71 virtual void SuspendFastMemoryPolling() {} 72 73 protected: MemoryDumpProvider()74 MemoryDumpProvider() {} 75 76 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProvider); 77 }; 78 79 } // namespace trace_event 80 } // namespace base 81 82 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ 83