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

Side by Side Diff: base/trace_event/heap_profiler_stack_frame_deduplicator.cc

Issue 1839503002: [tracing] Add native allocation tracing mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WalkStackFrames (wants frame pointers) 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 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" 5 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h"
6 6
7 #include <inttypes.h>
7 #include <stddef.h> 8 #include <stddef.h>
8 9
9 #include <string> 10 #include <string>
10 #include <utility> 11 #include <utility>
11 12
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "base/trace_event/trace_event_argument.h" 14 #include "base/trace_event/trace_event_argument.h"
14 #include "base/trace_event/trace_event_memory_overhead.h" 15 #include "base/trace_event/trace_event_memory_overhead.h"
15 16
16 namespace base { 17 namespace base {
17 namespace trace_event { 18 namespace trace_event {
18 19
19 StackFrameDeduplicator::FrameNode::FrameNode(StackFrame frame, 20 StackFrameDeduplicator::FrameNode::FrameNode(StackFrameType frame_type,
21 StackFrame frame,
20 int parent_frame_index) 22 int parent_frame_index)
21 : frame(frame), parent_frame_index(parent_frame_index) {} 23 : frame_type(frame_type), frame(frame),
24 parent_frame_index(parent_frame_index) {}
22 StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default; 25 StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default;
23 StackFrameDeduplicator::FrameNode::~FrameNode() {} 26 StackFrameDeduplicator::FrameNode::~FrameNode() {}
24 27
25 StackFrameDeduplicator::StackFrameDeduplicator() {} 28 StackFrameDeduplicator::StackFrameDeduplicator() {}
26 StackFrameDeduplicator::~StackFrameDeduplicator() {} 29 StackFrameDeduplicator::~StackFrameDeduplicator() {}
27 30
28 int StackFrameDeduplicator::Insert(const StackFrame* beginFrame, 31 int StackFrameDeduplicator::Insert(StackFrameType frame_type,
32 const StackFrame* beginFrame,
29 const StackFrame* endFrame) { 33 const StackFrame* endFrame) {
30 int frame_index = -1; 34 int frame_index = -1;
31 std::map<StackFrame, int>* nodes = &roots_; 35 std::map<StackFrame, int>* nodes = &roots_;
32 36
33 // Loop through the frames, early out when a frame is null. 37 // Loop through the frames, early out when a frame is null.
34 for (const StackFrame* it = beginFrame; it != endFrame && *it; it++) { 38 for (const StackFrame* it = beginFrame; it != endFrame && *it; it++) {
35 StackFrame frame = *it; 39 StackFrame frame = *it;
36 40
37 auto node = nodes->find(frame); 41 auto node = nodes->find(frame);
38 if (node == nodes->end()) { 42 if (node == nodes->end()) {
39 // There is no tree node for this frame yet, create it. The parent node 43 // There is no tree node for this frame yet, create it. The parent node
40 // is the node associated with the previous frame. 44 // is the node associated with the previous frame.
41 FrameNode frame_node(frame, frame_index); 45 FrameNode frame_node(frame_type, frame, frame_index);
42 46
43 // The new frame node will be appended, so its index is the current size 47 // The new frame node will be appended, so its index is the current size
44 // of the vector. 48 // of the vector.
45 frame_index = static_cast<int>(frames_.size()); 49 frame_index = static_cast<int>(frames_.size());
46 50
47 // Add the node to the trie so it will be found next time. 51 // Add the node to the trie so it will be found next time.
48 nodes->insert(std::make_pair(frame, frame_index)); 52 nodes->insert(std::make_pair(frame, frame_index));
49 53
50 // Append the node after modifying |nodes|, because the |frames_| vector 54 // Append the node after modifying |nodes|, because the |frames_| vector
51 // might need to resize, and this invalidates the |nodes| pointer. 55 // might need to resize, and this invalidates the |nodes| pointer.
(...skipping 19 matching lines...) Expand all
71 75
72 while (frame_node != it_end) { 76 while (frame_node != it_end) {
73 // The |stackFrames| format is a dictionary, not an array, so the 77 // The |stackFrames| format is a dictionary, not an array, so the
74 // keys are stringified indices. Write the index manually, then use 78 // keys are stringified indices. Write the index manually, then use
75 // |TracedValue| to format the object. This is to avoid building the 79 // |TracedValue| to format the object. This is to avoid building the
76 // entire dictionary as a |TracedValue| in memory. 80 // entire dictionary as a |TracedValue| in memory.
77 SStringPrintf(&stringify_buffer, "\"%d\":", i); 81 SStringPrintf(&stringify_buffer, "\"%d\":", i);
78 out->append(stringify_buffer); 82 out->append(stringify_buffer);
79 83
80 scoped_ptr<TracedValue> frame_node_value(new TracedValue); 84 scoped_ptr<TracedValue> frame_node_value(new TracedValue);
81 frame_node_value->SetString("name", frame_node->frame); 85 switch (frame_node->frame_type) {
86 case STACK_FRAME_TYPE_SYMBOL:
87 frame_node_value->SetString(
88 "name", static_cast<const char*>(frame_node->frame));
89 break;
90 case STACK_FRAME_TYPE_PC:
91 SStringPrintf(&stringify_buffer,
92 "pc:%" PRIxPTR,
93 reinterpret_cast<uintptr_t>(frame_node->frame));
94 frame_node_value->SetString("name", stringify_buffer);
95 break;
96 }
82 if (frame_node->parent_frame_index >= 0) { 97 if (frame_node->parent_frame_index >= 0) {
83 SStringPrintf(&stringify_buffer, "%d", frame_node->parent_frame_index); 98 SStringPrintf(&stringify_buffer, "%d", frame_node->parent_frame_index);
84 frame_node_value->SetString("parent", stringify_buffer); 99 frame_node_value->SetString("parent", stringify_buffer);
85 } 100 }
86 frame_node_value->AppendAsTraceFormat(out); 101 frame_node_value->AppendAsTraceFormat(out);
87 102
88 i++; 103 i++;
89 frame_node++; 104 frame_node++;
90 105
91 if (frame_node != it_end) 106 if (frame_node != it_end)
(...skipping 15 matching lines...) Expand all
107 for (const FrameNode& node : frames_) 122 for (const FrameNode& node : frames_)
108 maps_size += node.children.size() * sizeof(std::pair<StackFrame, int>); 123 maps_size += node.children.size() * sizeof(std::pair<StackFrame, int>);
109 124
110 overhead->Add("StackFrameDeduplicator", 125 overhead->Add("StackFrameDeduplicator",
111 sizeof(StackFrameDeduplicator) + maps_size + frames_allocated, 126 sizeof(StackFrameDeduplicator) + maps_size + frames_allocated,
112 sizeof(StackFrameDeduplicator) + maps_size + frames_resident); 127 sizeof(StackFrameDeduplicator) + maps_size + frames_resident);
113 } 128 }
114 129
115 } // namespace trace_event 130 } // namespace trace_event
116 } // namespace base 131 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698