OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMP_WRITER_H_ | |
6 #define BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMP_WRITER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/base_export.h" | |
11 #include "base/containers/hash_tables.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/trace_event/memory_profiler_allocation_context.h" | |
15 #include "base/trace_event/trace_event_argument.h" | |
Primiano Tucci (use gerrit)
2015/10/27 11:56:20
Forward declare this if you can please, trace_even
Ruud van Asseldonk
2015/10/27 11:59:31
Done.
| |
16 | |
17 namespace base { | |
18 namespace trace_event { | |
19 | |
20 class AllocationRegister; | |
21 | |
22 // Helper class to dump a snapshot of an |AllocationRegister| or other heap | |
23 // bookkeeping structure into a |TracedValue|. This class is intended to be | |
24 // used as a one-shot local instance on the stack. To write heap dumps, call | |
25 // |InsertAllocation| for every captured allocation, then call |WriteHeapDump| | |
26 // to do the processing and generate a heap dump value for the trace log. | |
27 class BASE_EXPORT HeapDumpWriter { | |
28 public: | |
29 // The |StackFrameDeduplicator| is not owned. The heap dump writer assumes | |
30 // exclusive access to it during the lifetime of the dump writer. | |
31 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator); | |
32 ~HeapDumpWriter(); | |
33 | |
34 // Inserts information from which the heap dump will be generated. This method | |
35 // does minimal processing, so it can be called when a lock is held. | |
36 void InsertAllocation(const AllocationContext& context, size_t size); | |
37 | |
38 // Aggregates allocations and writes an "entries" array to a traced value. See | |
39 // https://goo.gl/jYN4Zn for a description of the format. | |
40 scoped_refptr<TracedValue> WriteHeapDump(); | |
41 | |
42 private: | |
43 // Writes a "bt" key that references a stack frame in the |stackFrames| | |
44 // dictionary. | |
45 void WriteStackFrameIndex(int index); | |
46 | |
47 // Writes a "size" key with value |size| as a hexidecimal string to the traced | |
48 // value. | |
49 void WriteSize(size_t size); | |
50 | |
51 // The value that this heap dumper writes to. | |
52 const scoped_refptr<TracedValue> traced_value_; | |
53 | |
54 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive | |
55 // this heap dump writer instance. | |
56 StackFrameDeduplicator* const stack_frame_deduplicator_; | |
57 | |
58 // A map of backtrace to the number of bytes allocated for that backtrace. | |
59 hash_map<Backtrace, size_t> bytes_by_backtrace_; | |
60 | |
61 // Buffer for converting integers into strings, that is re-used throughout the | |
62 // dump. | |
63 std::string buffer_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); | |
66 }; | |
67 | |
68 } // namespace trace_event | |
69 } // namespace base | |
70 | |
71 #endif // BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMP_WRITER_H_ | |
OLD | NEW |