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

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

Issue 1262333005: [tracing] Introduce MemoryDumpArgs to enable light and heavy dumps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 4 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
« no previous file with comments | « base/trace_event/malloc_dump_provider.cc ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/memory_allocator_dump.h" 5 #include "base/trace_event/memory_allocator_dump.h"
6 6
7 #include "base/format_macros.h" 7 #include "base/format_macros.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/trace_event/memory_allocator_dump_guid.h" 9 #include "base/trace_event/memory_allocator_dump_guid.h"
10 #include "base/trace_event/memory_dump_provider.h" 10 #include "base/trace_event/memory_dump_provider.h"
11 #include "base/trace_event/memory_dump_session_state.h" 11 #include "base/trace_event/memory_dump_session_state.h"
12 #include "base/trace_event/process_memory_dump.h" 12 #include "base/trace_event/process_memory_dump.h"
13 #include "base/trace_event/trace_event_argument.h" 13 #include "base/trace_event/trace_event_argument.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace base { 17 namespace base {
18 namespace trace_event { 18 namespace trace_event {
19 19
20 namespace { 20 namespace {
21 21
22 class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider { 22 class FakeMemoryAllocatorDumpProvider : public MemoryDumpProvider {
23 public: 23 public:
24 bool OnMemoryDump(ProcessMemoryDump* pmd) override { 24 bool OnMemoryDump(const MemoryDumpArgs& args,
25 ProcessMemoryDump* pmd) override {
25 MemoryAllocatorDump* root_heap = 26 MemoryAllocatorDump* root_heap =
26 pmd->CreateAllocatorDump("foobar_allocator"); 27 pmd->CreateAllocatorDump("foobar_allocator");
27 28
28 root_heap->AddScalar(MemoryAllocatorDump::kNameSize, 29 root_heap->AddScalar(MemoryAllocatorDump::kNameSize,
29 MemoryAllocatorDump::kUnitsBytes, 4096); 30 MemoryAllocatorDump::kUnitsBytes, 4096);
30 root_heap->AddScalar(MemoryAllocatorDump::kNameObjectsCount, 31 root_heap->AddScalar(MemoryAllocatorDump::kNameObjectsCount,
31 MemoryAllocatorDump::kUnitsObjects, 42); 32 MemoryAllocatorDump::kUnitsObjects, 42);
32 root_heap->AddScalar("attr1", "units1", 1234); 33 root_heap->AddScalar("attr1", "units1", 1234);
33 root_heap->AddString("attr2", "units2", "string_value"); 34 root_heap->AddString("attr2", "units2", "string_value");
34 root_heap->AddScalarF("attr3", "units3", 42.5f); 35 root_heap->AddScalarF("attr3", "units3", 42.5f);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 ASSERT_EQ(guid_bar, guid_bar_2); 119 ASSERT_EQ(guid_bar, guid_bar_2);
119 120
120 mad.reset(new MemoryAllocatorDump("baz", nullptr)); 121 mad.reset(new MemoryAllocatorDump("baz", nullptr));
121 const MemoryAllocatorDumpGuid guid_baz = mad->guid(); 122 const MemoryAllocatorDumpGuid guid_baz = mad->guid();
122 ASSERT_NE(guid_bar, guid_baz); 123 ASSERT_NE(guid_bar, guid_baz);
123 } 124 }
124 125
125 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) { 126 TEST(MemoryAllocatorDumpTest, DumpIntoProcessMemoryDump) {
126 FakeMemoryAllocatorDumpProvider fmadp; 127 FakeMemoryAllocatorDumpProvider fmadp;
127 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState())); 128 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
129 MemoryDumpArgs dump_args = {MemoryDumpArgs::LEVEL_OF_DETAIL_HIGH};
128 130
129 fmadp.OnMemoryDump(&pmd); 131 fmadp.OnMemoryDump(dump_args, &pmd);
130 132
131 ASSERT_EQ(3u, pmd.allocator_dumps().size()); 133 ASSERT_EQ(3u, pmd.allocator_dumps().size());
132 134
133 const MemoryAllocatorDump* root_heap = 135 const MemoryAllocatorDump* root_heap =
134 pmd.GetAllocatorDump("foobar_allocator"); 136 pmd.GetAllocatorDump("foobar_allocator");
135 ASSERT_NE(nullptr, root_heap); 137 ASSERT_NE(nullptr, root_heap);
136 EXPECT_EQ("foobar_allocator", root_heap->absolute_name()); 138 EXPECT_EQ("foobar_allocator", root_heap->absolute_name());
137 CheckScalar(root_heap, MemoryAllocatorDump::kNameSize, 139 CheckScalar(root_heap, MemoryAllocatorDump::kNameSize,
138 MemoryAllocatorDump::kUnitsBytes, 4096); 140 MemoryAllocatorDump::kUnitsBytes, 4096);
139 CheckScalar(root_heap, MemoryAllocatorDump::kNameObjectsCount, 141 CheckScalar(root_heap, MemoryAllocatorDump::kNameObjectsCount,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 pmd.CreateAllocatorDump("foo_allocator"); 176 pmd.CreateAllocatorDump("foo_allocator");
175 pmd.CreateAllocatorDump("bar_allocator/heap"); 177 pmd.CreateAllocatorDump("bar_allocator/heap");
176 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), ""); 178 ASSERT_DEATH(pmd.CreateAllocatorDump("foo_allocator"), "");
177 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), ""); 179 ASSERT_DEATH(pmd.CreateAllocatorDump("bar_allocator/heap"), "");
178 ASSERT_DEATH(pmd.CreateAllocatorDump(""), ""); 180 ASSERT_DEATH(pmd.CreateAllocatorDump(""), "");
179 } 181 }
180 #endif 182 #endif
181 183
182 } // namespace trace_event 184 } // namespace trace_event
183 } // namespace base 185 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/malloc_dump_provider.cc ('k') | base/trace_event/memory_dump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698