xref: /aosp_15_r20/external/cronet/base/trace_event/memory_dump_provider.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2015 The Chromium Authors
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/process/process_handle.h"
10 #include "base/trace_event/memory_dump_request_args.h"
11 
12 namespace base {
13 namespace trace_event {
14 
15 class ProcessMemoryDump;
16 
17 // The contract interface that memory dump providers must implement.
18 class BASE_EXPORT MemoryDumpProvider {
19  public:
20   // Optional arguments for MemoryDumpManager::RegisterDumpProvider().
21   struct Options {
OptionsOptions22     Options() : dumps_on_single_thread_task_runner(false) {}
23 
24     // |dumps_on_single_thread_task_runner| is true if the dump provider runs on
25     // a SingleThreadTaskRunner, which is usually the case. It is faster to run
26     // all providers that run on the same thread together without thread hops.
27     bool dumps_on_single_thread_task_runner;
28   };
29 
30   MemoryDumpProvider(const MemoryDumpProvider&) = delete;
31   MemoryDumpProvider& operator=(const MemoryDumpProvider&) = delete;
32   virtual ~MemoryDumpProvider() = default;
33 
34   // Called by the MemoryDumpManager when generating memory dumps.
35   // The |args| specify if the embedder should generate light/heavy dumps on
36   // dump requests. The embedder should return true if the |pmd| was
37   // successfully populated, false if something went wrong and the dump should
38   // be considered invalid.
39   // (Note, the MemoryDumpManager has a fail-safe logic which will disable the
40   // MemoryDumpProvider for the entire trace session if it fails consistently).
41   virtual bool OnMemoryDump(const MemoryDumpArgs& args,
42                             ProcessMemoryDump* pmd) = 0;
43 
44  protected:
45   MemoryDumpProvider() = default;
46 };
47 
48 }  // namespace trace_event
49 }  // namespace base
50 
51 #endif  // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_
52