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