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

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

Issue 1100173002: Add a WinHeap dump provider to the memory profiler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/trace_event/winheap_dump_provider.h"
6
7 #include <windows.h>
8
9 #include "base/trace_event/memory_dump_session_state.h"
10 #include "base/trace_event/process_memory_dump.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace base {
14 namespace trace_event {
15
16 namespace {
17
18 class TestWinHeapDumpProvider : public WinHeapDumpProvider {
Primiano Tucci (use gerrit) 2015/04/22 23:48:32 Uhm a bit curious about this: it seems to not add
Sébastien Marchand 2015/04/23 10:52:03 I just used this to expose some protected function
19 public:
20 using WinHeapDumpProvider::GetHeapInformation;
chrisha 2015/04/23 09:23:27 As suggested by Primiano, if you simply 'friend' t
Sébastien Marchand 2015/04/23 10:52:03 Yeah, I still need to put an accessor in the WinHe
21
22 static TestWinHeapDumpProvider* GetInstance() {
23 COMPILE_ASSERT(
24 sizeof(TestWinHeapDumpProvider) == sizeof(WinHeapDumpProvider),
25 TestWinHeapDumpProvider_should_be_an_interface);
26 return reinterpret_cast<TestWinHeapDumpProvider*>(
27 WinHeapDumpProvider::GetInstance());
28 }
29 };
30
31 } // namespace
32
33 TEST(WinHeapDumpProviderTest, DumpInto) {
34 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
35
36 TestWinHeapDumpProvider* winheap_dump_provider =
37 TestWinHeapDumpProvider::GetInstance();
38 ASSERT_NE(reinterpret_cast<TestWinHeapDumpProvider*>(nullptr),
39 winheap_dump_provider);
40
41 pmd.session_state()->allocators_attributes_type_info.Update(
42 winheap_dump_provider->allocator_attributes_type_info());
Primiano Tucci (use gerrit) 2015/04/22 23:48:32 I think you are not using any attribute, right? th
Sébastien Marchand 2015/04/23 10:52:03 Yeah, I thought that it was required for the |set_
43
44 ASSERT_TRUE(winheap_dump_provider->DumpInto(&pmd));
45 }
46
47 TEST(WinHeapDumpProviderTest, GetHeapInformation) {
48 ProcessMemoryDump pmd(make_scoped_refptr(new MemoryDumpSessionState()));
49
50 TestWinHeapDumpProvider* winheap_dump_provider =
51 TestWinHeapDumpProvider::GetInstance();
52 ASSERT_NE(reinterpret_cast<TestWinHeapDumpProvider*>(nullptr),
53 winheap_dump_provider);
54
55 HANDLE heap = ::HeapCreate(NULL, 0, 0);
56 ASSERT_NE(nullptr, heap);
57
58 const size_t kAllocSize = 42;
59 void* alloc = ::HeapAlloc(heap, 0, kAllocSize);
60 ASSERT_NE(nullptr, alloc);
61
62 WinHeapInfo heap_info = { 0 };
63 heap_info.heap_id = heap;
64 std::set<void*> block_to_skip;
65
66 // Put the allocation into the skip list and make sure that the provider
67 // ignore it.
chrisha 2015/04/23 09:23:27 ignores* it
Sébastien Marchand 2015/04/23 10:52:03 Done.
68 block_to_skip.insert(alloc);
69 ASSERT_TRUE(winheap_dump_provider->GetHeapInformation(&heap_info,
70 block_to_skip));
71 EXPECT_EQ(0U, heap_info.block_count);
72 EXPECT_EQ(0U, heap_info.allocated_size);
73 // We can't check the committed size here, as it can depend on the version of
74 // kernel32.dll.
75
76 // Remove the allocation from the skip list and check if it's analysed
77 // properlyly.
78 block_to_skip.erase(block_to_skip.find(alloc));
Primiano Tucci (use gerrit) 2015/04/22 23:48:32 I think you can omit the block_to_skip.find here a
Sébastien Marchand 2015/04/23 10:52:03 Good point... Fixed.
79 ASSERT_TRUE(winheap_dump_provider->GetHeapInformation(&heap_info,
80 block_to_skip));
81 EXPECT_EQ(1, heap_info.block_count);
82 EXPECT_EQ(kAllocSize, heap_info.allocated_size);
83 EXPECT_LT(kAllocSize, heap_info.committed_size);
84
85 EXPECT_TRUE(::HeapFree(heap, 0, alloc));
86 EXPECT_EQ(TRUE, ::HeapDestroy(heap));
87 }
88
89 } // namespace trace_event
90 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698