Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Side by Side Diff: base/trace_event/memory_profiler_heap_dump_writer.h

Issue 1419633004: [Tracing] Introduce HeapDumpWriter helper class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address primiano comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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"
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 // 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.
31 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator);
32 ~HeapDumpWriter();
33
34 // 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.
35 // does minimal processing, so it can be called when a lock is held. It should
36 // be called once for every allocation recorded.
37 void InsertAllocation(const AllocationContext& context, size_t size);
38
39 // 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
40 scoped_refptr<TracedValue> WriteHeapDump();
41
42 private:
43 // Writes a "size" key with value |size| as a hexidecimal string to the traced
44 // value.
45 void WriteSize(size_t size);
46
47 // The value that this heap dumper writes to.
48 const scoped_refptr<TracedValue> traced_value_;
49
50 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive
51 // this heap dump writer instance.
52 StackFrameDeduplicator* const stack_frame_deduplicator_;
53
54 // A map of backtrace to the number of bytes allocated for that backtrace.
55 hash_map<Backtrace, size_t> bytes_by_backtrace_;
56
57 // Buffer for converting integers into strings, that is re-used throughout the
58 // dump.
59 std::string buffer_;
60
61 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter);
62 };
63
64 } // namespace trace_event
65 } // namespace base
66
67 #endif // BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMP_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698