Index: base/trace_event/memory_dump_manager_unittest.cc |
diff --git a/base/trace_event/memory_dump_manager_unittest.cc b/base/trace_event/memory_dump_manager_unittest.cc |
index 48a50616574589a24473715880f3415f60b648f5..0c84afcb321178db75341786fd2bcac0fe8a158a 100644 |
--- a/base/trace_event/memory_dump_manager_unittest.cc |
+++ b/base/trace_event/memory_dump_manager_unittest.cc |
@@ -25,6 +25,7 @@ |
#include "base/threading/thread.h" |
#include "base/threading/thread_task_runner_handle.h" |
#include "base/trace_event/memory_dump_provider.h" |
+#include "base/trace_event/memory_dump_trigger.h" |
#include "base/trace_event/memory_infra_background_whitelist.h" |
#include "base/trace_event/process_memory_dump.h" |
#include "base/trace_event/trace_buffer.h" |
@@ -270,17 +271,11 @@ class MemoryDumpManagerTest : public testing::Test { |
void DisableTracing() { TraceLog::GetInstance()->SetDisabled(); } |
- bool IsPeriodicDumpingEnabled() const { |
- return mdm_->periodic_dump_timer_.IsRunning(); |
- } |
- |
int GetMaxConsecutiveFailuresCount() const { |
return MemoryDumpManager::kMaxConsecutiveFailuresCount; |
} |
- scoped_refptr<SequencedTaskRunner> GetPollingTaskRunnerUnsafe() { |
- return mdm_->dump_thread_->task_runner(); |
- } |
+ MemoryDumpTrigger* GetDumpTrigger() { return mdm_->dump_trigger_.get(); } |
const MemoryDumpProvider::Options kDefaultOptions; |
std::unique_ptr<MemoryDumpManager> mdm_; |
@@ -762,46 +757,57 @@ TEST_F(MemoryDumpManagerTest, TestPollingOnDumpThread) { |
EXPECT_CALL(*mdp1, Destructor()); |
EXPECT_CALL(*mdp2, Destructor()); |
+ MemoryDumpProvider::Options options; |
+ options.is_fast_polling_supported = true; |
+ RegisterDumpProvider(mdp1.get(), nullptr, options); |
+ |
RunLoop run_loop; |
scoped_refptr<SingleThreadTaskRunner> test_task_runner = |
ThreadTaskRunnerHandle::Get(); |
auto quit_closure = run_loop.QuitClosure(); |
+ const int kPollsToQuit = 10; |
int call_count = 0; |
+ MemoryDumpManager* mdm = mdm_.get(); |
+ const auto poll_function1 = [&call_count, &test_task_runner, quit_closure, |
+ &mdp2, mdm, &options, |
+ this](uint64_t* total) -> void { |
+ ++call_count; |
+ if (call_count == 1) |
+ RegisterDumpProvider(mdp2.get(), nullptr, options, kMDPName); |
+ else if (call_count == 4) |
+ mdm->UnregisterAndDeleteDumpProviderSoon(std::move(mdp2)); |
+ else if (call_count == kPollsToQuit) |
+ test_task_runner->PostTask(FROM_HERE, quit_closure); |
+ |
+ // Record increase of 10s of GiB of memory. |
+ *total = call_count * 10lu * 1024 * 1024 * 1024; |
+ }; |
EXPECT_CALL(*mdp1, PollFastMemoryTotal(_)) |
- .Times(4) |
- .WillRepeatedly(Invoke([&call_count, &test_task_runner, |
- quit_closure](uint64_t* total) -> void { |
- ++call_count; |
- if (call_count == 4) |
- test_task_runner->PostTask(FROM_HERE, quit_closure); |
- })); |
+ .Times(testing::AtLeast(kPollsToQuit)) |
+ .WillRepeatedly(Invoke(poll_function1)); |
// Depending on the order of PostTask calls the mdp2 might be registered after |
// all polls or in between polls. |
EXPECT_CALL(*mdp2, PollFastMemoryTotal(_)) |
- .Times(Between(0, 4)) |
+ .Times(Between(0, kPollsToQuit - 1)) |
.WillRepeatedly(Return()); |
- MemoryDumpProvider::Options options; |
- options.is_fast_polling_supported = true; |
- RegisterDumpProvider(mdp1.get(), nullptr, options); |
+ MemoryDumpTrigger::SetPollingIntervalForTesting(1); |
EnableTracingWithTraceConfig( |
- TraceConfigMemoryTestUtil::GetTraceConfig_PeakDetectionTrigger(1)); |
- scoped_refptr<SequencedTaskRunner> polling_task_runner = |
- GetPollingTaskRunnerUnsafe().get(); |
- ASSERT_TRUE(polling_task_runner); |
+ TraceConfigMemoryTestUtil::GetTraceConfig_PeakDetectionTrigger(3)); |
- uint64_t value = 0; |
- for (int i = 0; i < 4; i++) { |
- if (i == 0) |
- RegisterDumpProvider(mdp2.get(), nullptr, options); |
- if (i == 2) |
- mdm_->UnregisterAndDeleteDumpProviderSoon(std::move(mdp2)); |
- polling_task_runner->PostTask( |
- FROM_HERE, Bind(&MemoryDumpManagerTest::PollFastMemoryTotal, |
- Unretained(this), &value)); |
- } |
+ int last_poll_to_request_dump = -2; |
+ EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)) |
+ .Times(testing::AtLeast(2)) |
+ .WillRepeatedly(Invoke([&last_poll_to_request_dump, &call_count]( |
+ const MemoryDumpRequestArgs& args, |
+ const MemoryDumpCallback& callback) -> void { |
+ // Minimum number of polls between dumps must be 3 (polling interval is |
+ // 1ms). |
+ EXPECT_GE(call_count - last_poll_to_request_dump, 3); |
+ last_poll_to_request_dump = call_count; |
+ })); |
run_loop.Run(); |
DisableTracing(); |
@@ -924,7 +930,7 @@ TEST_F(MemoryDumpManagerTest, TraceConfigExpectations) { |
// Enabling memory-infra in a non-coordinator process should not trigger any |
// periodic dumps. |
EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
- EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
+ EXPECT_FALSE(GetDumpTrigger()->IsPeriodicDumpTimerRunning()); |
DisableTracing(); |
// Enabling memory-infra with the new (JSON) TraceConfig in a non-coordinator |
@@ -932,7 +938,7 @@ TEST_F(MemoryDumpManagerTest, TraceConfigExpectations) { |
// dumps. |
EnableTracingWithTraceConfig( |
TraceConfigMemoryTestUtil::GetTraceConfig_PeriodicTriggers(1, 5)); |
- EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
+ EXPECT_FALSE(GetDumpTrigger()->IsPeriodicDumpTimerRunning()); |
DisableTracing(); |
} |
@@ -944,7 +950,7 @@ TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) { |
// Enabling memory-infra with the legacy TraceConfig (category filter) in |
// a coordinator process should enable periodic dumps. |
EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
- EXPECT_TRUE(IsPeriodicDumpingEnabled()); |
+ EXPECT_TRUE(GetDumpTrigger()->IsPeriodicDumpTimerRunning()); |
DisableTracing(); |
// Enabling memory-infra with the new (JSON) TraceConfig in a coordinator |
@@ -953,7 +959,7 @@ TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) { |
// is: ticking memory-infra should dump periodically with the default config. |
EnableTracingWithTraceConfig( |
TraceConfigMemoryTestUtil::GetTraceConfig_NoTriggers()); |
- EXPECT_TRUE(IsPeriodicDumpingEnabled()); |
+ EXPECT_TRUE(GetDumpTrigger()->IsPeriodicDumpTimerRunning()); |
DisableTracing(); |
// Enabling memory-infra with the new (JSON) TraceConfig in a coordinator |
@@ -962,7 +968,7 @@ TEST_F(MemoryDumpManagerTest, TraceConfigExpectationsWhenIsCoordinator) { |
// only explicitly triggered dumps. |
EnableTracingWithTraceConfig( |
TraceConfigMemoryTestUtil::GetTraceConfig_EmptyTriggers()); |
- EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
+ EXPECT_FALSE(GetDumpTrigger()->IsPeriodicDumpTimerRunning()); |
DisableTracing(); |
// Enabling memory-infra with the new (JSON) TraceConfig in a coordinator |
@@ -1223,7 +1229,7 @@ TEST_F(MemoryDumpManagerTest, TestWhitelistingMDP) { |
EXPECT_CALL(*delegate_, RequestGlobalMemoryDump(_, _)).Times(1); |
EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
- EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
+ EXPECT_FALSE(GetDumpTrigger()->IsPeriodicDumpTimerRunning()); |
RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
MemoryDumpLevelOfDetail::BACKGROUND); |
DisableTracing(); |
@@ -1259,7 +1265,7 @@ TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { |
MemoryDumpLevelOfDetail::DETAILED); |
EXPECT_FALSE(last_callback_success_); |
- ASSERT_TRUE(IsPeriodicDumpingEnabled()); |
+ ASSERT_TRUE(GetDumpTrigger()->IsPeriodicDumpTimerRunning()); |
run_loop.Run(); |
DisableTracing(); |
} |