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

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: Add type to StackFrame; format thread name 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(StackFrame frame,
20 int parent_frame_index) 21 int parent_frame_index)
21 : frame(frame), parent_frame_index(parent_frame_index) {} 22 : frame(frame), parent_frame_index(parent_frame_index) {}
22 StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default; 23 StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default;
23 StackFrameDeduplicator::FrameNode::~FrameNode() {} 24 StackFrameDeduplicator::FrameNode::~FrameNode() {}
24 25
25 StackFrameDeduplicator::StackFrameDeduplicator() {} 26 StackFrameDeduplicator::StackFrameDeduplicator() {}
26 StackFrameDeduplicator::~StackFrameDeduplicator() {} 27 StackFrameDeduplicator::~StackFrameDeduplicator() {}
27 28
28 int StackFrameDeduplicator::Insert(const StackFrame* beginFrame, 29 int StackFrameDeduplicator::Insert(const StackFrame* beginFrame,
29 const StackFrame* endFrame) { 30 const StackFrame* endFrame) {
30 int frame_index = -1; 31 int frame_index = -1;
31 std::map<StackFrame, int>* nodes = &roots_; 32 std::map<StackFrame, int>* nodes = &roots_;
32 33
33 // Loop through the frames, early out when a frame is null. 34 // Loop through the frames, early out when a frame is null.
34 for (const StackFrame* it = beginFrame; it != endFrame && *it; it++) { 35 for (const StackFrame* it = beginFrame;
36 it != endFrame && !it->empty();
37 it++) {
35 StackFrame frame = *it; 38 StackFrame frame = *it;
36 39
37 auto node = nodes->find(frame); 40 auto node = nodes->find(frame);
38 if (node == nodes->end()) { 41 if (node == nodes->end()) {
39 // There is no tree node for this frame yet, create it. The parent node 42 // There is no tree node for this frame yet, create it. The parent node
40 // is the node associated with the previous frame. 43 // is the node associated with the previous frame.
41 FrameNode frame_node(frame, frame_index); 44 FrameNode frame_node(frame, frame_index);
42 45
43 // The new frame node will be appended, so its index is the current size 46 // The new frame node will be appended, so its index is the current size
44 // of the vector. 47 // of the vector.
(...skipping 26 matching lines...) Expand all
71 74
72 while (frame_node != it_end) { 75 while (frame_node != it_end) {
73 // The |stackFrames| format is a dictionary, not an array, so the 76 // The |stackFrames| format is a dictionary, not an array, so the
74 // keys are stringified indices. Write the index manually, then use 77 // keys are stringified indices. Write the index manually, then use
75 // |TracedValue| to format the object. This is to avoid building the 78 // |TracedValue| to format the object. This is to avoid building the
76 // entire dictionary as a |TracedValue| in memory. 79 // entire dictionary as a |TracedValue| in memory.
77 SStringPrintf(&stringify_buffer, "\"%d\":", i); 80 SStringPrintf(&stringify_buffer, "\"%d\":", i);
78 out->append(stringify_buffer); 81 out->append(stringify_buffer);
79 82
80 std::unique_ptr<TracedValue> frame_node_value(new TracedValue); 83 std::unique_ptr<TracedValue> frame_node_value(new TracedValue);
81 frame_node_value->SetString("name", frame_node->frame); 84 const StackFrame& frame = frame_node->frame;
85 switch (frame.type) {
86 case StackFrame::TYPE_SYMBOL:
87 frame_node_value->SetString(
88 "name", static_cast<const char*>(frame.value));
89 break;
90 case StackFrame::TYPE_THREAD_NAME:
91 SStringPrintf(&stringify_buffer,
92 "[Thread: %s]",
93 static_cast<const char*>(frame.value));
94 frame_node_value->SetString("name", stringify_buffer);
95 break;
96 case StackFrame::TYPE_PC:
97 SStringPrintf(&stringify_buffer,
98 "pc:%" PRIxPTR,
99 reinterpret_cast<uintptr_t>(frame.value));
100 frame_node_value->SetString("name", stringify_buffer);
101 break;
102 }
82 if (frame_node->parent_frame_index >= 0) { 103 if (frame_node->parent_frame_index >= 0) {
83 SStringPrintf(&stringify_buffer, "%d", frame_node->parent_frame_index); 104 SStringPrintf(&stringify_buffer, "%d", frame_node->parent_frame_index);
84 frame_node_value->SetString("parent", stringify_buffer); 105 frame_node_value->SetString("parent", stringify_buffer);
85 } 106 }
86 frame_node_value->AppendAsTraceFormat(out); 107 frame_node_value->AppendAsTraceFormat(out);
87 108
88 i++; 109 i++;
89 frame_node++; 110 frame_node++;
90 111
91 if (frame_node != it_end) 112 if (frame_node != it_end)
(...skipping 15 matching lines...) Expand all
107 for (const FrameNode& node : frames_) 128 for (const FrameNode& node : frames_)
108 maps_size += node.children.size() * sizeof(std::pair<StackFrame, int>); 129 maps_size += node.children.size() * sizeof(std::pair<StackFrame, int>);
109 130
110 overhead->Add("StackFrameDeduplicator", 131 overhead->Add("StackFrameDeduplicator",
111 sizeof(StackFrameDeduplicator) + maps_size + frames_allocated, 132 sizeof(StackFrameDeduplicator) + maps_size + frames_allocated,
112 sizeof(StackFrameDeduplicator) + maps_size + frames_resident); 133 sizeof(StackFrameDeduplicator) + maps_size + frames_resident);
113 } 134 }
114 135
115 } // namespace trace_event 136 } // namespace trace_event
116 } // namespace base 137 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698