OLD | NEW |
---|---|
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 MOCK_METHOD0(SuspendFastMemoryPolling, void()); | 156 MOCK_METHOD0(SuspendFastMemoryPolling, void()); |
157 | 157 |
158 MockMemoryDumpProvider() : enable_mock_destructor(false) { | 158 MockMemoryDumpProvider() : enable_mock_destructor(false) { |
159 ON_CALL(*this, OnMemoryDump(_, _)) | 159 ON_CALL(*this, OnMemoryDump(_, _)) |
160 .WillByDefault(Invoke([](const MemoryDumpArgs&, | 160 .WillByDefault(Invoke([](const MemoryDumpArgs&, |
161 ProcessMemoryDump* pmd) -> bool { | 161 ProcessMemoryDump* pmd) -> bool { |
162 // |session_state| should not be null under any circumstances when | 162 // |session_state| should not be null under any circumstances when |
163 // invoking a memory dump. The problem might arise in race conditions | 163 // invoking a memory dump. The problem might arise in race conditions |
164 // like crbug.com/600570 . | 164 // like crbug.com/600570 . |
165 EXPECT_TRUE(pmd->session_state().get() != nullptr); | 165 EXPECT_TRUE(pmd->session_state().get() != nullptr); |
166 pmd->CreateAllocatorDump("example")->AddScalar( | |
Primiano Tucci (use gerrit)
2017/05/05 13:38:25
do you need this or is this the leftover from some
hjd
2017/05/05 14:50:53
Yeah, removed. Thanks!
| |
167 MemoryAllocatorDump::kNameSize, MemoryAllocatorDump::kUnitsBytes, | |
168 1024); | |
166 return true; | 169 return true; |
167 })); | 170 })); |
168 | 171 |
169 ON_CALL(*this, PollFastMemoryTotal(_)) | 172 ON_CALL(*this, PollFastMemoryTotal(_)) |
170 .WillByDefault( | 173 .WillByDefault( |
171 Invoke([](uint64_t* memory_total) -> void { NOTREACHED(); })); | 174 Invoke([](uint64_t* memory_total) -> void { NOTREACHED(); })); |
172 } | 175 } |
173 ~MockMemoryDumpProvider() override { | 176 ~MockMemoryDumpProvider() override { |
174 if (enable_mock_destructor) | 177 if (enable_mock_destructor) |
175 Destructor(); | 178 Destructor(); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 403 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
401 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 404 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
402 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); | 405 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(1); |
403 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); | 406 EXPECT_CALL(mdp, OnMemoryDump(IsLightDump(), _)).WillOnce(Return(true)); |
404 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 407 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
405 MemoryDumpLevelOfDetail::LIGHT); | 408 MemoryDumpLevelOfDetail::LIGHT); |
406 DisableTracing(); | 409 DisableTracing(); |
407 mdm_->UnregisterDumpProvider(&mdp); | 410 mdm_->UnregisterDumpProvider(&mdp); |
408 } | 411 } |
409 | 412 |
410 // Checks that the SharedSessionState object is acqually shared over time. | 413 // Checks that the SharedSessionState object is acqually shared over time. |
Primiano Tucci (use gerrit)
2017/05/05 13:38:25
update the comment and the name of the TEST_F
hjd
2017/05/05 14:50:53
Done.
| |
411 TEST_F(MemoryDumpManagerTest, SharedSessionState) { | 414 TEST_F(MemoryDumpManagerTest, SharedSessionState) { |
412 InitializeMemoryDumpManager(false /* is_coordinator */); | 415 InitializeMemoryDumpManager(false /* is_coordinator */); |
413 MockMemoryDumpProvider mdp1; | 416 MockMemoryDumpProvider mdp1; |
414 MockMemoryDumpProvider mdp2; | 417 MockMemoryDumpProvider mdp2; |
415 RegisterDumpProvider(&mdp1, nullptr); | 418 RegisterDumpProvider(&mdp1, nullptr); |
416 RegisterDumpProvider(&mdp2, nullptr); | 419 RegisterDumpProvider(&mdp2, nullptr); |
417 | 420 |
418 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 421 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
419 const MemoryDumpSessionState* session_state = | 422 const MemoryDumpSessionState* heap_profiler_serialization_state = |
420 mdm_->session_state_for_testing().get(); | 423 mdm_->heap_profiler_serialization_state_for_testing().get(); |
421 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); | 424 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)).Times(2); |
422 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) | 425 EXPECT_CALL(mdp1, OnMemoryDump(_, _)) |
423 .Times(2) | 426 .Times(2) |
424 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, | 427 .WillRepeatedly( |
425 ProcessMemoryDump* pmd) -> bool { | 428 Invoke([heap_profiler_serialization_state]( |
426 EXPECT_EQ(session_state, pmd->session_state().get()); | 429 const MemoryDumpArgs&, ProcessMemoryDump* pmd) -> bool { |
427 return true; | 430 EXPECT_EQ(heap_profiler_serialization_state, |
428 })); | 431 pmd->session_state().get()); |
432 return true; | |
433 })); | |
429 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) | 434 EXPECT_CALL(mdp2, OnMemoryDump(_, _)) |
430 .Times(2) | 435 .Times(2) |
431 .WillRepeatedly(Invoke([session_state](const MemoryDumpArgs&, | 436 .WillRepeatedly( |
432 ProcessMemoryDump* pmd) -> bool { | 437 Invoke([heap_profiler_serialization_state]( |
433 EXPECT_EQ(session_state, pmd->session_state().get()); | 438 const MemoryDumpArgs&, ProcessMemoryDump* pmd) -> bool { |
434 return true; | 439 EXPECT_EQ(heap_profiler_serialization_state, |
435 })); | 440 pmd->session_state().get()); |
441 return true; | |
442 })); | |
436 | 443 |
437 for (int i = 0; i < 2; ++i) { | 444 for (int i = 0; i < 2; ++i) { |
438 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 445 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
439 MemoryDumpLevelOfDetail::DETAILED); | 446 MemoryDumpLevelOfDetail::DETAILED); |
440 } | 447 } |
441 | 448 |
442 DisableTracing(); | 449 DisableTracing(); |
443 } | 450 } |
444 | 451 |
445 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. | 452 // Checks that the (Un)RegisterDumpProvider logic behaves sanely. |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1243 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); | 1250 EnableTracingWithLegacyCategories(MemoryDumpManager::kTraceCategory); |
1244 EXPECT_FALSE(IsPeriodicDumpingEnabled()); | 1251 EXPECT_FALSE(IsPeriodicDumpingEnabled()); |
1245 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1252 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1246 MemoryDumpLevelOfDetail::BACKGROUND); | 1253 MemoryDumpLevelOfDetail::BACKGROUND); |
1247 DisableTracing(); | 1254 DisableTracing(); |
1248 } | 1255 } |
1249 | 1256 |
1250 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { | 1257 TEST_F(MemoryDumpManagerTest, TestBackgroundTracingSetup) { |
1251 InitializeMemoryDumpManager(true /* is_coordinator */); | 1258 InitializeMemoryDumpManager(true /* is_coordinator */); |
1252 | 1259 |
1260 MockMemoryDumpProvider mdp; | |
1261 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | |
hjd
2017/05/05 11:42:27
We now need an mdp to hit the code path where the
Primiano Tucci (use gerrit)
2017/05/05 13:38:25
Acknowledged. Maybe add a comment to explain this
| |
1262 | |
1253 RunLoop run_loop; | 1263 RunLoop run_loop; |
1254 auto test_task_runner = ThreadTaskRunnerHandle::Get(); | 1264 auto test_task_runner = ThreadTaskRunnerHandle::Get(); |
1255 auto quit_closure = run_loop.QuitClosure(); | 1265 auto quit_closure = run_loop.QuitClosure(); |
1256 | 1266 |
1257 testing::InSequence sequence; | 1267 testing::InSequence sequence; |
1258 EXPECT_CALL(global_dump_handler_, | 1268 EXPECT_CALL(global_dump_handler_, |
1259 RequestGlobalMemoryDump(IsBackgroundDump(), _)) | 1269 RequestGlobalMemoryDump(IsBackgroundDump(), _)) |
1260 .Times(5); | 1270 .Times(5); |
1261 EXPECT_CALL(global_dump_handler_, | 1271 EXPECT_CALL(global_dump_handler_, |
1262 RequestGlobalMemoryDump(IsBackgroundDump(), _)) | 1272 RequestGlobalMemoryDump(IsBackgroundDump(), _)) |
1263 .WillOnce(Invoke([test_task_runner, quit_closure]( | 1273 .WillOnce(Invoke([test_task_runner, quit_closure]( |
1264 const MemoryDumpRequestArgs& args, | 1274 const MemoryDumpRequestArgs& args, |
1265 const GlobalMemoryDumpCallback& callback) { | 1275 const GlobalMemoryDumpCallback& callback) { |
1266 test_task_runner->PostTask(FROM_HERE, quit_closure); | 1276 test_task_runner->PostTask(FROM_HERE, quit_closure); |
1267 })); | 1277 })); |
1268 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) | 1278 EXPECT_CALL(global_dump_handler_, RequestGlobalMemoryDump(_, _)) |
1269 .Times(AnyNumber()); | 1279 .Times(AnyNumber()); |
1270 | 1280 |
1271 EnableTracingWithTraceConfig( | 1281 EnableTracingWithTraceConfig( |
1272 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger( | 1282 TraceConfigMemoryTestUtil::GetTraceConfig_BackgroundTrigger( |
1273 1 /* period_ms */)); | 1283 1 /* period_ms */)); |
1274 | 1284 |
1285 run_loop.Run(); | |
hjd
2017/05/05 11:42:27
Previously this was racy, we relied on the 6 backg
Primiano Tucci (use gerrit)
2017/05/05 13:38:25
Well I think that became just racy now. Before we
hjd
2017/05/05 14:50:53
On master if I run the test on its own it hangs fo
| |
1286 | |
1275 // Only background mode dumps should be allowed with the trace config. | 1287 // Only background mode dumps should be allowed with the trace config. |
1276 last_callback_success_ = false; | 1288 last_callback_success_ = false; |
1277 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1289 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1278 MemoryDumpLevelOfDetail::LIGHT); | 1290 MemoryDumpLevelOfDetail::LIGHT); |
1279 EXPECT_FALSE(last_callback_success_); | 1291 EXPECT_FALSE(last_callback_success_); |
1280 last_callback_success_ = false; | 1292 last_callback_success_ = false; |
1281 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, | 1293 RequestGlobalDumpAndWait(MemoryDumpType::EXPLICITLY_TRIGGERED, |
1282 MemoryDumpLevelOfDetail::DETAILED); | 1294 MemoryDumpLevelOfDetail::DETAILED); |
1283 EXPECT_FALSE(last_callback_success_); | 1295 EXPECT_FALSE(last_callback_success_); |
1284 | 1296 |
1285 ASSERT_TRUE(IsPeriodicDumpingEnabled()); | 1297 ASSERT_TRUE(IsPeriodicDumpingEnabled()); |
1286 run_loop.Run(); | |
1287 DisableTracing(); | 1298 DisableTracing(); |
1288 } | 1299 } |
1289 | 1300 |
1290 // Tests that we can manually take a dump without enabling tracing. | 1301 // Tests that we can manually take a dump without enabling tracing. |
1291 TEST_F(MemoryDumpManagerTest, DumpWithTracingDisabled) { | 1302 TEST_F(MemoryDumpManagerTest, DumpWithTracingDisabled) { |
1292 InitializeMemoryDumpManager(false /* is_coordinator */); | 1303 InitializeMemoryDumpManager(false /* is_coordinator */); |
1293 MockMemoryDumpProvider mdp; | 1304 MockMemoryDumpProvider mdp; |
1294 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); | 1305 RegisterDumpProvider(&mdp, ThreadTaskRunnerHandle::Get()); |
1295 | 1306 |
1296 DisableTracing(); | 1307 DisableTracing(); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1392 EXPECT_EQ(3u, result.chrome_dump.v8_total_kb); | 1403 EXPECT_EQ(3u, result.chrome_dump.v8_total_kb); |
1393 // partition_alloc has partition_alloc/allocated_objects/* which is a subset | 1404 // partition_alloc has partition_alloc/allocated_objects/* which is a subset |
1394 // of partition_alloc/partitions/* so we only count the latter. | 1405 // of partition_alloc/partitions/* so we only count the latter. |
1395 EXPECT_EQ(4u, result.chrome_dump.partition_alloc_total_kb); | 1406 EXPECT_EQ(4u, result.chrome_dump.partition_alloc_total_kb); |
1396 // resident_set_kb should read from process_totals. | 1407 // resident_set_kb should read from process_totals. |
1397 EXPECT_EQ(5u, result.os_dump.resident_set_kb); | 1408 EXPECT_EQ(5u, result.os_dump.resident_set_kb); |
1398 }; | 1409 }; |
1399 | 1410 |
1400 } // namespace trace_event | 1411 } // namespace trace_event |
1401 } // namespace base | 1412 } // namespace base |
OLD | NEW |