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 |stack_frame_deduplicator| and |type_name_deduplicator| are not owned. |
66 // heap dump writer assumes exclusive access to them during the lifetime of | 66 // The heap dump writer assumes exclusive access to them during the lifetime |
67 // the dump writer. | 67 // of the dump writer. The heap dumps are broken down for allocations bigger |
| 68 // than |breakdown_threshold_bytes|. |
68 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, | 69 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, |
69 TypeNameDeduplicator* type_name_deduplicator); | 70 TypeNameDeduplicator* type_name_deduplicator, |
| 71 uint32_t breakdown_threshold_bytes); |
70 | 72 |
71 ~HeapDumpWriter(); | 73 ~HeapDumpWriter(); |
72 | 74 |
73 // Aggregates allocations to compute the total size of the heap, then breaks | 75 // 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 | 76 // 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 | 77 // 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. | 78 // long tails are not included. Use |Serialize| to convert to a traced value. |
77 const std::set<Entry>& Summarize( | 79 const std::set<Entry>& Summarize( |
78 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context); | 80 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context); |
79 | 81 |
(...skipping 10 matching lines...) Expand all Loading... |
90 std::set<Entry> entries_; | 92 std::set<Entry> entries_; |
91 | 93 |
92 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive | 94 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive |
93 // this heap dump writer instance. | 95 // this heap dump writer instance. |
94 StackFrameDeduplicator* const stack_frame_deduplicator_; | 96 StackFrameDeduplicator* const stack_frame_deduplicator_; |
95 | 97 |
96 // Helper for converting type names to IDs. Not owned, must outlive this heap | 98 // Helper for converting type names to IDs. Not owned, must outlive this heap |
97 // dump writer instance. | 99 // dump writer instance. |
98 TypeNameDeduplicator* const type_name_deduplicator_; | 100 TypeNameDeduplicator* const type_name_deduplicator_; |
99 | 101 |
| 102 // Minimum size of an allocation for which an allocation bucket will be |
| 103 // broken down with children. |
| 104 uint32_t breakdown_threshold_bytes_; |
| 105 |
100 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); | 106 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); |
101 }; | 107 }; |
102 | 108 |
103 } // namespace internal | 109 } // namespace internal |
104 } // namespace trace_event | 110 } // namespace trace_event |
105 } // namespace base | 111 } // namespace base |
106 | 112 |
107 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ | 113 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
OLD | NEW |