| 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" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/containers/small_map.h" | 10 #include "base/containers/small_map.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class MemoryDumpSessionState; | 23 class MemoryDumpSessionState; |
| 24 | 24 |
| 25 // ProcessMemoryDump is as a strongly typed container which enforces the data | 25 // ProcessMemoryDump is as a strongly typed container which enforces the data |
| 26 // model for each memory dump and holds the dumps produced by the | 26 // model for each memory dump and holds the dumps produced by the |
| 27 // MemoryDumpProvider(s) for a specific process. | 27 // MemoryDumpProvider(s) for a specific process. |
| 28 // At trace generation time (i.e. when AsValue() is called), ProcessMemoryDump | 28 // At trace generation time (i.e. when AsValue() is called), ProcessMemoryDump |
| 29 // will compose a key-value dictionary of the various dumps obtained at trace | 29 // will compose a key-value dictionary of the various dumps obtained at trace |
| 30 // dump point time. | 30 // dump point time. |
| 31 class BASE_EXPORT ProcessMemoryDump { | 31 class BASE_EXPORT ProcessMemoryDump { |
| 32 public: | 32 public: |
| 33 // Maps allocator dumps absolute names (allocator_name/heap/subheap) to |
| 34 // MemoryAllocatorDump instances. |
| 33 using AllocatorDumpsMap = | 35 using AllocatorDumpsMap = |
| 34 SmallMap<hash_map<std::string, MemoryAllocatorDump*>>; | 36 SmallMap<hash_map<std::string, MemoryAllocatorDump*>>; |
| 35 | 37 |
| 36 ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state); | 38 ProcessMemoryDump(const scoped_refptr<MemoryDumpSessionState>& session_state); |
| 37 ~ProcessMemoryDump(); | 39 ~ProcessMemoryDump(); |
| 38 | 40 |
| 39 // Called at trace generation time to populate the TracedValue. | 41 // Called at trace generation time to populate the TracedValue. |
| 40 void AsValueInto(TracedValue* value) const; | 42 void AsValueInto(TracedValue* value) const; |
| 41 | 43 |
| 42 ProcessMemoryTotals* process_totals() { return &process_totals_; } | 44 ProcessMemoryTotals* process_totals() { return &process_totals_; } |
| 43 bool has_process_totals() const { return has_process_totals_; } | 45 bool has_process_totals() const { return has_process_totals_; } |
| 44 void set_has_process_totals() { has_process_totals_ = true; } | 46 void set_has_process_totals() { has_process_totals_ = true; } |
| 45 | 47 |
| 46 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } | 48 ProcessMemoryMaps* process_mmaps() { return &process_mmaps_; } |
| 47 bool has_process_mmaps() const { return has_process_mmaps_; } | 49 bool has_process_mmaps() const { return has_process_mmaps_; } |
| 48 void set_has_process_mmaps() { has_process_mmaps_ = true; } | 50 void set_has_process_mmaps() { has_process_mmaps_ = true; } |
| 49 | 51 |
| 50 // Creates a new MemoryAllocatorDump with the given name and returns the | 52 // Creates a new MemoryAllocatorDump with the given name and returns the |
| 51 // empty object back to the caller. The |name| must be unique in the dump. | 53 // empty object back to the caller. |
| 52 // ProcessMemoryDump handles the memory ownership of the created object. | 54 // Arguments: |
| 53 // |parent| can be used to specify a hierarchical relationship of the | 55 // allocator_name: a name that univocally identifies allocator dumps |
| 54 // allocator dumps. | 56 // produced by this provider. It acts as a type w.r.t. the allocator |
| 55 MemoryAllocatorDump* CreateAllocatorDump(const std::string& name); | 57 // attributes, in the sense that all the MAD with the same allocator_name |
| 56 MemoryAllocatorDump* CreateAllocatorDump(const std::string& name, | 58 // are expected to have the same attributes. |
| 57 MemoryAllocatorDump* parent); | 59 // heap_name, either: |
| 60 // - kRootHeap: if the allocator has only one default heap. |
| 61 // - a string identifing a heap name (e.g., isolate1, isolate2 ...). It is |
| 62 // possible to specify nesting by using a path-like string (e.g., |
| 63 // isolate1/heap_spaceX, isolate1/heap_spaceY, isolate2/heap_spaceX). |
| 64 // The tuple (|allocator_name|, |heap_name|) is unique inside a PMD. |
| 65 // ProcessMemoryDump handles the memory ownership of its MemoryAllocatorDumps. |
| 66 MemoryAllocatorDump* CreateAllocatorDump(const std::string& allocator_name, |
| 67 const std::string& heap_name); |
| 58 | 68 |
| 59 // Returns a MemoryAllocatorDump given its name or nullptr if not found. | 69 // Looks up a MemoryAllocatorDump given its allocator and heap names, or |
| 60 MemoryAllocatorDump* GetAllocatorDump(const std::string& name) const; | 70 // nullptr if not found. |
| 71 MemoryAllocatorDump* GetAllocatorDump(const std::string& allocator_name, |
| 72 const std::string& heap_name) const; |
| 61 | 73 |
| 62 // Returns the map of the MemoryAllocatorDumps added to this dump. | 74 // Returns the map of the MemoryAllocatorDumps added to this dump. |
| 63 const AllocatorDumpsMap& allocator_dumps() const { return allocator_dumps_; } | 75 const AllocatorDumpsMap& allocator_dumps() const { return allocator_dumps_; } |
| 64 | 76 |
| 65 const scoped_refptr<MemoryDumpSessionState>& session_state() const { | 77 const scoped_refptr<MemoryDumpSessionState>& session_state() const { |
| 66 return session_state_; | 78 return session_state_; |
| 67 } | 79 } |
| 68 | 80 |
| 69 private: | 81 private: |
| 70 ProcessMemoryTotals process_totals_; | 82 ProcessMemoryTotals process_totals_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 // State shared among all PMDs instances created in a given trace session. | 93 // State shared among all PMDs instances created in a given trace session. |
| 82 scoped_refptr<MemoryDumpSessionState> session_state_; | 94 scoped_refptr<MemoryDumpSessionState> session_state_; |
| 83 | 95 |
| 84 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); | 96 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDump); |
| 85 }; | 97 }; |
| 86 | 98 |
| 87 } // namespace trace_event | 99 } // namespace trace_event |
| 88 } // namespace base | 100 } // namespace base |
| 89 | 101 |
| 90 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ | 102 #endif // BASE_TRACE_EVENT_PROCESS_MEMORY_DUMP_H_ |
| OLD | NEW |