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 <set> | 11 #include <set> |
11 | 12 |
12 #include "base/base_export.h" | 13 #include "base/base_export.h" |
13 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.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 StackFrameDeduplicator; | 21 class StackFrameDeduplicator; |
22 class TracedValue; | 22 class TracedValue; |
23 class TypeNameDeduplicator; | 23 class TypeNameDeduplicator; |
24 | 24 |
25 // Aggregates |bytes_by_context|, recursively breaks down the heap, and returns | 25 // Aggregates |bytes_by_context|, recursively breaks down the heap, and returns |
26 // a traced value with an "entries" array that can be dumped in the trace log, | 26 // a traced value with an "entries" array that can be dumped in the trace log, |
27 // following the format described in https://goo.gl/KY7zVE. The number of | 27 // following the format described in https://goo.gl/KY7zVE. The number of |
28 // entries is kept reasonable because long tails are not included. | 28 // entries is kept reasonable because long tails are not included. |
29 BASE_EXPORT scoped_ptr<TracedValue> ExportHeapDump( | 29 BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapDump( |
30 const hash_map<AllocationContext, size_t>& bytes_by_context, | 30 const hash_map<AllocationContext, size_t>& bytes_by_context, |
31 StackFrameDeduplicator* stack_frame_deduplicator, | 31 StackFrameDeduplicator* stack_frame_deduplicator, |
32 TypeNameDeduplicator* type_name_deduplicator); | 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; |
43 | 43 |
44 // References a backtrace in the stack frame deduplicator. -1 means empty | 44 // References a backtrace in the stack frame deduplicator. -1 means empty |
45 // backtrace (the root of the tree). | 45 // backtrace (the root of the tree). |
46 int stack_frame_id; | 46 int stack_frame_id; |
47 | 47 |
48 // References a type name in the type name deduplicator. -1 indicates that | 48 // References a type name in the type name deduplicator. -1 indicates that |
49 // the size is the cumulative size for all types (the root of the tree). | 49 // the size is the cumulative size for all types (the root of the tree). |
50 int type_id; | 50 int type_id; |
51 }; | 51 }; |
52 | 52 |
53 // Comparison operator to enable putting |Entry| in a |std::set|. | 53 // Comparison operator to enable putting |Entry| in a |std::set|. |
54 BASE_EXPORT bool operator<(Entry lhs, Entry rhs); | 54 BASE_EXPORT bool operator<(Entry lhs, Entry rhs); |
55 | 55 |
56 // Serializes entries to an "entries" array in a traced value. | 56 // Serializes entries to an "entries" array in a traced value. |
57 BASE_EXPORT scoped_ptr<TracedValue> Serialize(const std::set<Entry>& dump); | 57 BASE_EXPORT std::unique_ptr<TracedValue> Serialize(const std::set<Entry>& dump); |
58 | 58 |
59 // Helper class to dump a snapshot of an |AllocationRegister| or other heap | 59 // Helper class to dump a snapshot of an |AllocationRegister| or other heap |
60 // bookkeeping structure into a |TracedValue|. This class is intended to be | 60 // bookkeeping structure into a |TracedValue|. This class is intended to be |
61 // used as a one-shot local instance on the stack. | 61 // used as a one-shot local instance on the stack. |
62 class BASE_EXPORT HeapDumpWriter { | 62 class BASE_EXPORT HeapDumpWriter { |
63 public: | 63 public: |
64 // The |StackFrameDeduplicator| and |TypeNameDeduplicator| are not owned. The | 64 // The |StackFrameDeduplicator| and |TypeNameDeduplicator| are not owned. The |
65 // heap dump writer assumes exclusive access to them during the lifetime of | 65 // heap dump writer assumes exclusive access to them during the lifetime of |
66 // the dump writer. | 66 // the dump writer. |
67 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, | 67 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, |
(...skipping 29 matching lines...) Expand all Loading... |
97 TypeNameDeduplicator* const type_name_deduplicator_; | 97 TypeNameDeduplicator* const type_name_deduplicator_; |
98 | 98 |
99 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); | 99 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); |
100 }; | 100 }; |
101 | 101 |
102 } // namespace internal | 102 } // namespace internal |
103 } // namespace trace_event | 103 } // namespace trace_event |
104 } // namespace base | 104 } // namespace base |
105 | 105 |
106 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ | 106 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
OLD | NEW |