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

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

Issue 2799023002: memory-infra: Switch to MemoryPeakDetector and simplify MemoryDumpScheduler (Closed)
Patch Set: . Created 3 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Turns a Closure into a MemoryDumpCallback, keeping track of the callback 237 // Turns a Closure into a MemoryDumpCallback, keeping track of the callback
238 // result and taking care of posting the closure on the correct task runner. 238 // result and taking care of posting the closure on the correct task runner.
239 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner, 239 void DumpCallbackAdapter(scoped_refptr<SingleThreadTaskRunner> task_runner,
240 Closure closure, 240 Closure closure,
241 uint64_t dump_guid, 241 uint64_t dump_guid,
242 bool success) { 242 bool success) {
243 last_callback_success_ = success; 243 last_callback_success_ = success;
244 task_runner->PostTask(FROM_HERE, closure); 244 task_runner->PostTask(FROM_HERE, closure);
245 } 245 }
246 246
247 void PollFastMemoryTotal(uint64_t* memory_total) {
248 mdm_->PollFastMemoryTotal(memory_total);
249 }
250
251 protected: 247 protected:
252 void InitializeMemoryDumpManager(bool is_coordinator) { 248 void InitializeMemoryDumpManager(bool is_coordinator) {
253 mdm_->set_dumper_registrations_ignored_for_testing(true); 249 mdm_->set_dumper_registrations_ignored_for_testing(true);
254 delegate_ = new MemoryDumpManagerDelegateForTesting(is_coordinator); 250 delegate_ = new MemoryDumpManagerDelegateForTesting(is_coordinator);
255 mdm_->Initialize(base::WrapUnique(delegate_)); 251 mdm_->Initialize(base::WrapUnique(delegate_));
256 } 252 }
257 253
258 void RequestGlobalDumpAndWait(MemoryDumpType dump_type, 254 void RequestGlobalDumpAndWait(MemoryDumpType dump_type,
259 MemoryDumpLevelOfDetail level_of_detail) { 255 MemoryDumpLevelOfDetail level_of_detail) {
260 RunLoop run_loop; 256 RunLoop run_loop;
(...skipping 10 matching lines...) Expand all
271 } 267 }
272 268
273 void EnableTracingWithTraceConfig(const std::string& trace_config) { 269 void EnableTracingWithTraceConfig(const std::string& trace_config) {
274 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config), 270 TraceLog::GetInstance()->SetEnabled(TraceConfig(trace_config),
275 TraceLog::RECORDING_MODE); 271 TraceLog::RECORDING_MODE);
276 } 272 }
277 273
278 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } 274 void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); }
279 275
280 bool IsPeriodicDumpingEnabled() const { 276 bool IsPeriodicDumpingEnabled() const {
281 return MemoryDumpScheduler::GetInstance() 277 return MemoryDumpScheduler::GetInstance()->IsEnabledForTesting();
282 ->IsPeriodicTimerRunningForTesting();
283 } 278 }
284 279
285 int GetMaxConsecutiveFailuresCount() const { 280 int GetMaxConsecutiveFailuresCount() const {
286 return MemoryDumpManager::kMaxConsecutiveFailuresCount; 281 return MemoryDumpManager::kMaxConsecutiveFailuresCount;
287 } 282 }
288 283
289 const MemoryDumpProvider::Options kDefaultOptions; 284 const MemoryDumpProvider::Options kDefaultOptions;
290 std::unique_ptr<MemoryDumpManager> mdm_; 285 std::unique_ptr<MemoryDumpManager> mdm_;
291 MemoryDumpManagerDelegateForTesting* delegate_; 286 MemoryDumpManagerDelegateForTesting* delegate_;
292 bool last_callback_success_; 287 bool last_callback_success_;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 EXPECT_CALL(*mdp1, PollFastMemoryTotal(_)) 796 EXPECT_CALL(*mdp1, PollFastMemoryTotal(_))
802 .Times(testing::AtLeast(kPollsToQuit)) 797 .Times(testing::AtLeast(kPollsToQuit))
803 .WillRepeatedly(Invoke(poll_function1)); 798 .WillRepeatedly(Invoke(poll_function1));
804 799
805 // Depending on the order of PostTask calls the mdp2 might be registered after 800 // Depending on the order of PostTask calls the mdp2 might be registered after
806 // all polls or in between polls. 801 // all polls or in between polls.
807 EXPECT_CALL(*mdp2, PollFastMemoryTotal(_)) 802 EXPECT_CALL(*mdp2, PollFastMemoryTotal(_))
808 .Times(Between(0, kPollsToQuit - 1)) 803 .Times(Between(0, kPollsToQuit - 1))
809 .WillRepeatedly(Return()); 804 .WillRepeatedly(Return());
810 805
811 MemoryDumpScheduler::SetPollingIntervalForTesting(1); 806 // TODO here MemoryDumpScheduler::SetPollingIntervalForTesting(1);
812 EnableTracingWithTraceConfig( 807 EnableTracingWithTraceConfig(
813 TraceConfigMemoryTestUtil::GetTraceConfig_PeakDetectionTrigger(3)); 808 TraceConfigMemoryTestUtil::GetTraceConfig_PeakDetectionTrigger(3));
814 809
815 int last_poll_to_request_dump = -2; 810 int last_poll_to_request_dump = -2;
816 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)) 811 EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _))
817 .Times(testing::AtLeast(2)) 812 .Times(testing::AtLeast(2))
818 .WillRepeatedly(Invoke([&last_poll_to_request_dump, &call_count]( 813 .WillRepeatedly(Invoke([&last_poll_to_request_dump, &call_count](
819 const MemoryDumpRequestArgs& args, 814 const MemoryDumpRequestArgs& args,
820 const MemoryDumpCallback& callback) -> void { 815 const MemoryDumpCallback& callback) -> void {
821 // Minimum number of polls between dumps must be 3 (polling interval is 816 // Minimum number of polls between dumps must be 3 (polling interval is
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 thread.Start(); 1297 thread.Start();
1303 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions, 1298 RegisterDumpProvider(&mdp1, thread.task_runner(), kDefaultOptions,
1304 "BlacklistTestDumpProvider"); 1299 "BlacklistTestDumpProvider");
1305 // Unregistering on wrong thread should not crash. 1300 // Unregistering on wrong thread should not crash.
1306 mdm_->UnregisterDumpProvider(&mdp1); 1301 mdm_->UnregisterDumpProvider(&mdp1);
1307 thread.Stop(); 1302 thread.Stop();
1308 } 1303 }
1309 1304
1310 } // namespace trace_event 1305 } // namespace trace_event
1311 } // namespace base 1306 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698