| 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_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ | 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
| 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ | 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/base_export.h" | 13 #include "base/base_export.h" |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/trace_event/heap_profiler_allocation_context.h" | 16 #include "base/trace_event/heap_profiler_allocation_context.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 namespace trace_event { | 19 namespace trace_event { |
| 20 | 20 |
| 21 class MemoryDumpSessionState; |
| 21 class StackFrameDeduplicator; | 22 class StackFrameDeduplicator; |
| 22 class TracedValue; | 23 class TracedValue; |
| 23 class TypeNameDeduplicator; | 24 class TypeNameDeduplicator; |
| 24 | 25 |
| 25 // Aggregates |metrics_by_context|, recursively breaks down the heap, and | 26 // Aggregates |metrics_by_context|, recursively breaks down the heap, and |
| 26 // returns a traced value with an "entries" array that can be dumped in the | 27 // returns a traced value with an "entries" array that can be dumped in the |
| 27 // trace log, following the format described in https://goo.gl/KY7zVE. The | 28 // trace log, following the format described in https://goo.gl/KY7zVE. The |
| 28 // number of entries is kept reasonable because long tails are not included. | 29 // number of entries is kept reasonable because long tails are not included. |
| 29 BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapDump( | 30 BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapDump( |
| 30 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context, | 31 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context, |
| 31 StackFrameDeduplicator* stack_frame_deduplicator, | 32 const MemoryDumpSessionState& session_state); |
| 32 TypeNameDeduplicator* type_name_deduplicator); | |
| 33 | 33 |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 struct Bucket; | 37 struct Bucket; |
| 38 } | 38 } |
| 39 | 39 |
| 40 // An entry in the "entries" array as described in https://goo.gl/KY7zVE. | 40 // An entry in the "entries" array as described in https://goo.gl/KY7zVE. |
| 41 struct BASE_EXPORT Entry { | 41 struct BASE_EXPORT Entry { |
| 42 size_t size; | 42 size_t size; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 55 BASE_EXPORT bool operator<(Entry lhs, Entry rhs); | 55 BASE_EXPORT bool operator<(Entry lhs, Entry rhs); |
| 56 | 56 |
| 57 // Serializes entries to an "entries" array in a traced value. | 57 // Serializes entries to an "entries" array in a traced value. |
| 58 BASE_EXPORT std::unique_ptr<TracedValue> Serialize(const std::set<Entry>& dump); | 58 BASE_EXPORT std::unique_ptr<TracedValue> Serialize(const std::set<Entry>& dump); |
| 59 | 59 |
| 60 // Helper class to dump a snapshot of an |AllocationRegister| or other heap | 60 // Helper class to dump a snapshot of an |AllocationRegister| or other heap |
| 61 // bookkeeping structure into a |TracedValue|. This class is intended to be | 61 // bookkeeping structure into a |TracedValue|. This class is intended to be |
| 62 // used as a one-shot local instance on the stack. | 62 // used as a one-shot local instance on the stack. |
| 63 class BASE_EXPORT HeapDumpWriter { | 63 class BASE_EXPORT HeapDumpWriter { |
| 64 public: | 64 public: |
| 65 // The |StackFrameDeduplicator| and |TypeNameDeduplicator| are not owned. The | 65 // The |session_state| is used to retrieve |stack_frame_deduplicator_| and |
| 66 // heap dump writer assumes exclusive access to them during the lifetime of | 66 // |type_name_deduplicator_|, which are not owned. The heap dump writer |
| 67 // the dump writer. | 67 // assumes exclusive access to them during the lifetime of the dump writer. |
| 68 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, | 68 HeapDumpWriter(const MemoryDumpSessionState& session_state); |
| 69 TypeNameDeduplicator* type_name_deduplicator); | |
| 70 | 69 |
| 71 ~HeapDumpWriter(); | 70 ~HeapDumpWriter(); |
| 72 | 71 |
| 73 // Aggregates allocations to compute the total size of the heap, then breaks | 72 // Aggregates allocations to compute the total size of the heap, then breaks |
| 74 // down the heap recursively. This produces the values that should be dumped | 73 // down the heap recursively. This produces the values that should be dumped |
| 75 // in the "entries" array. The number of entries is kept reasonable because | 74 // in the "entries" array. The number of entries is kept reasonable because |
| 76 // long tails are not included. Use |Serialize| to convert to a traced value. | 75 // long tails are not included. Use |Serialize| to convert to a traced value. |
| 77 const std::set<Entry>& Summarize( | 76 const std::set<Entry>& Summarize( |
| 78 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context); | 77 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context); |
| 79 | 78 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 90 std::set<Entry> entries_; | 89 std::set<Entry> entries_; |
| 91 | 90 |
| 92 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive | 91 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive |
| 93 // this heap dump writer instance. | 92 // this heap dump writer instance. |
| 94 StackFrameDeduplicator* const stack_frame_deduplicator_; | 93 StackFrameDeduplicator* const stack_frame_deduplicator_; |
| 95 | 94 |
| 96 // Helper for converting type names to IDs. Not owned, must outlive this heap | 95 // Helper for converting type names to IDs. Not owned, must outlive this heap |
| 97 // dump writer instance. | 96 // dump writer instance. |
| 98 TypeNameDeduplicator* const type_name_deduplicator_; | 97 TypeNameDeduplicator* const type_name_deduplicator_; |
| 99 | 98 |
| 99 // Minimum size of an allocation for which an allocation bucket will be |
| 100 // broken down with children. |
| 101 uint32_t breakdown_threshold_bytes_; |
| 102 |
| 100 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); | 103 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); |
| 101 }; | 104 }; |
| 102 | 105 |
| 103 } // namespace internal | 106 } // namespace internal |
| 104 } // namespace trace_event | 107 } // namespace trace_event |
| 105 } // namespace base | 108 } // namespace base |
| 106 | 109 |
| 107 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ | 110 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
| OLD | NEW |