Chromium Code Reviews| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/synchronization/waitable_event.h" | |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/trace_event/memory_dump_manager.h" | 13 #include "base/trace_event/memory_dump_manager.h" |
| 13 #include "base/trace_event/memory_dump_provider.h" | 14 #include "base/trace_event/memory_dump_provider.h" |
| 14 #include "base/trace_event/memory_dump_request_args.h" | 15 #include "base/trace_event/memory_dump_request_args.h" |
| 15 #include "base/trace_event/trace_config_memory_test_util.h" | 16 #include "base/trace_event/trace_config_memory_test_util.h" |
| 16 #include "base/trace_event/trace_log.h" | 17 #include "base/trace_event/trace_log.h" |
| 17 #include "content/public/browser/tracing_controller.h" | 18 #include "content/public/browser/tracing_controller.h" |
| 18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 20 #include "content/public/test/content_browser_test.h" | 21 #include "content/public/test/content_browser_test.h" |
| 21 #include "content/public/test/content_browser_test_utils.h" | 22 #include "content/public/test/content_browser_test_utils.h" |
| 22 #include "content/shell/browser/shell.h" | 23 #include "content/shell/browser/shell.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 24 | 25 |
| 25 using base::trace_event::MemoryDumpArgs; | 26 using base::trace_event::MemoryDumpArgs; |
| 26 using base::trace_event::MemoryDumpLevelOfDetail; | 27 using base::trace_event::MemoryDumpLevelOfDetail; |
| 27 using base::trace_event::MemoryDumpManager; | 28 using base::trace_event::MemoryDumpManager; |
| 28 using base::trace_event::MemoryDumpType; | 29 using base::trace_event::MemoryDumpType; |
| 29 using base::trace_event::ProcessMemoryDump; | 30 using base::trace_event::ProcessMemoryDump; |
| 30 using testing::_; | 31 using testing::_; |
| 31 using testing::Return; | 32 using testing::Return; |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 35 namespace { | |
| 36 | |
| 37 void OnStartTracingDoneCallback(base::Closure quit_loop, | |
| 38 base::WaitableEvent* evt) { | |
| 39 quit_loop.Run(); | |
| 40 if (evt) | |
|
chiniforooshan
2017/04/12 19:32:57
I know that BrowserInitiatedDump is flaky because
ssid
2017/04/12 20:03:18
Yes, you are right! I just realized both the tests
| |
| 41 evt->Signal(); | |
| 42 } | |
| 43 } | |
| 34 | 44 |
| 35 // A mock dump provider, used to check that dump requests actually end up | 45 // A mock dump provider, used to check that dump requests actually end up |
| 36 // creating memory dumps. | 46 // creating memory dumps. |
| 37 class MockDumpProvider : public base::trace_event::MemoryDumpProvider { | 47 class MockDumpProvider : public base::trace_event::MemoryDumpProvider { |
| 38 public: | 48 public: |
| 39 MOCK_METHOD2(OnMemoryDump, bool(const MemoryDumpArgs& args, | 49 MOCK_METHOD2(OnMemoryDump, bool(const MemoryDumpArgs& args, |
| 40 ProcessMemoryDump* pmd)); | 50 ProcessMemoryDump* pmd)); |
| 41 }; | 51 }; |
| 42 | 52 |
| 43 class MemoryTracingTest : public ContentBrowserTest { | 53 class MemoryTracingTest : public ContentBrowserTest { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 ContentBrowserTest::SetUp(); | 113 ContentBrowserTest::SetUp(); |
| 104 } | 114 } |
| 105 | 115 |
| 106 void TearDown() override { | 116 void TearDown() override { |
| 107 MemoryDumpManager::GetInstance()->UnregisterAndDeleteDumpProviderSoon( | 117 MemoryDumpManager::GetInstance()->UnregisterAndDeleteDumpProviderSoon( |
| 108 std::move(mock_dump_provider_)); | 118 std::move(mock_dump_provider_)); |
| 109 mock_dump_provider_.reset(); | 119 mock_dump_provider_.reset(); |
| 110 ContentBrowserTest::TearDown(); | 120 ContentBrowserTest::TearDown(); |
| 111 } | 121 } |
| 112 | 122 |
| 113 void EnableMemoryTracing() { | 123 void EnableMemoryTracing(base::WaitableEvent* start_tracing_done_signal) { |
| 114 // Re-enabling tracing could crash these tests https://crbug.com/657628 . | 124 // Re-enabling tracing could crash these tests https://crbug.com/657628 . |
| 115 if (base::trace_event::TraceLog::GetInstance()->IsEnabled()) { | 125 if (base::trace_event::TraceLog::GetInstance()->IsEnabled()) { |
| 116 FAIL() << "Tracing seems to be already enabled. " | 126 FAIL() << "Tracing seems to be already enabled. " |
| 117 "Very likely this is because the startup tracing file " | 127 "Very likely this is because the startup tracing file " |
| 118 "has been leaked from a previous test."; | 128 "has been leaked from a previous test."; |
| 119 } | 129 } |
| 120 // Enable tracing without periodic dumps. | 130 // Enable tracing without periodic dumps. |
| 121 base::trace_event::TraceConfig trace_config( | 131 base::trace_event::TraceConfig trace_config( |
| 122 base::trace_event::TraceConfigMemoryTestUtil:: | 132 base::trace_event::TraceConfigMemoryTestUtil:: |
| 123 GetTraceConfig_EmptyTriggers()); | 133 GetTraceConfig_EmptyTriggers()); |
| 124 | 134 |
| 125 base::RunLoop run_loop; | 135 base::RunLoop run_loop; |
| 126 bool success = TracingController::GetInstance()->StartTracing( | 136 bool success = TracingController::GetInstance()->StartTracing( |
| 127 trace_config, run_loop.QuitClosure()); | 137 trace_config, |
| 138 base::Bind(&OnStartTracingDoneCallback, run_loop.QuitClosure(), | |
| 139 start_tracing_done_signal)); | |
| 128 EXPECT_TRUE(success); | 140 EXPECT_TRUE(success); |
| 129 run_loop.Run(); | 141 run_loop.Run(); |
| 130 } | 142 } |
| 131 | 143 |
| 132 void DisableTracing() { | 144 void DisableTracing() { |
| 133 bool success = TracingController::GetInstance()->StopTracing(NULL); | 145 bool success = TracingController::GetInstance()->StopTracing(NULL); |
| 134 EXPECT_TRUE(success); | 146 EXPECT_TRUE(success); |
| 135 base::RunLoop().RunUntilIdle(); | 147 base::RunLoop().RunUntilIdle(); |
| 136 } | 148 } |
| 137 | 149 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 | 191 |
| 180 // Checks that a memory dump initiated from a the main browser thread ends up in | 192 // Checks that a memory dump initiated from a the main browser thread ends up in |
| 181 // a single dump even in single process mode. | 193 // a single dump even in single process mode. |
| 182 IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, | 194 IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, |
| 183 BrowserInitiatedSingleDump) { | 195 BrowserInitiatedSingleDump) { |
| 184 Navigate(shell()); | 196 Navigate(shell()); |
| 185 | 197 |
| 186 EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)).WillOnce(Return(true)); | 198 EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)).WillOnce(Return(true)); |
| 187 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)); | 199 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)); |
| 188 | 200 |
| 189 EnableMemoryTracing(); | 201 EnableMemoryTracing(nullptr /* start_tracing_done_signal */); |
| 190 RequestGlobalDumpAndWait(false /* from_renderer_thread */, | 202 RequestGlobalDumpAndWait(false /* from_renderer_thread */, |
| 191 MemoryDumpType::EXPLICITLY_TRIGGERED, | 203 MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 192 MemoryDumpLevelOfDetail::DETAILED); | 204 MemoryDumpLevelOfDetail::DETAILED); |
| 193 DisableTracing(); | 205 DisableTracing(); |
| 194 } | 206 } |
| 195 | 207 |
| 196 // Checks that a memory dump initiated from a renderer thread ends up in a | 208 // Checks that a memory dump initiated from a renderer thread ends up in a |
| 197 // single dump even in single process mode. | 209 // single dump even in single process mode. |
| 198 IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, | 210 IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, |
| 199 RendererInitiatedSingleDump) { | 211 RendererInitiatedSingleDump) { |
| 200 Navigate(shell()); | 212 Navigate(shell()); |
| 201 | 213 |
| 202 EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)).WillOnce(Return(true)); | 214 EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)).WillOnce(Return(true)); |
| 203 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)); | 215 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)); |
| 204 | 216 |
| 205 EnableMemoryTracing(); | 217 EnableMemoryTracing(nullptr /* start_tracing_done_signal */); |
| 206 RequestGlobalDumpAndWait(true /* from_renderer_thread */, | 218 RequestGlobalDumpAndWait(true /* from_renderer_thread */, |
| 207 MemoryDumpType::EXPLICITLY_TRIGGERED, | 219 MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 208 MemoryDumpLevelOfDetail::DETAILED); | 220 MemoryDumpLevelOfDetail::DETAILED); |
| 209 DisableTracing(); | 221 DisableTracing(); |
| 210 } | 222 } |
| 211 | 223 |
| 212 IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, ManyInterleavedDumps) { | 224 IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, ManyInterleavedDumps) { |
| 213 Navigate(shell()); | 225 Navigate(shell()); |
| 214 | 226 |
| 215 EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)) | 227 EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)) |
| 216 .Times(4) | 228 .Times(4) |
| 217 .WillRepeatedly(Return(true)); | 229 .WillRepeatedly(Return(true)); |
| 218 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)).Times(4); | 230 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)).Times(4); |
| 219 | 231 |
| 220 EnableMemoryTracing(); | 232 EnableMemoryTracing(nullptr /* start_tracing_done_signal */); |
| 221 RequestGlobalDumpAndWait(true /* from_renderer_thread */, | 233 RequestGlobalDumpAndWait(true /* from_renderer_thread */, |
| 222 MemoryDumpType::EXPLICITLY_TRIGGERED, | 234 MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 223 MemoryDumpLevelOfDetail::DETAILED); | 235 MemoryDumpLevelOfDetail::DETAILED); |
| 224 RequestGlobalDumpAndWait(false /* from_renderer_thread */, | 236 RequestGlobalDumpAndWait(false /* from_renderer_thread */, |
| 225 MemoryDumpType::EXPLICITLY_TRIGGERED, | 237 MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 226 MemoryDumpLevelOfDetail::DETAILED); | 238 MemoryDumpLevelOfDetail::DETAILED); |
| 227 RequestGlobalDumpAndWait(false /* from_renderer_thread */, | 239 RequestGlobalDumpAndWait(false /* from_renderer_thread */, |
| 228 MemoryDumpType::EXPLICITLY_TRIGGERED, | 240 MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 229 MemoryDumpLevelOfDetail::DETAILED); | 241 MemoryDumpLevelOfDetail::DETAILED); |
| 230 RequestGlobalDumpAndWait(true /* from_renderer_thread */, | 242 RequestGlobalDumpAndWait(true /* from_renderer_thread */, |
| 231 MemoryDumpType::EXPLICITLY_TRIGGERED, | 243 MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 232 MemoryDumpLevelOfDetail::DETAILED); | 244 MemoryDumpLevelOfDetail::DETAILED); |
| 233 DisableTracing(); | 245 DisableTracing(); |
| 234 } | 246 } |
| 235 | 247 |
| 236 // Checks that, if there already is a memory dump in progress, subsequent memory | 248 // Checks that, if there already is a memory dump in progress, subsequent memory |
| 237 // dump requests are queued and carried out after it's finished. Also checks | 249 // dump requests are queued and carried out after it's finished. Also checks |
| 238 // that periodic dump requests fail in case there is already a request in the | 250 // that periodic dump requests fail in case there is already a request in the |
| 239 // queue with the same level of detail. | 251 // queue with the same level of detail. |
| 240 IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, QueuedDumps) { | 252 IN_PROC_BROWSER_TEST_F(SingleProcessMemoryTracingTest, QueuedDumps) { |
| 241 Navigate(shell()); | 253 Navigate(shell()); |
| 242 | 254 |
| 243 EnableMemoryTracing(); | 255 EnableMemoryTracing(nullptr /* start_tracing_done_signal */); |
| 244 | 256 |
| 245 // Issue the following 6 global memory dump requests: | 257 // Issue the following 6 global memory dump requests: |
| 246 // | 258 // |
| 247 // 0 (ED) req-------------------------------------->ok | 259 // 0 (ED) req-------------------------------------->ok |
| 248 // 1 (PD) req->fail(0) | 260 // 1 (PD) req->fail(0) |
| 249 // 2 (PL) req------------------------>ok | 261 // 2 (PL) req------------------------>ok |
| 250 // 3 (PL) req->fail(2) | 262 // 3 (PL) req->fail(2) |
| 251 // 4 (EL) req---------->ok | 263 // 4 (EL) req---------->ok |
| 252 // 5 (ED) req--------->ok | 264 // 5 (ED) req--------->ok |
| 253 // 6 (PL) req->ok | 265 // 6 (PL) req->ok |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 EXPECT_CALL(*this, OnMemoryDumpDone(6, true /* success */)); | 307 EXPECT_CALL(*this, OnMemoryDumpDone(6, true /* success */)); |
| 296 RequestGlobalDumpAndWait(true /* from_renderer_thread */, | 308 RequestGlobalDumpAndWait(true /* from_renderer_thread */, |
| 297 MemoryDumpType::PERIODIC_INTERVAL, | 309 MemoryDumpType::PERIODIC_INTERVAL, |
| 298 MemoryDumpLevelOfDetail::LIGHT); | 310 MemoryDumpLevelOfDetail::LIGHT); |
| 299 | 311 |
| 300 DisableTracing(); | 312 DisableTracing(); |
| 301 } | 313 } |
| 302 | 314 |
| 303 #endif // !defined(GOOGLE_CHROME_BUILD) | 315 #endif // !defined(GOOGLE_CHROME_BUILD) |
| 304 | 316 |
| 305 // Non-deterministic races under TSan. crbug.com/529678 | |
| 306 // Flaky on Linux. crbug.com/709524 | |
| 307 #if defined(THREAD_SANITIZER) || defined(OS_LINUX) | |
| 308 #define MAYBE_BrowserInitiatedDump DISABLED_BrowserInitiatedDump | |
| 309 #else | |
| 310 #define MAYBE_BrowserInitiatedDump BrowserInitiatedDump | |
| 311 #endif | |
| 312 // Checks that a memory dump initiated from a the main browser thread ends up in | 317 // Checks that a memory dump initiated from a the main browser thread ends up in |
| 313 // a successful dump. | 318 // a successful dump. |
| 314 IN_PROC_BROWSER_TEST_F(MemoryTracingTest, MAYBE_BrowserInitiatedDump) { | 319 IN_PROC_BROWSER_TEST_F(MemoryTracingTest, BrowserInitiatedDump) { |
| 315 Navigate(shell()); | 320 Navigate(shell()); |
| 316 | 321 |
| 317 EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)).WillOnce(Return(true)); | 322 EXPECT_CALL(*mock_dump_provider_, OnMemoryDump(_,_)).WillOnce(Return(true)); |
| 318 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)); | 323 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)); |
| 319 | 324 |
| 320 EnableMemoryTracing(); | 325 base::WaitableEvent start_tracing_done( |
| 326 base::WaitableEvent::ResetPolicy::MANUAL, | |
| 327 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
| 328 EnableMemoryTracing(&start_tracing_done); | |
| 329 | |
| 330 // Wait till child processes gets tracing enabled signal. | |
| 331 start_tracing_done.Wait(); | |
| 321 RequestGlobalDumpAndWait(false /* from_renderer_thread */, | 332 RequestGlobalDumpAndWait(false /* from_renderer_thread */, |
| 322 MemoryDumpType::EXPLICITLY_TRIGGERED, | 333 MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 323 MemoryDumpLevelOfDetail::DETAILED); | 334 MemoryDumpLevelOfDetail::DETAILED); |
| 324 DisableTracing(); | 335 DisableTracing(); |
| 325 } | 336 } |
| 326 | 337 |
| 327 } // namespace content | 338 } // namespace content |
| OLD | NEW |