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

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

Issue 1375963007: [tracing] Display the resident size of the discardable memory segments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lock_discardable
Patch Set: Fixes. Created 5 years, 2 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 "base/trace_event/process_memory_dump.h" 5 #include "base/trace_event/process_memory_dump.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/process/process_metrics.h"
8 #include "base/trace_event/memory_allocator_dump_guid.h" 9 #include "base/trace_event/memory_allocator_dump_guid.h"
9 #include "base/trace_event/trace_event_argument.h" 10 #include "base/trace_event/trace_event_argument.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace base { 13 namespace base {
13 namespace trace_event { 14 namespace trace_event {
14 15
15 TEST(ProcessMemoryDumpTest, Clear) { 16 TEST(ProcessMemoryDumpTest, Clear) {
16 scoped_ptr<ProcessMemoryDump> pmd1(new ProcessMemoryDump(nullptr)); 17 scoped_ptr<ProcessMemoryDump> pmd1(new ProcessMemoryDump(nullptr));
17 pmd1->CreateAllocatorDump("mad1"); 18 pmd1->CreateAllocatorDump("mad1");
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 ASSERT_TRUE(found_edge[0]); 148 ASSERT_TRUE(found_edge[0]);
148 ASSERT_TRUE(found_edge[1]); 149 ASSERT_TRUE(found_edge[1]);
149 150
150 // Check that calling AsValueInto() doesn't cause a crash. 151 // Check that calling AsValueInto() doesn't cause a crash.
151 scoped_refptr<TracedValue> traced_value(new TracedValue()); 152 scoped_refptr<TracedValue> traced_value(new TracedValue());
152 pmd->AsValueInto(traced_value.get()); 153 pmd->AsValueInto(traced_value.get());
153 154
154 pmd.reset(); 155 pmd.reset();
155 } 156 }
156 157
158 #if defined(OS_POSIX) && !defined(OS_NACL)
159 TEST(ProcessMemoryDumpTest, CountResidentBytes) {
160 const size_t page_size = base::GetPageSize();
161 // Allocate a segment on stack and check if the page is resident.
162 char memory1[100] = {0};
163 void* page_start1 = reinterpret_cast<void*>(
164 reinterpret_cast<uintptr_t>(memory1) / page_size * page_size);
165 ssize_t res1 = ProcessMemoryDump::CountResidentBytes(page_start1, page_size);
166 ASSERT_GE(static_cast<size_t>(res1), page_size);
167
168 // Allocate few page of dirty memory and check if it is resident.
169 scoped_ptr<char[]> memory2(new char[5 * page_size]());
170 void* page_start2 = reinterpret_cast<void*>(
171 reinterpret_cast<uintptr_t>(memory2.get()) / page_size * page_size);
172 ssize_t res2 =
173 ProcessMemoryDump::CountResidentBytes(page_start2, 5 * page_size);
174 ASSERT_NE(-1, res2);
175 ASSERT_GE(static_cast<size_t>(res2), 5 * page_size);
176
177 // Allocate a large memory segment (>32Mib).
178 const size_t kVeryLargeMemorySize = 34 * 1024 * 1024;
179 scoped_ptr<char[]> memory3(new char[kVeryLargeMemorySize]());
180 void* page_start3 = reinterpret_cast<void*>(
181 reinterpret_cast<uintptr_t>(memory3.get()) / page_size * page_size);
182 ssize_t res3 =
183 ProcessMemoryDump::CountResidentBytes(page_start3, kVeryLargeMemorySize);
184 ASSERT_NE(-1, res3);
185 ASSERT_GE(static_cast<size_t>(res3), kVeryLargeMemorySize);
186 }
187 #endif // defined(OS_POSIX) && !defined(OS_NACL)
188
157 } // namespace trace_event 189 } // namespace trace_event
158 } // namespace base 190 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698