OLD | NEW |
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_STACK_FRAME_DEDUPLICATOR_H_ | 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_STACK_FRAME_DEDUPLICATOR_H_ |
6 #define BASE_TRACE_EVENT_HEAP_PROFILER_STACK_FRAME_DEDUPLICATOR_H_ | 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_STACK_FRAME_DEDUPLICATOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 12 matching lines...) Expand all Loading... |
23 // efficient manner by creating a call tree and writing it as a set of (node, | 23 // efficient manner by creating a call tree and writing it as a set of (node, |
24 // parent) pairs. The tree nodes reference both parent and children. The parent | 24 // parent) pairs. The tree nodes reference both parent and children. The parent |
25 // is referenced by index into |frames_|. The children are referenced via a map | 25 // is referenced by index into |frames_|. The children are referenced via a map |
26 // of |StackFrame|s to index into |frames_|. So there is a trie for bottum-up | 26 // of |StackFrame|s to index into |frames_|. So there is a trie for bottum-up |
27 // lookup of a backtrace for deduplication, and a tree for compact storage in | 27 // lookup of a backtrace for deduplication, and a tree for compact storage in |
28 // the trace log. | 28 // the trace log. |
29 class BASE_EXPORT StackFrameDeduplicator : public ConvertableToTraceFormat { | 29 class BASE_EXPORT StackFrameDeduplicator : public ConvertableToTraceFormat { |
30 public: | 30 public: |
31 // A node in the call tree. | 31 // A node in the call tree. |
32 struct FrameNode { | 32 struct FrameNode { |
33 FrameNode(StackFrame frame, int parent_frame_index); | 33 FrameNode(StackFrameType frame_type, |
| 34 StackFrame frame, |
| 35 int parent_frame_index); |
34 FrameNode(const FrameNode& other); | 36 FrameNode(const FrameNode& other); |
35 ~FrameNode(); | 37 ~FrameNode(); |
36 | 38 |
| 39 StackFrameType frame_type; |
37 StackFrame frame; | 40 StackFrame frame; |
38 | 41 |
39 // The index of the parent stack frame in |frames_|, or -1 if there is no | 42 // The index of the parent stack frame in |frames_|, or -1 if there is no |
40 // parent frame (when it is at the bottom of the call stack). | 43 // parent frame (when it is at the bottom of the call stack). |
41 int parent_frame_index; | 44 int parent_frame_index; |
42 | 45 |
43 // Indices into |frames_| of frames called from the current frame. | 46 // Indices into |frames_| of frames called from the current frame. |
44 std::map<StackFrame, int> children; | 47 std::map<StackFrame, int> children; |
45 }; | 48 }; |
46 | 49 |
47 using ConstIterator = std::vector<FrameNode>::const_iterator; | 50 using ConstIterator = std::vector<FrameNode>::const_iterator; |
48 | 51 |
49 StackFrameDeduplicator(); | 52 StackFrameDeduplicator(); |
50 ~StackFrameDeduplicator() override; | 53 ~StackFrameDeduplicator() override; |
51 | 54 |
52 // Inserts a backtrace where |beginFrame| is a pointer to the bottom frame | 55 // Inserts a backtrace where |beginFrame| is a pointer to the bottom frame |
53 // (e.g. main) and |endFrame| is a pointer past the top frame (most recently | 56 // (e.g. main) and |endFrame| is a pointer past the top frame (most recently |
54 // called function), and returns the index of its leaf node in |frames_|. | 57 // called function), and returns the index of its leaf node in |frames_|. |
55 // Returns -1 if the backtrace is empty. | 58 // Returns -1 if the backtrace is empty. |
56 int Insert(const StackFrame* beginFrame, const StackFrame* endFrame); | 59 int Insert(StackFrameType frame_type, |
| 60 const StackFrame* beginFrame, const StackFrame* endFrame); |
57 | 61 |
58 // Iterators over the frame nodes in the call tree. | 62 // Iterators over the frame nodes in the call tree. |
59 ConstIterator begin() const { return frames_.begin(); } | 63 ConstIterator begin() const { return frames_.begin(); } |
60 ConstIterator end() const { return frames_.end(); } | 64 ConstIterator end() const { return frames_.end(); } |
61 | 65 |
62 // Writes the |stackFrames| dictionary as defined in https://goo.gl/GerkV8 to | 66 // Writes the |stackFrames| dictionary as defined in https://goo.gl/GerkV8 to |
63 // the trace log. | 67 // the trace log. |
64 void AppendAsTraceFormat(std::string* out) const override; | 68 void AppendAsTraceFormat(std::string* out) const override; |
65 | 69 |
66 // Estimates memory overhead including |sizeof(StackFrameDeduplicator)|. | 70 // Estimates memory overhead including |sizeof(StackFrameDeduplicator)|. |
67 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override; | 71 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override; |
68 | 72 |
69 private: | 73 private: |
70 std::map<StackFrame, int> roots_; | 74 std::map<StackFrame, int> roots_; |
71 std::vector<FrameNode> frames_; | 75 std::vector<FrameNode> frames_; |
72 | 76 |
73 DISALLOW_COPY_AND_ASSIGN(StackFrameDeduplicator); | 77 DISALLOW_COPY_AND_ASSIGN(StackFrameDeduplicator); |
74 }; | 78 }; |
75 | 79 |
76 } // namespace trace_event | 80 } // namespace trace_event |
77 } // namespace base | 81 } // namespace base |
78 | 82 |
79 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_STACK_FRAME_DEDUPLICATOR_H_ | 83 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_STACK_FRAME_DEDUPLICATOR_H_ |
OLD | NEW |