Chromium Code Reviews| Index: base/trace_event/memory_profiler_heap_dump_writer.h |
| diff --git a/base/trace_event/memory_profiler_heap_dump_writer.h b/base/trace_event/memory_profiler_heap_dump_writer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cb5ce11a25fdbb5b739aa87d3b46b14ce3020060 |
| --- /dev/null |
| +++ b/base/trace_event/memory_profiler_heap_dump_writer.h |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMP_WRITER_H_ |
| +#define BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMP_WRITER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/base_export.h" |
| +#include "base/containers/hash_tables.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/trace_event/memory_profiler_allocation_context.h" |
| +#include "base/trace_event/trace_event_argument.h" |
| + |
| +namespace base { |
| +namespace trace_event { |
| + |
| +class AllocationRegister; |
| + |
| +// 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| is not owned. The heap dump writer assumes |
| + // unique access to it during the lifetime of the dump writer. |
|
Primiano Tucci (use gerrit)
2015/10/26 20:57:57
s/unique/exclusive/
Ruud van Asseldonk
2015/10/27 10:50:18
Done.
|
| + HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator); |
| + ~HeapDumpWriter(); |
| + |
| + // Inserts information from which the heap dump will be generated. This method |
|
Primiano Tucci (use gerrit)
2015/10/26 20:57:57
The first period is pleonastic and doesn't tell an
Ruud van Asseldonk
2015/10/27 10:50:18
Done.
|
| + // does minimal processing, so it can be called when a lock is held. It should |
| + // be called once for every allocation recorded. |
| + void InsertAllocation(const AllocationContext& context, size_t size); |
| + |
| + // Aggregates allocations and writes a "heap" array to a traced value. |
|
Primiano Tucci (use gerrit)
2015/10/26 20:57:57
add: See goo.gl/XXXX for the actual format
Ruud van Asseldonk
2015/10/27 10:50:18
We don't have a document for this yet, except the
|
| + scoped_refptr<TracedValue> WriteHeapDump(); |
| + |
| + private: |
| + // 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_; |
| + |
| + // A map of backtrace to the number of bytes allocated for that backtrace. |
| + hash_map<Backtrace, size_t> bytes_by_backtrace_; |
| + |
| + // Buffer for converting integers into strings, that is re-used throughout the |
| + // dump. |
| + std::string buffer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); |
| +}; |
| + |
| +} // namespace trace_event |
| +} // namespace base |
| + |
| +#endif // BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMP_WRITER_H_ |