| 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 #include <unordered_map> |
| 12 | 13 |
| 13 #include "base/base_export.h" | 14 #include "base/base_export.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 MemoryDumpSessionState; |
| 22 class StackFrameDeduplicator; | 22 class StackFrameDeduplicator; |
| 23 class TracedValue; | 23 class TracedValue; |
| 24 class TypeNameDeduplicator; | 24 class TypeNameDeduplicator; |
| 25 | 25 |
| 26 // Aggregates |metrics_by_context|, recursively breaks down the heap, and | 26 // Aggregates |metrics_by_context|, recursively breaks down the heap, and |
| 27 // 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 |
| 28 // 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 |
| 29 // 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. |
| 30 BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapDump( | 30 BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapDump( |
| 31 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context, | 31 const std::unordered_map<AllocationContext, AllocationMetrics>& |
| 32 metrics_by_context, |
| 32 const MemoryDumpSessionState& session_state); | 33 const MemoryDumpSessionState& session_state); |
| 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 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 70 TypeNameDeduplicator* type_name_deduplicator, | 71 TypeNameDeduplicator* type_name_deduplicator, |
| 71 uint32_t breakdown_threshold_bytes); | 72 uint32_t breakdown_threshold_bytes); |
| 72 | 73 |
| 73 ~HeapDumpWriter(); | 74 ~HeapDumpWriter(); |
| 74 | 75 |
| 75 // Aggregates allocations to compute the total size of the heap, then breaks | 76 // Aggregates allocations to compute the total size of the heap, then breaks |
| 76 // down the heap recursively. This produces the values that should be dumped | 77 // down the heap recursively. This produces the values that should be dumped |
| 77 // in the "entries" array. The number of entries is kept reasonable because | 78 // in the "entries" array. The number of entries is kept reasonable because |
| 78 // long tails are not included. Use |Serialize| to convert to a traced value. | 79 // long tails are not included. Use |Serialize| to convert to a traced value. |
| 79 const std::set<Entry>& Summarize( | 80 const std::set<Entry>& Summarize( |
| 80 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context); | 81 const std::unordered_map<AllocationContext, AllocationMetrics>& |
| 82 metrics_by_context); |
| 81 | 83 |
| 82 private: | 84 private: |
| 83 // Inserts an |Entry| for |Bucket| into |entries_|. Returns false if the | 85 // Inserts an |Entry| for |Bucket| into |entries_|. Returns false if the |
| 84 // entry was present before, true if it was not. | 86 // entry was present before, true if it was not. |
| 85 bool AddEntryForBucket(const Bucket& bucket); | 87 bool AddEntryForBucket(const Bucket& bucket); |
| 86 | 88 |
| 87 // Recursively breaks down a bucket into smaller buckets and adds entries for | 89 // Recursively breaks down a bucket into smaller buckets and adds entries for |
| 88 // the buckets worth dumping to |entries_|. | 90 // the buckets worth dumping to |entries_|. |
| 89 void BreakDown(const Bucket& bucket); | 91 void BreakDown(const Bucket& bucket); |
| 90 | 92 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 uint32_t breakdown_threshold_bytes_; | 106 uint32_t breakdown_threshold_bytes_; |
| 105 | 107 |
| 106 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); | 108 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 } // namespace internal | 111 } // namespace internal |
| 110 } // namespace trace_event | 112 } // namespace trace_event |
| 111 } // namespace base | 113 } // namespace base |
| 112 | 114 |
| 113 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ | 115 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
| OLD | NEW |