| 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 #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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 StackFrameDeduplicator::StackFrameDeduplicator() {} | 25 StackFrameDeduplicator::StackFrameDeduplicator() {} |
| 26 StackFrameDeduplicator::~StackFrameDeduplicator() {} | 26 StackFrameDeduplicator::~StackFrameDeduplicator() {} |
| 27 | 27 |
| 28 int StackFrameDeduplicator::Insert(const StackFrame* beginFrame, | 28 int StackFrameDeduplicator::Insert(const StackFrame* beginFrame, |
| 29 const StackFrame* endFrame) { | 29 const StackFrame* endFrame) { |
| 30 int frame_index = -1; | 30 int frame_index = -1; |
| 31 std::map<StackFrame, int>* nodes = &roots_; | 31 std::map<StackFrame, int>* nodes = &roots_; |
| 32 | 32 |
| 33 // Loop through the frames, early out when a frame is null. | 33 // Loop through the frames, early out when a frame is null. |
| 34 for (const StackFrame* it = beginFrame; it != endFrame && *it; it++) { | 34 for (const StackFrame* it = beginFrame; it != endFrame; it++) { |
| 35 StackFrame frame = *it; | 35 StackFrame frame = *it; |
| 36 | 36 |
| 37 auto node = nodes->find(frame); | 37 auto node = nodes->find(frame); |
| 38 if (node == nodes->end()) { | 38 if (node == nodes->end()) { |
| 39 // There is no tree node for this frame yet, create it. The parent node | 39 // There is no tree node for this frame yet, create it. The parent node |
| 40 // is the node associated with the previous frame. | 40 // is the node associated with the previous frame. |
| 41 FrameNode frame_node(frame, frame_index); | 41 FrameNode frame_node(frame, frame_index); |
| 42 | 42 |
| 43 // The new frame node will be appended, so its index is the current size | 43 // The new frame node will be appended, so its index is the current size |
| 44 // of the vector. | 44 // of the vector. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 71 | 71 |
| 72 while (frame_node != it_end) { | 72 while (frame_node != it_end) { |
| 73 // The |stackFrames| format is a dictionary, not an array, so the | 73 // The |stackFrames| format is a dictionary, not an array, so the |
| 74 // keys are stringified indices. Write the index manually, then use | 74 // keys are stringified indices. Write the index manually, then use |
| 75 // |TracedValue| to format the object. This is to avoid building the | 75 // |TracedValue| to format the object. This is to avoid building the |
| 76 // entire dictionary as a |TracedValue| in memory. | 76 // entire dictionary as a |TracedValue| in memory. |
| 77 SStringPrintf(&stringify_buffer, "\"%d\":", i); | 77 SStringPrintf(&stringify_buffer, "\"%d\":", i); |
| 78 out->append(stringify_buffer); | 78 out->append(stringify_buffer); |
| 79 | 79 |
| 80 std::unique_ptr<TracedValue> frame_node_value(new TracedValue); | 80 std::unique_ptr<TracedValue> frame_node_value(new TracedValue); |
| 81 frame_node_value->SetString("name", frame_node->frame); | 81 const StackFrame& frame = frame_node->frame; |
| 82 switch (frame.type) { |
| 83 case StackFrame::Type::TRACE_EVENT_NAME: |
| 84 frame_node_value->SetString( |
| 85 "name", static_cast<const char*>(frame.value)); |
| 86 break; |
| 87 case StackFrame::Type::THREAD_NAME: |
| 88 SStringPrintf(&stringify_buffer, |
| 89 "[Thread: %s]", |
| 90 static_cast<const char*>(frame.value)); |
| 91 frame_node_value->SetString("name", stringify_buffer); |
| 92 break; |
| 93 } |
| 82 if (frame_node->parent_frame_index >= 0) { | 94 if (frame_node->parent_frame_index >= 0) { |
| 83 SStringPrintf(&stringify_buffer, "%d", frame_node->parent_frame_index); | 95 SStringPrintf(&stringify_buffer, "%d", frame_node->parent_frame_index); |
| 84 frame_node_value->SetString("parent", stringify_buffer); | 96 frame_node_value->SetString("parent", stringify_buffer); |
| 85 } | 97 } |
| 86 frame_node_value->AppendAsTraceFormat(out); | 98 frame_node_value->AppendAsTraceFormat(out); |
| 87 | 99 |
| 88 i++; | 100 i++; |
| 89 frame_node++; | 101 frame_node++; |
| 90 | 102 |
| 91 if (frame_node != it_end) | 103 if (frame_node != it_end) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 107 for (const FrameNode& node : frames_) | 119 for (const FrameNode& node : frames_) |
| 108 maps_size += node.children.size() * sizeof(std::pair<StackFrame, int>); | 120 maps_size += node.children.size() * sizeof(std::pair<StackFrame, int>); |
| 109 | 121 |
| 110 overhead->Add("StackFrameDeduplicator", | 122 overhead->Add("StackFrameDeduplicator", |
| 111 sizeof(StackFrameDeduplicator) + maps_size + frames_allocated, | 123 sizeof(StackFrameDeduplicator) + maps_size + frames_allocated, |
| 112 sizeof(StackFrameDeduplicator) + maps_size + frames_resident); | 124 sizeof(StackFrameDeduplicator) + maps_size + frames_resident); |
| 113 } | 125 } |
| 114 | 126 |
| 115 } // namespace trace_event | 127 } // namespace trace_event |
| 116 } // namespace base | 128 } // namespace base |
| OLD | NEW |