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

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

Issue 1822013002: Revert of tracing: add dump provider for malloc heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shim_layer_linux
Patch Set: Created 4 years, 9 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/trace_event/heap_profiler_allocation_context.h" 10 #include "base/trace_event/heap_profiler_allocation_context.h"
11 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 11 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace base { 15 namespace base {
16 namespace trace_event { 16 namespace trace_event {
17 17
18 // Define all strings once, because the pseudo stack requires pointer equality, 18 // Define all strings once, because the pseudo stack requires pointer equality,
19 // and string interning is unreliable. 19 // and string interning is unreliable.
20 const char kCupcake[] = "Cupcake"; 20 const char kCupcake[] = "Cupcake";
21 const char kDonut[] = "Donut"; 21 const char kDonut[] = "Donut";
22 const char kEclair[] = "Eclair"; 22 const char kEclair[] = "Eclair";
23 const char kFroyo[] = "Froyo"; 23 const char kFroyo[] = "Froyo";
24 const char kGingerbread[] = "Gingerbread"; 24 const char kGingerbread[] = "Gingerbread";
25 25
26 // Asserts that the fixed-size array |expected_backtrace| matches the backtrace 26 // Asserts that the fixed-size array |expected_backtrace| matches the backtrace
27 // in |AllocationContextTracker::GetContextSnapshot|. 27 // in |AllocationContextTracker::GetContextSnapshot|.
28 template <size_t N> 28 template <size_t N>
29 void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) { 29 void AssertBacktraceEquals(const StackFrame(&expected_backtrace)[N]) {
30 AllocationContext ctx = 30 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot();
31 AllocationContextTracker::GetInstanceForCurrentThread()
32 ->GetContextSnapshot();
33 31
34 auto actual = std::begin(ctx.backtrace.frames); 32 auto actual = std::begin(ctx.backtrace.frames);
35 auto actual_bottom = std::end(ctx.backtrace.frames); 33 auto actual_bottom = std::end(ctx.backtrace.frames);
36 auto expected = std::begin(expected_backtrace); 34 auto expected = std::begin(expected_backtrace);
37 auto expected_bottom = std::end(expected_backtrace); 35 auto expected_bottom = std::end(expected_backtrace);
38 36
39 // Note that this requires the pointers to be equal, this is not doing a deep 37 // Note that this requires the pointers to be equal, this is not doing a deep
40 // string comparison. 38 // string comparison.
41 for (; actual != actual_bottom && expected != expected_bottom; 39 for (; actual != actual_bottom && expected != expected_bottom;
42 actual++, expected++) 40 actual++, expected++)
43 ASSERT_EQ(*expected, *actual); 41 ASSERT_EQ(*expected, *actual);
44 42
45 // Ensure that the height of the stacks is the same. 43 // Ensure that the height of the stacks is the same.
46 ASSERT_EQ(actual, actual_bottom); 44 ASSERT_EQ(actual, actual_bottom);
47 ASSERT_EQ(expected, expected_bottom); 45 ASSERT_EQ(expected, expected_bottom);
48 } 46 }
49 47
50 void AssertBacktraceEmpty() { 48 void AssertBacktraceEmpty() {
51 AllocationContext ctx = 49 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot();
52 AllocationContextTracker::GetInstanceForCurrentThread()
53 ->GetContextSnapshot();
54 50
55 for (StackFrame frame : ctx.backtrace.frames) 51 for (StackFrame frame : ctx.backtrace.frames)
56 ASSERT_EQ(nullptr, frame); 52 ASSERT_EQ(nullptr, frame);
57 } 53 }
58 54
59 class AllocationContextTrackerTest : public testing::Test { 55 class AllocationContextTrackerTest : public testing::Test {
60 public: 56 public:
61 void SetUp() override { 57 void SetUp() override {
62 TraceConfig config(""); 58 TraceConfig config("");
63 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE); 59 TraceLog::GetInstance()->SetEnabled(config, TraceLog::RECORDING_MODE);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 TRACE_EVENT0("Testing", kCupcake); 200 TRACE_EVENT0("Testing", kCupcake);
205 TRACE_EVENT0("Testing", kCupcake); 201 TRACE_EVENT0("Testing", kCupcake);
206 202
207 TRACE_EVENT0("Testing", kCupcake); 203 TRACE_EVENT0("Testing", kCupcake);
208 TRACE_EVENT0("Testing", kDonut); 204 TRACE_EVENT0("Testing", kDonut);
209 TRACE_EVENT0("Testing", kEclair); 205 TRACE_EVENT0("Testing", kEclair);
210 TRACE_EVENT0("Testing", kFroyo); 206 TRACE_EVENT0("Testing", kFroyo);
211 207
212 { 208 {
213 TRACE_EVENT0("Testing", kGingerbread); 209 TRACE_EVENT0("Testing", kGingerbread);
214 AllocationContext ctx = 210 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot();
215 AllocationContextTracker::GetInstanceForCurrentThread()
216 ->GetContextSnapshot();
217 211
218 // The pseudo stack relies on pointer equality, not deep string comparisons. 212 // The pseudo stack relies on pointer equality, not deep string comparisons.
219 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]); 213 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]);
220 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]); 214 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]);
221 } 215 }
222 216
223 { 217 {
224 AllocationContext ctx = 218 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot();
225 AllocationContextTracker::GetInstanceForCurrentThread()
226 ->GetContextSnapshot();
227 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]); 219 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]);
228 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]); 220 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]);
229 } 221 }
230 } 222 }
231 223
232 } // namespace trace_event 224 } // namespace trace_event
233 } // namespace base 225 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_allocation_context_tracker.cc ('k') | base/trace_event/malloc_dump_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698