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/process_memory_dump.h" | 5 #include "base/trace_event/process_memory_dump.h" |
6 | 6 |
7 #include "base/memory/aligned_memory.h" | 7 #include "base/memory/aligned_memory.h" |
8 #include "base/process/process_metrics.h" | 8 #include "base/process/process_metrics.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/trace_event_argument.h" | 10 #include "base/trace_event/trace_event_argument.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 158 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
159 TEST(ProcessMemoryDumpTest, CountResidentBytes) { | 159 TEST(ProcessMemoryDumpTest, CountResidentBytes) { |
160 const size_t page_size = base::GetPageSize(); | 160 const size_t page_size = base::GetPageSize(); |
161 | 161 |
162 // Allocate few page of dirty memory and check if it is resident. | 162 // Allocate few page of dirty memory and check if it is resident. |
163 const size_t size1 = 5 * page_size; | 163 const size_t size1 = 5 * page_size; |
164 scoped_ptr<char, base::AlignedFreeDeleter> memory1( | 164 scoped_ptr<char, base::AlignedFreeDeleter> memory1( |
165 static_cast<char*>(base::AlignedAlloc(size1, page_size))); | 165 static_cast<char*>(base::AlignedAlloc(size1, page_size))); |
166 memset(memory1.get(), 0, size1); | 166 memset(memory1.get(), 0, size1); |
167 size_t res1 = ProcessMemoryDump::CountResidentBytes(memory1.get(), size1); | 167 size_t res1 = 0; |
168 ASSERT_EQ(res1, size1); | 168 bool ret = ProcessMemoryDump::CountResidentBytes(memory1.get(), size1, &res1); |
| 169 ASSERT_TRUE(ret); |
| 170 ASSERT_EQ(size1, res1); |
169 | 171 |
170 // Allocate a large memory segment (>32Mib). | 172 // Allocate a large memory segment (>32Mib). |
171 const size_t kVeryLargeMemorySize = 34 * 1024 * 1024; | 173 const size_t kVeryLargeMemorySize = 34 * 1024 * 1024; |
172 scoped_ptr<char, base::AlignedFreeDeleter> memory2( | 174 scoped_ptr<char, base::AlignedFreeDeleter> memory2( |
173 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); | 175 static_cast<char*>(base::AlignedAlloc(kVeryLargeMemorySize, page_size))); |
174 memset(memory2.get(), 0, kVeryLargeMemorySize); | 176 memset(memory2.get(), 0, kVeryLargeMemorySize); |
175 size_t res2 = ProcessMemoryDump::CountResidentBytes(memory2.get(), | 177 size_t res2 = 0; |
176 kVeryLargeMemorySize); | 178 ret = ProcessMemoryDump::CountResidentBytes(memory2.get(), |
177 ASSERT_EQ(res2, kVeryLargeMemorySize); | 179 kVeryLargeMemorySize, &res2); |
| 180 ASSERT_TRUE(ret); |
| 181 ASSERT_EQ(kVeryLargeMemorySize, res2); |
178 } | 182 } |
179 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 183 #endif // defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
180 | 184 |
181 } // namespace trace_event | 185 } // namespace trace_event |
182 } // namespace base | 186 } // namespace base |
OLD | NEW |