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/memory/ref_counted.h" | 9 #include "base/macros.h" |
10 #include "base/trace_event/memory_allocator_attributes_type_info.h" | |
11 | 10 |
12 namespace base { | 11 namespace base { |
13 | |
14 class SingleThreadTaskRunner; | |
15 | |
16 namespace trace_event { | 12 namespace trace_event { |
17 | 13 |
18 class ProcessMemoryDump; | 14 class ProcessMemoryDump; |
19 | 15 |
20 // The contract interface that memory dump providers must implement. | 16 // The contract interface that memory dump providers must implement. |
21 class BASE_EXPORT MemoryDumpProvider { | 17 class BASE_EXPORT MemoryDumpProvider { |
22 public: | 18 public: |
23 // Called by the MemoryDumpManager when generating memory dumps. | 19 // Called by the MemoryDumpManager when generating memory dumps. |
24 // Returns: true if the |pmd| was successfully populated, false otherwise. | 20 // The embedder should return true if the |pmd| was successfully populated, |
25 virtual bool DumpInto(ProcessMemoryDump* pmd) = 0; | 21 // false if something went wrong and the dump should be considered invalid. |
26 | 22 // (Note, the MemoryDumpManager has a fail-safe logic which will disable the |
27 virtual const char* GetFriendlyName() const = 0; | 23 // MemoryDumpProvider for the entire trace session if it fails consistently). |
28 | 24 virtual bool OnMemoryDump(ProcessMemoryDump* pmd) = 0; |
29 const MemoryAllocatorAttributesTypeInfo& allocator_attributes_type_info() | |
30 const { | |
31 return allocator_attributes_type_info_; | |
32 } | |
33 | |
34 // The dump provider can specify an optional thread affinity (in its | |
35 // base constructor call). If |task_runner| is non empty, all the calls to | |
36 // DumpInto are guaranteed to be posted to that TaskRunner. | |
37 const scoped_refptr<SingleThreadTaskRunner>& task_runner() const { | |
38 return task_runner_; | |
39 } | |
40 | 25 |
41 protected: | 26 protected: |
42 // Default ctor: the MDP is not bound to any thread (must be a singleton). | 27 MemoryDumpProvider() {} |
43 MemoryDumpProvider(); | 28 virtual ~MemoryDumpProvider() {} |
44 | |
45 // Use this ctor to ensure that DumpInto() is called always on the same thread | |
46 // specified by |task_runner|. | |
47 explicit MemoryDumpProvider( | |
48 const scoped_refptr<SingleThreadTaskRunner>& task_runner); | |
49 | |
50 virtual ~MemoryDumpProvider(); | |
51 | |
52 void DeclareAllocatorAttribute(const std::string& allocator_name, | |
53 const std::string& attribute_name, | |
54 const std::string& attribute_type); | |
55 | |
56 private: | |
57 // A map of attributes types (declared through DeclareAllocatorAttribute()) | |
58 // emitted by this allocator dumper. | |
59 MemoryAllocatorAttributesTypeInfo allocator_attributes_type_info_; | |
60 | |
61 // (Optional) TaskRunner on which the DumpInfo call should be posted. | |
62 scoped_refptr<SingleThreadTaskRunner> task_runner_; | |
63 | 29 |
64 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProvider); | 30 DISALLOW_COPY_AND_ASSIGN(MemoryDumpProvider); |
65 }; | 31 }; |
66 | 32 |
67 } // namespace trace_event | 33 } // namespace trace_event |
68 } // namespace base | 34 } // namespace base |
69 | 35 |
70 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ | 36 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_PROVIDER_H_ |
OLD | NEW |