| 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 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 |metrics_by_context|, recursively breaks down the heap, and |
| 26 // a traced value with an "entries" array that can be dumped in the trace log, | 26 // returns a traced value with an "entries" array that can be dumped in the |
| 27 // following the format described in https://goo.gl/KY7zVE. The number of | 27 // trace log, following the format described in https://goo.gl/KY7zVE. The |
| 28 // entries is kept reasonable because long tails are not included. | 28 // number of entries is kept reasonable because long tails are not included. |
| 29 BASE_EXPORT std::unique_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, AllocationsSizeAndCount>& |
| 31 metrics_by_context, |
| 31 StackFrameDeduplicator* stack_frame_deduplicator, | 32 StackFrameDeduplicator* stack_frame_deduplicator, |
| 32 TypeNameDeduplicator* type_name_deduplicator); | 33 TypeNameDeduplicator* type_name_deduplicator); |
| 33 | 34 |
| 34 namespace internal { | 35 namespace internal { |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 struct Bucket; | 38 struct Bucket; |
| 38 } | 39 } |
| 39 | 40 |
| 40 // An entry in the "entries" array as described in https://goo.gl/KY7zVE. | 41 // An entry in the "entries" array as described in https://goo.gl/KY7zVE. |
| 41 struct BASE_EXPORT Entry { | 42 struct BASE_EXPORT Entry { |
| 42 size_t size; | 43 size_t size; |
| 44 size_t count; |
| 43 | 45 |
| 44 // References a backtrace in the stack frame deduplicator. -1 means empty | 46 // References a backtrace in the stack frame deduplicator. -1 means empty |
| 45 // backtrace (the root of the tree). | 47 // backtrace (the root of the tree). |
| 46 int stack_frame_id; | 48 int stack_frame_id; |
| 47 | 49 |
| 48 // References a type name in the type name deduplicator. -1 indicates that | 50 // 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). | 51 // the size is the cumulative size for all types (the root of the tree). |
| 50 int type_id; | 52 int type_id; |
| 51 }; | 53 }; |
| 52 | 54 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 67 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, | 69 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, |
| 68 TypeNameDeduplicator* type_name_deduplicator); | 70 TypeNameDeduplicator* type_name_deduplicator); |
| 69 | 71 |
| 70 ~HeapDumpWriter(); | 72 ~HeapDumpWriter(); |
| 71 | 73 |
| 72 // Aggregates allocations to compute the total size of the heap, then breaks | 74 // Aggregates allocations to compute the total size of the heap, then breaks |
| 73 // down the heap recursively. This produces the values that should be dumped | 75 // down the heap recursively. This produces the values that should be dumped |
| 74 // in the "entries" array. The number of entries is kept reasonable because | 76 // in the "entries" array. The number of entries is kept reasonable because |
| 75 // long tails are not included. Use |Serialize| to convert to a traced value. | 77 // long tails are not included. Use |Serialize| to convert to a traced value. |
| 76 const std::set<Entry>& Summarize( | 78 const std::set<Entry>& Summarize( |
| 77 const hash_map<AllocationContext, size_t>& bytes_by_context); | 79 const hash_map<AllocationContext, AllocationsSizeAndCount>& |
| 80 metrics_by_context); |
| 78 | 81 |
| 79 private: | 82 private: |
| 80 // Inserts an |Entry| for |Bucket| into |entries_|. Returns false if the | 83 // Inserts an |Entry| for |Bucket| into |entries_|. Returns false if the |
| 81 // entry was present before, true if it was not. | 84 // entry was present before, true if it was not. |
| 82 bool AddEntryForBucket(const Bucket& bucket); | 85 bool AddEntryForBucket(const Bucket& bucket); |
| 83 | 86 |
| 84 // Recursively breaks down a bucket into smaller buckets and adds entries for | 87 // Recursively breaks down a bucket into smaller buckets and adds entries for |
| 85 // the buckets worth dumping to |entries_|. | 88 // the buckets worth dumping to |entries_|. |
| 86 void BreakDown(const Bucket& bucket); | 89 void BreakDown(const Bucket& bucket); |
| 87 | 90 |
| 88 // The collection of entries that is filled by |Summarize|. | 91 // The collection of entries that is filled by |Summarize|. |
| 89 std::set<Entry> entries_; | 92 std::set<Entry> entries_; |
| 90 | 93 |
| 91 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive | 94 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive |
| 92 // this heap dump writer instance. | 95 // this heap dump writer instance. |
| 93 StackFrameDeduplicator* const stack_frame_deduplicator_; | 96 StackFrameDeduplicator* const stack_frame_deduplicator_; |
| 94 | 97 |
| 95 // 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 |
| 96 // dump writer instance. | 99 // dump writer instance. |
| 97 TypeNameDeduplicator* const type_name_deduplicator_; | 100 TypeNameDeduplicator* const type_name_deduplicator_; |
| 98 | 101 |
| 99 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); | 102 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); |
| 100 }; | 103 }; |
| 101 | 104 |
| 102 } // namespace internal | 105 } // namespace internal |
| 103 } // namespace trace_event | 106 } // namespace trace_event |
| 104 } // namespace base | 107 } // namespace base |
| 105 | 108 |
| 106 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ | 109 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
| OLD | NEW |