| 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_allocation_register.h" | 5 #include "base/trace_event/heap_profiler_allocation_register.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/process/process_metrics.h" | 10 #include "base/process/process_metrics.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 reg.Remove(reinterpret_cast<void*>(4)); // Remove never inserted address. | 100 reg.Remove(reinterpret_cast<void*>(4)); // Remove never inserted address. |
| 101 | 101 |
| 102 EXPECT_EQ(2u, OrAllAddresses(reg)); | 102 EXPECT_EQ(2u, OrAllAddresses(reg)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 TEST_F(AllocationRegisterTest, DoubleInsertOverwrites) { | 105 TEST_F(AllocationRegisterTest, DoubleInsertOverwrites) { |
| 106 // TODO(ruuda): Although double insert happens in practice, it should not. | 106 // TODO(ruuda): Although double insert happens in practice, it should not. |
| 107 // Find out the cause and ban double insert if possible. | 107 // Find out the cause and ban double insert if possible. |
| 108 AllocationRegister reg; | 108 AllocationRegister reg; |
| 109 AllocationContext ctx = AllocationContext::Empty(); | 109 AllocationContext ctx = AllocationContext::Empty(); |
| 110 StackFrame frame1 = "Foo"; | 110 StackFrame frame1 = StackFrame::FromTraceEventName("Foo"); |
| 111 StackFrame frame2 = "Bar"; | 111 StackFrame frame2 = StackFrame::FromTraceEventName("Bar"); |
| 112 |
| 113 ctx.backtrace.frame_count = 1; |
| 112 | 114 |
| 113 ctx.backtrace.frames[0] = frame1; | 115 ctx.backtrace.frames[0] = frame1; |
| 114 reg.Insert(reinterpret_cast<void*>(1), 11, ctx); | 116 reg.Insert(reinterpret_cast<void*>(1), 11, ctx); |
| 115 | 117 |
| 116 { | 118 { |
| 117 AllocationRegister::Allocation elem = *reg.begin(); | 119 AllocationRegister::Allocation elem = *reg.begin(); |
| 118 | 120 |
| 119 EXPECT_EQ(frame1, elem.context.backtrace.frames[0]); | 121 EXPECT_EQ(frame1, elem.context.backtrace.frames[0]); |
| 120 EXPECT_EQ(11u, elem.size); | 122 EXPECT_EQ(11u, elem.size); |
| 121 EXPECT_EQ(reinterpret_cast<void*>(1), elem.address); | 123 EXPECT_EQ(reinterpret_cast<void*>(1), elem.address); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 const size_t cells_per_page = GetNumCellsPerPage(); | 282 const size_t cells_per_page = GetNumCellsPerPage(); |
| 281 | 283 |
| 282 ASSERT_DEATH(for (size_t j = 0; j < cells_per_page; j++) { | 284 ASSERT_DEATH(for (size_t j = 0; j < cells_per_page; j++) { |
| 283 reg.Insert(reinterpret_cast<void*>(i + j), 1, ctx); | 285 reg.Insert(reinterpret_cast<void*>(i + j), 1, ctx); |
| 284 }, ""); | 286 }, ""); |
| 285 } | 287 } |
| 286 #endif | 288 #endif |
| 287 | 289 |
| 288 } // namespace trace_event | 290 } // namespace trace_event |
| 289 } // namespace base | 291 } // namespace base |
| OLD | NEW |