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 <iterator> |
| 6 |
5 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
6 #include "base/trace_event/heap_profiler_allocation_context.h" | 8 #include "base/trace_event/heap_profiler_allocation_context.h" |
7 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 9 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" |
8 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 | 12 |
11 namespace base { | 13 namespace base { |
12 namespace trace_event { | 14 namespace trace_event { |
13 | 15 |
14 // Define all strings once, because the pseudo stack requires pointer equality, | 16 // Define all strings once, because the pseudo stack requires pointer equality, |
15 // and string interning is unreliable. | 17 // and string interning is unreliable. |
16 const char kCupcake[] = "Cupcake"; | 18 const char kCupcake[] = "Cupcake"; |
17 const char kDonut[] = "Donut"; | 19 const char kDonut[] = "Donut"; |
18 const char kEclair[] = "Eclair"; | 20 const char kEclair[] = "Eclair"; |
19 const char kFroyo[] = "Froyo"; | 21 const char kFroyo[] = "Froyo"; |
20 const char kGingerbread[] = "Gingerbread"; | 22 const char kGingerbread[] = "Gingerbread"; |
21 | 23 |
22 // Returns a pointer past the end of the fixed-size array |array| of |T| of | |
23 // length |N|, identical to C++11 |std::end|. | |
24 template <typename T, int N> | |
25 const T* End(const T(&array)[N]) { | |
26 return array + N; | |
27 } | |
28 | |
29 // Asserts that the fixed-size array |expected_backtrace| matches the backtrace | 24 // Asserts that the fixed-size array |expected_backtrace| matches the backtrace |
30 // in |AllocationContextTracker::GetContextSnapshot|. | 25 // in |AllocationContextTracker::GetContextSnapshot|. |
31 template <size_t N> | 26 template <size_t N> |
32 void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) { | 27 void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) { |
33 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot(); | 28 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot(); |
34 | 29 |
35 auto actual = ctx.backtrace.frames; | 30 auto actual = std::begin(ctx.backtrace.frames); |
36 auto actual_bottom = End(ctx.backtrace.frames); | 31 auto actual_bottom = std::end(ctx.backtrace.frames); |
37 auto expected = expected_backtrace; | 32 auto expected = std::begin(expected_backtrace); |
38 auto expected_bottom = End(expected_backtrace); | 33 auto expected_bottom = std::end(expected_backtrace); |
39 | 34 |
40 // Note that this requires the pointers to be equal, this is not doing a deep | 35 // Note that this requires the pointers to be equal, this is not doing a deep |
41 // string comparison. | 36 // string comparison. |
42 for (; actual != actual_bottom && expected != expected_bottom; | 37 for (; actual != actual_bottom && expected != expected_bottom; |
43 actual++, expected++) | 38 actual++, expected++) |
44 ASSERT_EQ(*expected, *actual); | 39 ASSERT_EQ(*expected, *actual); |
45 | 40 |
46 // Ensure that the height of the stacks is the same. | 41 // Ensure that the height of the stacks is the same. |
47 ASSERT_EQ(actual, actual_bottom); | 42 ASSERT_EQ(actual, actual_bottom); |
48 ASSERT_EQ(expected, expected_bottom); | 43 ASSERT_EQ(expected, expected_bottom); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 214 |
220 { | 215 { |
221 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot(); | 216 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot(); |
222 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]); | 217 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]); |
223 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]); | 218 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]); |
224 } | 219 } |
225 } | 220 } |
226 | 221 |
227 } // namespace trace_event | 222 } // namespace trace_event |
228 } // namespace base | 223 } // namespace base |
OLD | NEW |