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/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/trace_event/memory_dump_manager.h" | 12 #include "base/trace_event/memory_dump_manager.h" |
| 13 #include "base/trace_event/memory_dump_provider.h" | 13 #include "base/trace_event/memory_dump_provider.h" |
| 14 #include "base/trace_event/memory_dump_request_args.h" | 14 #include "base/trace_event/memory_dump_request_args.h" |
| 15 #include "base/trace_event/trace_config_memory_test_util.h" | 15 #include "base/trace_event/trace_config_memory_test_util.h" |
| 16 #include "base/trace_event/trace_log.h" | 16 #include "base/trace_event/trace_log.h" |
| 17 #include "content/public/browser/tracing_controller.h" | 17 #include "content/public/browser/tracing_controller.h" |
| 18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 20 #include "content/public/test/content_browser_test.h" | 20 #include "content/public/test/content_browser_test.h" |
| 21 #include "content/public/test/content_browser_test_utils.h" | 21 #include "content/public/test/content_browser_test_utils.h" |
| 22 #include "content/shell/browser/shell.h" | 22 #include "content/shell/browser/shell.h" |
| 23 #include "services/resource_coordinator/memory/coordinator/coordinator_impl.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 { |
| 34 | 35 |
| 35 // A mock dump provider, used to check that dump requests actually end up | 36 // A mock dump provider, used to check that dump requests actually end up |
| 36 // creating memory dumps. | 37 // creating memory dumps. |
| 37 class MockDumpProvider : public base::trace_event::MemoryDumpProvider { | 38 class MockDumpProvider : public base::trace_event::MemoryDumpProvider { |
| 38 public: | 39 public: |
| 39 MOCK_METHOD2(OnMemoryDump, bool(const MemoryDumpArgs& args, | 40 MOCK_METHOD2(OnMemoryDump, bool(const MemoryDumpArgs& args, |
| 40 ProcessMemoryDump* pmd)); | 41 ProcessMemoryDump* pmd)); |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 class MemoryTracingTest : public ContentBrowserTest { | 44 class MemoryTracingTest : public ContentBrowserTest { |
| 44 public: | 45 public: |
| 45 void DoRequestGlobalDump(const MemoryDumpType& dump_type, | 46 void DoRequestGlobalDump(const MemoryDumpType& dump_type, |
| 46 const MemoryDumpLevelOfDetail& level_of_detail, | 47 const MemoryDumpLevelOfDetail& level_of_detail, |
| 47 const base::trace_event::MemoryDumpCallback& cb) { | 48 const base::trace_event::MemoryDumpCallback& cb) { |
| 49 LOG(ERROR) << "MDM::RequestGlobalDump"; | |
|
ssid
2017/02/24 23:19:05
Do we need these logs?
chiniforooshan
2017/02/25 00:04:51
Ooops!
| |
| 48 MemoryDumpManager::GetInstance()->RequestGlobalDump(dump_type, | 50 MemoryDumpManager::GetInstance()->RequestGlobalDump(dump_type, |
| 49 level_of_detail, cb); | 51 level_of_detail, cb); |
| 50 } | 52 } |
| 51 | 53 |
| 52 // Used as callback argument for MemoryDumpManager::RequestGlobalDump(): | 54 // Used as callback argument for MemoryDumpManager::RequestGlobalDump(): |
| 53 void OnGlobalMemoryDumpDone( | 55 void OnGlobalMemoryDumpDone( |
| 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 55 base::Closure closure, | 57 base::Closure closure, |
| 56 uint32_t request_index, | 58 uint32_t request_index, |
| 57 uint64_t dump_guid, | 59 uint64_t dump_guid, |
| 58 bool success) { | 60 bool success) { |
| 61 LOG(ERROR) << "OnGlobalDump: " << request_index; | |
| 59 // Make sure we run the RunLoop closure on the same thread that originated | 62 // Make sure we run the RunLoop closure on the same thread that originated |
| 60 // the run loop (which is the IN_PROC_BROWSER_TEST_F main thread). | 63 // the run loop (which is the IN_PROC_BROWSER_TEST_F main thread). |
| 61 if (!task_runner->RunsTasksOnCurrentThread()) { | 64 if (!task_runner->RunsTasksOnCurrentThread()) { |
| 65 LOG(ERROR) << "OnGlobalDump: " << request_index << " (repost)"; | |
| 62 task_runner->PostTask( | 66 task_runner->PostTask( |
| 63 FROM_HERE, base::Bind(&MemoryTracingTest::OnGlobalMemoryDumpDone, | 67 FROM_HERE, base::Bind(&MemoryTracingTest::OnGlobalMemoryDumpDone, |
| 64 base::Unretained(this), task_runner, closure, | 68 base::Unretained(this), task_runner, closure, |
| 65 request_index, dump_guid, success)); | 69 request_index, dump_guid, success)); |
| 66 return; | 70 return; |
| 67 } | 71 } |
| 68 if (success) | 72 if (success) |
| 69 EXPECT_NE(0u, dump_guid); | 73 EXPECT_NE(0u, dump_guid); |
| 70 OnMemoryDumpDone(request_index, success); | 74 OnMemoryDumpDone(request_index, success); |
| 71 if (!closure.is_null()) | 75 if (!closure.is_null()) { |
| 76 LOG(ERROR) << "OnGlobalDump: " << request_index << " (quit loop)"; | |
| 72 closure.Run(); | 77 closure.Run(); |
| 78 } | |
| 73 } | 79 } |
| 74 | 80 |
| 75 void RequestGlobalDumpWithClosure( | 81 void RequestGlobalDumpWithClosure( |
| 76 bool from_renderer_thread, | 82 bool from_renderer_thread, |
| 77 const MemoryDumpType& dump_type, | 83 const MemoryDumpType& dump_type, |
| 78 const MemoryDumpLevelOfDetail& level_of_detail, | 84 const MemoryDumpLevelOfDetail& level_of_detail, |
| 79 const base::Closure& closure) { | 85 const base::Closure& closure) { |
| 80 uint32_t request_index = next_request_index_++; | 86 uint32_t request_index = next_request_index_++; |
| 81 base::trace_event::MemoryDumpCallback callback = base::Bind( | 87 base::trace_event::MemoryDumpCallback callback = base::Bind( |
| 82 &MemoryTracingTest::OnGlobalMemoryDumpDone, base::Unretained(this), | 88 &MemoryTracingTest::OnGlobalMemoryDumpDone, base::Unretained(this), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 FAIL() << "Tracing seems to be already enabled. " | 121 FAIL() << "Tracing seems to be already enabled. " |
| 116 "Very likely this is because the startup tracing file " | 122 "Very likely this is because the startup tracing file " |
| 117 "has been leaked from a previous test."; | 123 "has been leaked from a previous test."; |
| 118 } | 124 } |
| 119 // Enable tracing without periodic dumps. | 125 // Enable tracing without periodic dumps. |
| 120 base::trace_event::TraceConfig trace_config( | 126 base::trace_event::TraceConfig trace_config( |
| 121 base::trace_event::TraceConfigMemoryTestUtil:: | 127 base::trace_event::TraceConfigMemoryTestUtil:: |
| 122 GetTraceConfig_EmptyTriggers()); | 128 GetTraceConfig_EmptyTriggers()); |
| 123 | 129 |
| 124 base::RunLoop run_loop; | 130 base::RunLoop run_loop; |
| 131 // Start the Coordinator service. | |
| 132 memory_instrumentation::CoordinatorImpl::GetInstance( | |
| 133 base::ThreadTaskRunnerHandle::Get().get()); | |
| 125 bool success = TracingController::GetInstance()->StartTracing( | 134 bool success = TracingController::GetInstance()->StartTracing( |
| 126 trace_config, run_loop.QuitClosure()); | 135 trace_config, run_loop.QuitClosure()); |
| 127 EXPECT_TRUE(success); | 136 EXPECT_TRUE(success); |
| 128 run_loop.Run(); | 137 run_loop.Run(); |
| 129 } | 138 } |
| 130 | 139 |
| 131 void DisableTracing() { | 140 void DisableTracing() { |
| 132 bool success = TracingController::GetInstance()->StopTracing(NULL); | 141 bool success = TracingController::GetInstance()->StopTracing(NULL); |
| 133 EXPECT_TRUE(success); | 142 EXPECT_TRUE(success); |
| 134 base::RunLoop().RunUntilIdle(); | 143 base::RunLoop().RunUntilIdle(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)); | 325 EXPECT_CALL(*this, OnMemoryDumpDone(_, true /* success */)); |
| 317 | 326 |
| 318 EnableMemoryTracing(); | 327 EnableMemoryTracing(); |
| 319 RequestGlobalDumpAndWait(false /* from_renderer_thread */, | 328 RequestGlobalDumpAndWait(false /* from_renderer_thread */, |
| 320 MemoryDumpType::EXPLICITLY_TRIGGERED, | 329 MemoryDumpType::EXPLICITLY_TRIGGERED, |
| 321 MemoryDumpLevelOfDetail::DETAILED); | 330 MemoryDumpLevelOfDetail::DETAILED); |
| 322 DisableTracing(); | 331 DisableTracing(); |
| 323 } | 332 } |
| 324 | 333 |
| 325 } // namespace content | 334 } // namespace content |
| OLD | NEW |