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_PROCESS_MEMORY_DUMP_H_ | 5 #ifndef BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
6 #define BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ | 6 #define BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
7 | 7 |
8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/containers/small_map.h" |
| 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/trace_event/memory_allocator_dump.h" |
9 #include "base/trace_event/process_memory_maps.h" | 13 #include "base/trace_event/process_memory_maps.h" |
10 #include "base/trace_event/process_memory_totals.h" | 14 #include "base/trace_event/process_memory_totals.h" |
11 | 15 |
12 namespace base { | 16 namespace base { |
13 namespace trace_event { | 17 namespace trace_event { |
14 | 18 |
15 class ConvertableToTraceFormat; | 19 class ConvertableToTraceFormat; |
| 20 class MemoryDumpManager; |
16 | 21 |
17 // ProcessMemoryDump is as a strongly typed container which enforces the data | 22 // ProcessMemoryDump is as a strongly typed container which enforces the data |
18 // model for each memory dump point and holds the dumps produced by the | 23 // model for each memory dump point and holds the dumps produced by the |
19 // MemoryDumpProvider(s) for a specific process. | 24 // MemoryDumpProvider(s) for a specific process. |
20 // At trace generation time (i.e. when AsValue() is called), ProcessMemoryDump | 25 // At trace generation time (i.e. when AsValue() is called), ProcessMemoryDump |
21 // will compose a key-value dictionary of the various dumps obtained at trace | 26 // will compose a key-value dictionary of the various dumps obtained at trace |
22 // dump point time. | 27 // dump point time. |
23 class BASE_EXPORT ProcessMemoryDump { | 28 class BASE_EXPORT ProcessMemoryDump { |
24 public: | 29 public: |
| 30 using AllocatorDumpsMap = |
| 31 SmallMap<hash_map<std::string, MemoryAllocatorDump*>>; |
| 32 |
25 ProcessMemoryDump(); | 33 ProcessMemoryDump(); |
26 ~ProcessMemoryDump(); | 34 ~ProcessMemoryDump(); |
27 | 35 |
28 // Called at trace generation time to populate the TracedValue. | 36 // Called at trace generation time to populate the TracedValue. |
29 void AsValueInto(TracedValue* value) const; | 37 void AsValueInto(TracedValue* value) const; |
30 | 38 |
31 ProcessMemoryTotals* process_totals() { return &process_totals_; } | 39 ProcessMemoryTotals* process_totals() { return &process_totals_; } |
32 bool has_process_totals() const { return has_process_totals_; } | 40 bool has_process_totals() const { return has_process_totals_; } |
33 void set_has_process_totals() { has_process_totals_ = true; } | 41 void set_has_process_totals() { has_process_totals_ = true; } |
34 | 42 |
35 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } | 43 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } |
36 bool has_process_mmaps() const { return has_process_mmaps_; } | 44 bool has_process_mmaps() const { return has_process_mmaps_; } |
37 void set_has_process_mmaps() { has_process_mmaps_ = true; } | 45 void set_has_process_mmaps() { has_process_mmaps_ = true; } |
38 | 46 |
| 47 // Creates a new MemoryAllocatorDump with the given name and returns the |
| 48 // empty object back to the caller. The |name| must be unique in the dump. |
| 49 // ProcessMemoryDump handles the memory ownership of the created object. |
| 50 // |parent| can be used to specify a hierarchical relationship of the |
| 51 // allocator dumps. |
| 52 MemoryAllocatorDump* CreateAllocatorDump(const std::string& name); |
| 53 MemoryAllocatorDump* CreateAllocatorDump(const std::string& name, |
| 54 MemoryAllocatorDump* parent); |
| 55 |
| 56 // Returns a MemoryAllocatorDump given its name or nullptr if not found. |
| 57 MemoryAllocatorDump* GetAllocatorDump(const std::string& name) const; |
| 58 |
| 59 // Returns the map of the MemoryAllocatorDumps added to this dump. |
| 60 const AllocatorDumpsMap& allocator_dumps() const { return allocator_dumps_; } |
| 61 |
39 private: | 62 private: |
40 ProcessMemoryTotals process_totals_; | 63 ProcessMemoryTotals process_totals_; |
41 bool has_process_totals_; | 64 bool has_process_totals_; |
42 | 65 |
43 ProcessMemoryMaps process_mmaps_; | 66 ProcessMemoryMaps process_mmaps_; |
44 bool has_process_mmaps_; | 67 bool has_process_mmaps_; |
45 | 68 |
| 69 // A maps of "allocator_name" -> MemoryAllocatorDump populated by |
| 70 // allocator dump providers. |
| 71 AllocatorDumpsMap allocator_dumps_; |
| 72 |
| 73 // ProcessMemoryDump handles the memory ownership of all its belongings. |
| 74 ScopedVector<MemoryAllocatorDump> allocator_dumps_storage_; |
| 75 |
46 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); | 76 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); |
47 }; | 77 }; |
48 | 78 |
49 } // namespace trace_event | 79 } // namespace trace_event |
50 } // namespace base | 80 } // namespace base |
51 | 81 |
52 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ | 82 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
OLD | NEW |