Index: base/trace_event/heap_profiler_heap_dump_writer.h |
diff --git a/base/trace_event/heap_profiler_heap_dump_writer.h b/base/trace_event/heap_profiler_heap_dump_writer.h |
index c3a776739973b270d6c34f9d4bca8c0806ec8a07..6f19b3ac8af921d1b82bd84a8ec92dedb8b57f2e 100644 |
--- a/base/trace_event/heap_profiler_heap_dump_writer.h |
+++ b/base/trace_event/heap_profiler_heap_dump_writer.h |
@@ -5,7 +5,7 @@ |
#ifndef BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
#define BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ |
-#include <string> |
+#include <set> |
#include "base/base_export.h" |
#include "base/containers/hash_tables.h" |
@@ -14,68 +14,55 @@ |
#include "base/trace_event/heap_profiler_allocation_context.h" |
namespace base { |
+ |
+class Value; |
+ |
namespace trace_event { |
class StackFrameDeduplicator; |
class TracedValue; |
class TypeNameDeduplicator; |
-// Helper class to dump a snapshot of an |AllocationRegister| or other heap |
-// bookkeeping structure into a |TracedValue|. This class is intended to be |
-// used as a one-shot local instance on the stack. To write heap dumps, call |
-// |InsertAllocation| for every captured allocation, then call |WriteHeapDump| |
-// to do the processing and generate a heap dump value for the trace log. |
-class BASE_EXPORT HeapDumpWriter { |
- public: |
- // The |StackFrameDeduplicator| and |TypeNameDeduplicator| are not owned. The |
- // heap dump writer assumes exclusive access to them during the lifetime of |
- // the dump writer. |
- HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, |
- TypeNameDeduplicator* type_name_deduplicator); |
- ~HeapDumpWriter(); |
- |
- // Inserts information from which the heap dump will be generated. This method |
- // does minimal processing, so it can be called when a lock is held. |
- void InsertAllocation(const AllocationContext& context, size_t size); |
- |
- // Aggregates allocations and writes an "entries" array to a traced value. See |
- // https://goo.gl/jYN4Zn for a description of the format. |
- scoped_refptr<TracedValue> WriteHeapDump(); |
- |
- private: |
- // Writes a "bt" key that references a stack frame in the |stackFrames| |
- // dictionary. |
- void WriteStackFrameIndex(int index); |
- |
- // Writes a "type" key with the stringified type ID. |
- void WriteTypeId(int type_id); |
- |
- // Writes a "size" key with value |size| as a hexidecimal string to the traced |
- // value. |
- void WriteSize(size_t size); |
- |
- // The value that this heap dumper writes to. |
- const scoped_refptr<TracedValue> traced_value_; |
- |
- // Helper for generating the |stackFrames| dictionary. Not owned, must outlive |
- // this heap dump writer instance. |
- StackFrameDeduplicator* const stack_frame_deduplicator_; |
- |
- // Helper for converting type names to IDs. Not owned, must outlive this heap |
- // dump writer instance. |
- TypeNameDeduplicator* const type_name_deduplicator_; |
- |
- // A map of allocation context to the number of bytes allocated for that |
- // context. |
- hash_map<AllocationContext, size_t> bytes_by_context_; |
- |
- // Buffer for converting integers into strings, that is re-used throughout the |
- // dump. |
- std::string buffer_; |
- |
- DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); |
+// Aggregates and breaks down allocations and writes an "entries" array with |
+// the most significant entries to a traced value. See https://goo.gl/KY7zVE |
+// for a description of the format. |
+scoped_refptr<TracedValue> BASE_EXPORT |
+WriteHeapDump(const base::hash_map<AllocationContext, size_t>& allocations, |
+ StackFrameDeduplicator* stack_frame_deduplicator, |
+ TypeNameDeduplicator* type_name_deduplicator); |
+ |
+namespace heap_dump { |
+ |
+// An entry in the "entries" array as described in https://goo.gl/KY7zVE. |
+struct BASE_EXPORT HeapEntry { |
+ size_t size; |
+ |
+ // References a backtrace in the stack frame deduplicator. -1 means empty |
+ // backtrace (the root of the tree). |
+ int stack_frame_id; |
+ |
+ // References a type name in the type name deduplicator. -1 indicates that |
+ // the size is the cumulative size for all types (the root of the tree). |
+ int type_id; |
}; |
+// Comparison operator to enable putting |HeapEntry| in a |std::set|. |
+bool BASE_EXPORT operator<(HeapEntry lhs, HeapEntry rhs); |
+ |
+// Aggregates allocations to compute the total size of the heap, then breaks |
+// down the heap recursively. This produces the values that should be dumped |
+// in the "entries" array. The number of entries is kept reasonable because |
+// long tails are not included. Use |Write| to convert to a traced value. |
+std::set<HeapEntry> BASE_EXPORT |
+Dump(const base::hash_map<AllocationContext, size_t>& allocations, |
+ StackFrameDeduplicator* stack_frame_deduplicator, |
+ TypeNameDeduplicator* type_name_deduplicator); |
+ |
+// Writes an "entries" array to a traced value. See https://goo.gl/KY7zVE for |
+// a description of the format. |
+scoped_refptr<TracedValue> BASE_EXPORT Write(const std::set<HeapEntry>& dump); |
+ |
+} // namespace heap_dump |
} // namespace trace_event |
} // namespace base |