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

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

Issue 1095003002: [tracing] Simplify design of MemoryAllocatorDump (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@matr_2_sess
Patch Set: Rebase 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
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_provider.h » ('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_dump_manager.h" 5 #include "base/trace_event/memory_dump_manager.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 scoped_ptr<MessageLoop> message_loop_; 73 scoped_ptr<MessageLoop> message_loop_;
74 MemoryDumpManagerDelegateForTesting delegate_; 74 MemoryDumpManagerDelegateForTesting delegate_;
75 75
76 // We want our singleton torn down after each test. 76 // We want our singleton torn down after each test.
77 ShadowingAtExitManager at_exit_manager_; 77 ShadowingAtExitManager at_exit_manager_;
78 }; 78 };
79 79
80 class MockDumpProvider : public MemoryDumpProvider { 80 class MockDumpProvider : public MemoryDumpProvider {
81 public: 81 public:
82 MockDumpProvider() {} 82 MockDumpProvider() {}
83 MockDumpProvider(const scoped_refptr<SingleThreadTaskRunner>& task_runner) 83
84 explicit MockDumpProvider(
85 const scoped_refptr<SingleThreadTaskRunner>& task_runner)
84 : MemoryDumpProvider(task_runner) {} 86 : MemoryDumpProvider(task_runner) {}
87
88 // Ctor for the SharedSessionState test.
89 explicit MockDumpProvider(const std::string& id) {
90 DeclareAllocatorAttribute("allocator" + id, "attr" + id, "type" + id);
91 }
92
85 MOCK_METHOD1(DumpInto, bool(ProcessMemoryDump* pmd)); 93 MOCK_METHOD1(DumpInto, bool(ProcessMemoryDump* pmd));
86 94
87 // DumpInto() override for the ActiveDumpProviderConsistency test. 95 // DumpInto() override for the ActiveDumpProviderConsistency test.
88 bool DumpIntoAndCheckDumpProviderCurrentlyActive(ProcessMemoryDump* pmd) { 96 bool DumpIntoAndCheckDumpProviderCurrentlyActive(ProcessMemoryDump* pmd) {
89 EXPECT_EQ( 97 EXPECT_EQ(
90 this, 98 this,
91 MemoryDumpManager::GetInstance()->dump_provider_currently_active()); 99 MemoryDumpManager::GetInstance()->dump_provider_currently_active());
92 return true; 100 return true;
93 } 101 }
94 102
95 // DumpInto() override for the RespectTaskRunnerAffinity test. 103 // DumpInto() override for the RespectTaskRunnerAffinity test.
96 bool DumpIntoAndCheckTaskRunner(ProcessMemoryDump* pmd) { 104 bool DumpIntoAndCheckTaskRunner(ProcessMemoryDump* pmd) {
97 EXPECT_TRUE(task_runner()->RunsTasksOnCurrentThread()); 105 EXPECT_TRUE(task_runner()->RunsTasksOnCurrentThread());
98 return true; 106 return true;
99 } 107 }
100 108
109 // DumpInto() override for the SharedSessionState test.
110 bool DumpIntoAndCheckSessionState(ProcessMemoryDump* pmd) {
111 EXPECT_TRUE(pmd->session_state());
112 const auto& attrs_type_info =
113 pmd->session_state()->allocators_attributes_type_info;
114 EXPECT_TRUE(attrs_type_info.Exists("allocator1", "attr1"));
115 EXPECT_TRUE(attrs_type_info.Exists("allocator2", "attr2"));
116 return true;
117 }
118
101 const char* GetFriendlyName() const override { return "MockDumpProvider"; } 119 const char* GetFriendlyName() const override { return "MockDumpProvider"; }
102 }; 120 };
103 121
104 TEST_F(MemoryDumpManagerTest, SingleDumper) { 122 TEST_F(MemoryDumpManagerTest, SingleDumper) {
105 MockDumpProvider mdp; 123 MockDumpProvider mdp;
106 mdm_->RegisterDumpProvider(&mdp); 124 mdm_->RegisterDumpProvider(&mdp);
107 125
108 // Check that the dumper is not called if the memory category is not enabled. 126 // Check that the dumper is not called if the memory category is not enabled.
109 EnableTracing("foo-and-bar-but-not-memory"); 127 EnableTracing("foo-and-bar-but-not-memory");
110 EXPECT_CALL(mdp, DumpInto(_)).Times(0); 128 EXPECT_CALL(mdp, DumpInto(_)).Times(0);
(...skipping 10 matching lines...) Expand all
121 139
122 mdm_->UnregisterDumpProvider(&mdp); 140 mdm_->UnregisterDumpProvider(&mdp);
123 141
124 // Finally check the unregister logic (no calls to the mdp after unregister). 142 // Finally check the unregister logic (no calls to the mdp after unregister).
125 EnableTracing(kTraceCategory); 143 EnableTracing(kTraceCategory);
126 EXPECT_CALL(mdp, DumpInto(_)).Times(0); 144 EXPECT_CALL(mdp, DumpInto(_)).Times(0);
127 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 145 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED);
128 TraceLog::GetInstance()->SetDisabled(); 146 TraceLog::GetInstance()->SetDisabled();
129 } 147 }
130 148
149 TEST_F(MemoryDumpManagerTest, SharedSessionState) {
150 MockDumpProvider mdp1("1"); // Will declare an allocator property "attr1".
151 MockDumpProvider mdp2("2"); // Will declare an allocator property "attr2".
152 mdm_->RegisterDumpProvider(&mdp1);
153 mdm_->RegisterDumpProvider(&mdp2);
154
155 EnableTracing(kTraceCategory);
156 EXPECT_CALL(mdp1, DumpInto(_)).Times(2).WillRepeatedly(
157 Invoke(&mdp1, &MockDumpProvider::DumpIntoAndCheckSessionState));
158 EXPECT_CALL(mdp2, DumpInto(_)).Times(2).WillRepeatedly(
159 Invoke(&mdp2, &MockDumpProvider::DumpIntoAndCheckSessionState));
160
161 for (int i = 0; i < 2; ++i)
162 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED);
163
164 DisableTracing();
165 }
166
131 TEST_F(MemoryDumpManagerTest, MultipleDumpers) { 167 TEST_F(MemoryDumpManagerTest, MultipleDumpers) {
132 MockDumpProvider mdp1; 168 MockDumpProvider mdp1;
133 MockDumpProvider mdp2; 169 MockDumpProvider mdp2;
134 170
135 // Enable only mdp1. 171 // Enable only mdp1.
136 mdm_->RegisterDumpProvider(&mdp1); 172 mdm_->RegisterDumpProvider(&mdp1);
137 EnableTracing(kTraceCategory); 173 EnableTracing(kTraceCategory);
138 EXPECT_CALL(mdp1, DumpInto(_)).Times(1).WillRepeatedly(Return(true)); 174 EXPECT_CALL(mdp1, DumpInto(_)).Times(1).WillRepeatedly(Return(true));
139 EXPECT_CALL(mdp2, DumpInto(_)).Times(0); 175 EXPECT_CALL(mdp2, DumpInto(_)).Times(0);
140 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 176 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 .WillRepeatedly(Invoke( 295 .WillRepeatedly(Invoke(
260 &mdp2, 296 &mdp2,
261 &MockDumpProvider::DumpIntoAndCheckDumpProviderCurrentlyActive)); 297 &MockDumpProvider::DumpIntoAndCheckDumpProviderCurrentlyActive));
262 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 298 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED);
263 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED); 299 mdm_->RequestGlobalDump(MemoryDumpType::EXPLICITLY_TRIGGERED);
264 DisableTracing(); 300 DisableTracing();
265 } 301 }
266 302
267 } // namespace trace_event 303 } // namespace trace_event
268 } // namespace base 304 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/memory_dump_manager.cc ('k') | base/trace_event/memory_dump_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698