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

Side by Side Diff: content/common/discardable_shared_memory_heap_unittest.cc

Issue 1306243003: Add support to create memory allocator dump in base::DiscardableMemory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits. 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/common/discardable_shared_memory_heap.h" 5 #include "content/common/discardable_shared_memory_heap.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/discardable_shared_memory.h" 8 #include "base/memory/discardable_shared_memory.h"
9 #include "base/process/process_metrics.h" 9 #include "base/process/process_metrics.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 scoped_ptr<DiscardableSharedMemoryHeap::Span> span = 295 scoped_ptr<DiscardableSharedMemoryHeap::Span> span =
296 heap.Grow(memory.Pass(), block_size, next_discardable_shared_memory_id++, 296 heap.Grow(memory.Pass(), block_size, next_discardable_shared_memory_id++,
297 base::Bind(OnDeleted, base::Unretained(&deleted))); 297 base::Bind(OnDeleted, base::Unretained(&deleted)));
298 298
299 heap.MergeIntoFreeLists(span.Pass()); 299 heap.MergeIntoFreeLists(span.Pass());
300 heap.ReleaseFreeMemory(); 300 heap.ReleaseFreeMemory();
301 301
302 EXPECT_TRUE(deleted); 302 EXPECT_TRUE(deleted);
303 } 303 }
304 304
305 TEST(DiscardableSharedMemoryHeapTest, CreateMemoryAllocatorDumpTest) {
306 size_t block_size = base::GetPageSize();
307 DiscardableSharedMemoryHeap heap(block_size);
308 int next_discardable_shared_memory_id = 0;
309
310 scoped_ptr<base::DiscardableSharedMemory> memory(
311 new base::DiscardableSharedMemory);
312 ASSERT_TRUE(memory->CreateAndMap(block_size));
313 scoped_ptr<DiscardableSharedMemoryHeap::Span> span =
314 heap.Grow(memory.Pass(), block_size, next_discardable_shared_memory_id++,
315 base::Bind(NullTask));
316
317 // Unlock memory so it can be purged.
318 span->shared_memory()->Unlock(0, 0);
reveman 2015/08/22 14:21:16 Keep in mind that there's no guarantee that memory
ssid 2015/08/22 14:50:19 Ah, yes. I will move this after create dump, I did
ssid 2015/08/24 14:52:10 Done.
319
320 // Check if allocator dump is created when span exists.
321 scoped_ptr<base::trace_event::ProcessMemoryDump> pmd(
322 new base::trace_event::ProcessMemoryDump(nullptr));
323 EXPECT_TRUE(heap.CreateMemoryAllocatorDump(span.get(), "discardable/test1",
324 pmd.get()) != nullptr);
325
326 // Purge and release shared memory.
327 bool rv = span->shared_memory()->Purge(base::Time::Now());
328 EXPECT_TRUE(rv);
329 heap.ReleasePurgedMemory();
330
331 // Check that allocator dump is not created after memory is purged.
332 EXPECT_TRUE(heap.CreateMemoryAllocatorDump(span.get(), "discardable/test2",
reveman 2015/08/21 18:05:24 hm, do we need a test for this? I'm worried that s
ssid 2015/08/21 19:02:30 If you feel that then I will remove the purging pa
reveman 2015/08/22 14:21:16 You can keep the purging part but don't rely on so
ssid 2015/08/24 14:52:10 Done.
333 pmd.get()) == nullptr);
334 }
335
305 } // namespace 336 } // namespace
306 } // namespace content 337 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698