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

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

Issue 1877313003: [tracing] Track number of allocations in heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix indentation. Created 4 years, 8 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_
6 #define BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 12
13 #include "base/base_export.h" 13 #include "base/base_export.h"
14 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/trace_event/heap_profiler_allocation_context.h" 16 #include "base/trace_event/heap_profiler_allocation_context.h"
17 17
18 namespace base { 18 namespace base {
19 namespace trace_event { 19 namespace trace_event {
20 20
21 class StackFrameDeduplicator; 21 class StackFrameDeduplicator;
22 class TracedValue; 22 class TracedValue;
23 class TypeNameDeduplicator; 23 class TypeNameDeduplicator;
24 24
25 // Aggregates |bytes_by_context|, recursively breaks down the heap, and returns 25 // Aggregates |metrics_by_context|, recursively breaks down the heap, and
26 // a traced value with an "entries" array that can be dumped in the trace log, 26 // returns a traced value with an "entries" array that can be dumped in the
27 // following the format described in https://goo.gl/KY7zVE. The number of 27 // trace log, following the format described in https://goo.gl/KY7zVE. The
28 // entries is kept reasonable because long tails are not included. 28 // number of entries is kept reasonable because long tails are not included.
29 BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapDump( 29 BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapDump(
30 const hash_map<AllocationContext, size_t>& bytes_by_context, 30 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context,
31 StackFrameDeduplicator* stack_frame_deduplicator, 31 StackFrameDeduplicator* stack_frame_deduplicator,
32 TypeNameDeduplicator* type_name_deduplicator); 32 TypeNameDeduplicator* type_name_deduplicator);
33 33
34 namespace internal { 34 namespace internal {
35 35
36 namespace { 36 namespace {
37 struct Bucket; 37 struct Bucket;
38 } 38 }
39 39
40 // An entry in the "entries" array as described in https://goo.gl/KY7zVE. 40 // An entry in the "entries" array as described in https://goo.gl/KY7zVE.
41 struct BASE_EXPORT Entry { 41 struct BASE_EXPORT Entry {
42 size_t size; 42 size_t size;
43 size_t count;
43 44
44 // References a backtrace in the stack frame deduplicator. -1 means empty 45 // References a backtrace in the stack frame deduplicator. -1 means empty
45 // backtrace (the root of the tree). 46 // backtrace (the root of the tree).
46 int stack_frame_id; 47 int stack_frame_id;
47 48
48 // References a type name in the type name deduplicator. -1 indicates that 49 // References a type name in the type name deduplicator. -1 indicates that
49 // the size is the cumulative size for all types (the root of the tree). 50 // the size is the cumulative size for all types (the root of the tree).
50 int type_id; 51 int type_id;
51 }; 52 };
52 53
(...skipping 14 matching lines...) Expand all
67 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator, 68 HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator,
68 TypeNameDeduplicator* type_name_deduplicator); 69 TypeNameDeduplicator* type_name_deduplicator);
69 70
70 ~HeapDumpWriter(); 71 ~HeapDumpWriter();
71 72
72 // Aggregates allocations to compute the total size of the heap, then breaks 73 // Aggregates allocations to compute the total size of the heap, then breaks
73 // down the heap recursively. This produces the values that should be dumped 74 // down the heap recursively. This produces the values that should be dumped
74 // in the "entries" array. The number of entries is kept reasonable because 75 // in the "entries" array. The number of entries is kept reasonable because
75 // long tails are not included. Use |Serialize| to convert to a traced value. 76 // long tails are not included. Use |Serialize| to convert to a traced value.
76 const std::set<Entry>& Summarize( 77 const std::set<Entry>& Summarize(
77 const hash_map<AllocationContext, size_t>& bytes_by_context); 78 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context);
78 79
79 private: 80 private:
80 // Inserts an |Entry| for |Bucket| into |entries_|. Returns false if the 81 // Inserts an |Entry| for |Bucket| into |entries_|. Returns false if the
81 // entry was present before, true if it was not. 82 // entry was present before, true if it was not.
82 bool AddEntryForBucket(const Bucket& bucket); 83 bool AddEntryForBucket(const Bucket& bucket);
83 84
84 // Recursively breaks down a bucket into smaller buckets and adds entries for 85 // Recursively breaks down a bucket into smaller buckets and adds entries for
85 // the buckets worth dumping to |entries_|. 86 // the buckets worth dumping to |entries_|.
86 void BreakDown(const Bucket& bucket); 87 void BreakDown(const Bucket& bucket);
87 88
88 // The collection of entries that is filled by |Summarize|. 89 // The collection of entries that is filled by |Summarize|.
89 std::set<Entry> entries_; 90 std::set<Entry> entries_;
90 91
91 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive 92 // Helper for generating the |stackFrames| dictionary. Not owned, must outlive
92 // this heap dump writer instance. 93 // this heap dump writer instance.
93 StackFrameDeduplicator* const stack_frame_deduplicator_; 94 StackFrameDeduplicator* const stack_frame_deduplicator_;
94 95
95 // Helper for converting type names to IDs. Not owned, must outlive this heap 96 // Helper for converting type names to IDs. Not owned, must outlive this heap
96 // dump writer instance. 97 // dump writer instance.
97 TypeNameDeduplicator* const type_name_deduplicator_; 98 TypeNameDeduplicator* const type_name_deduplicator_;
98 99
99 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter); 100 DISALLOW_COPY_AND_ASSIGN(HeapDumpWriter);
100 }; 101 };
101 102
102 } // namespace internal 103 } // namespace internal
103 } // namespace trace_event 104 } // namespace trace_event
104 } // namespace base 105 } // namespace base
105 106
106 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_ 107 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_HEAP_DUMP_WRITER_H_
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_allocation_context.h ('k') | base/trace_event/heap_profiler_heap_dump_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698