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

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

Issue 1419633004: [Tracing] Introduce HeapDumpWriter helper class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove WriteStackFrames, DISALLOW_COPY_AND_ASSIGN Created 5 years, 2 months 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.
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 I'd probably pick a stronger name for this, which
Ruud van Asseldonk 2015/10/26 14:51:26 Renamed to |HeapDumpWriter|.
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_DUMPER_H_
6 #define BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMPER_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| into a
23 // |TracedValue|. This class is intended to be used as a one-shot local
24 // instance on the stack. To write heap dumps, call |Fill| on it, then
25 // call |WriteHeapDump|.
26 class BASE_EXPORT HeapDumper {
27 public:
28 // The |StackFrameDeduplicator| is borrowed. The heap dumper assumes unique
29 // access to it during dumper lifetime.
30 HeapDumper(scoped_refptr<TracedValue> traced_value,
Primiano Tucci (use gerrit) 2015/10/26 11:52:07 This feels a bit an unnatural pattern: you take an
Ruud van Asseldonk 2015/10/26 14:51:26 Made it a member instead, and return it from |Writ
31 StackFrameDeduplicator* sf_deduplicator);
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 either deduplicator or stack_frame_deduplicator
Ruud van Asseldonk 2015/10/26 14:51:26 Done.
32 ~HeapDumper();
33
34 // Extracts all required information from the allocation register. This does
35 // minimal processing, so if the caller holds a lock for |allocation_register|
36 // the lock can be released as soon as possible.
37 void Fill(const AllocationRegister& allocation_register);
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 As discussed offline would be clearer to expose on
Ruud van Asseldonk 2015/10/26 14:51:26 I agree that would be much cleaner. Done.
38
39 // Aggregates allocations and writes a "heap" array to the traced value. Call
40 // |Fill| before using this.
41 void WriteHeapDump();
42
43 private:
44 // Writes a "size" key with value |size| as a hexidecimal string to the traced
45 // value.
46 void WriteSize(size_t size);
47
48 // The value that this heap dumper writes to.
49 const scoped_refptr<TracedValue> traced_value_;
50
51 // Helper for generating the |stackFrames| dictionary. Borrowed, not owned.
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 Borrowed doesn't make clear if you plan to transfe
Ruud van Asseldonk 2015/10/26 14:51:26 Done. I don't know about you, but to me "borrowin
52 StackFrameDeduplicator* const sf_deduplicator_;
53
54 // A map of backtrace to the number of bytes allocated for that backtrace.
55 hash_map<Backtrace, size_t, BacktraceHash> acc_by_backtrace_;
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 what about bytes_by_backtrace_?
Ruud van Asseldonk 2015/10/26 14:51:27 If you wish.
56
57 // Buffer for converting integers into strings, that is re-used throughout the
58 // dump.
59 std::string buffer_;
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 smart, I see what you are doing here ;-)
Ruud van Asseldonk 2015/10/26 14:51:26 The credit is yours, I stole this from |MemoryAllo
60
61 DISALLOW_COPY_AND_ASSIGN(HeapDumper);
62 };
63
64 } // namespace trace_event
65 } // namespace base
66
67 #endif // BASE_TRACE_EVENT_MEMORY_PROFILER_HEAP_DUMPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698