OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 <inttypes.h> | 5 #include <inttypes.h> |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/test/trace_event_analyzer.h" | 19 #include "base/test/trace_event_analyzer.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/trace_event/memory_dump_manager.h" | 21 #include "base/trace_event/memory_dump_manager.h" |
| 22 #include "base/trace_event/memory_dump_manager_test_utils.h" |
22 #include "base/trace_event/memory_dump_request_args.h" | 23 #include "base/trace_event/memory_dump_request_args.h" |
23 #include "base/trace_event/process_memory_dump.h" | 24 #include "base/trace_event/process_memory_dump.h" |
24 #include "base/trace_event/trace_buffer.h" | 25 #include "base/trace_event/trace_buffer.h" |
25 #include "base/trace_event/trace_config.h" | 26 #include "base/trace_event/trace_config.h" |
26 #include "base/trace_event/trace_config_memory_test_util.h" | 27 #include "base/trace_event/trace_config_memory_test_util.h" |
27 #include "base/trace_event/trace_log.h" | 28 #include "base/trace_event/trace_log.h" |
28 #include "net/base/load_timing_info.h" | 29 #include "net/base/load_timing_info.h" |
29 #include "net/cert/mock_cert_verifier.h" | 30 #include "net/cert/mock_cert_verifier.h" |
30 #include "net/dns/mapped_host_resolver.h" | 31 #include "net/dns/mapped_host_resolver.h" |
31 #include "net/dns/mock_host_resolver.h" | 32 #include "net/dns/mock_host_resolver.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void PrintPerfTest(const std::string& name, | 81 void PrintPerfTest(const std::string& name, |
81 int value, | 82 int value, |
82 const std::string& unit) { | 83 const std::string& unit) { |
83 const ::testing::TestInfo* test_info = | 84 const ::testing::TestInfo* test_info = |
84 ::testing::UnitTest::GetInstance()->current_test_info(); | 85 ::testing::UnitTest::GetInstance()->current_test_info(); |
85 perf_test::PrintResult(test_info->test_case_name(), | 86 perf_test::PrintResult(test_info->test_case_name(), |
86 std::string(".") + test_info->name(), name, | 87 std::string(".") + test_info->name(), name, |
87 static_cast<double>(value), unit, true); | 88 static_cast<double>(value), unit, true); |
88 } | 89 } |
89 | 90 |
90 void RequestGlobalDumpCallback(base::Closure quit_closure, | |
91 uint64_t, | |
92 bool success) { | |
93 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure); | |
94 ASSERT_TRUE(success); | |
95 } | |
96 | |
97 void ProcessDumpCallbackAdapter( | |
98 base::trace_event::GlobalMemoryDumpCallback callback, | |
99 uint64_t dump_guid, | |
100 bool success, | |
101 const base::Optional<base::trace_event::MemoryDumpCallbackResult>&) { | |
102 callback.Run(dump_guid, success); | |
103 } | |
104 | |
105 void RequestGlobalMemoryDumpCallback( | |
106 const base::trace_event::MemoryDumpRequestArgs& args, | |
107 const base::trace_event::GlobalMemoryDumpCallback& callback) { | |
108 base::trace_event::ProcessMemoryDumpCallback process_callback = | |
109 base::Bind(&ProcessDumpCallbackAdapter, callback); | |
110 base::trace_event::MemoryDumpManager::GetInstance()->CreateProcessDump( | |
111 args, process_callback); | |
112 } | |
113 | |
114 class URLRequestQuicPerfTest : public ::testing::Test { | 91 class URLRequestQuicPerfTest : public ::testing::Test { |
115 protected: | 92 protected: |
116 URLRequestQuicPerfTest() : message_loop_(new base::MessageLoopForIO()) { | 93 URLRequestQuicPerfTest() : message_loop_(new base::MessageLoopForIO()) { |
117 memory_dump_manager_ = | 94 memory_dump_manager_ = |
118 base::trace_event::MemoryDumpManager::CreateInstanceForTesting(); | 95 base::trace_event::MemoryDumpManager::CreateInstanceForTesting(); |
119 memory_dump_manager_->Initialize( | 96 base::trace_event::InitializeMemoryDumpManagerForInProcessTesting( |
120 base::BindRepeating(&RequestGlobalMemoryDumpCallback), | |
121 /*is_coordinator_process=*/false); | 97 /*is_coordinator_process=*/false); |
122 memory_dump_manager_->set_dumper_registrations_ignored_for_testing(false); | 98 memory_dump_manager_->set_dumper_registrations_ignored_for_testing(false); |
123 context_ = base::MakeUnique<TestURLRequestContext>(true); | 99 context_ = base::MakeUnique<TestURLRequestContext>(true); |
124 memory_dump_manager_->set_dumper_registrations_ignored_for_testing(true); | 100 memory_dump_manager_->set_dumper_registrations_ignored_for_testing(true); |
125 StartTcpServer(); | 101 StartTcpServer(); |
126 StartQuicServer(); | 102 StartQuicServer(); |
127 | 103 |
128 // Host mapping. | 104 // Host mapping. |
129 std::unique_ptr<MockHostResolver> resolver(new MockHostResolver()); | 105 std::unique_ptr<MockHostResolver> resolver(new MockHostResolver()); |
130 resolver->rules()->AddRule(kAltSvcHost, "127.0.0.1"); | 106 resolver->rules()->AddRule(kAltSvcHost, "127.0.0.1"); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 base::TimeTicks end = base::TimeTicks::Now(); | 238 base::TimeTicks end = base::TimeTicks::Now(); |
263 PrintPerfTest("time", (end - start).InMilliseconds() / kNumRequest, "ms"); | 239 PrintPerfTest("time", (end - start).InMilliseconds() / kNumRequest, "ms"); |
264 | 240 |
265 EXPECT_TRUE(quic_succeeded); | 241 EXPECT_TRUE(quic_succeeded); |
266 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 242 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
267 base::trace_event::TraceConfig( | 243 base::trace_event::TraceConfig( |
268 base::trace_event::MemoryDumpManager::kTraceCategory, ""), | 244 base::trace_event::MemoryDumpManager::kTraceCategory, ""), |
269 base::trace_event::TraceLog::RECORDING_MODE); | 245 base::trace_event::TraceLog::RECORDING_MODE); |
270 | 246 |
271 base::RunLoop run_loop; | 247 base::RunLoop run_loop; |
272 base::trace_event::MemoryDumpManager::GetInstance()->RequestGlobalDump( | 248 base::trace_event::MemoryDumpRequestArgs args{ |
273 base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED, | 249 1 /* dump_guid*/, base::trace_event::MemoryDumpType::EXPLICITLY_TRIGGERED, |
274 base::trace_event::MemoryDumpLevelOfDetail::LIGHT, | 250 base::trace_event::MemoryDumpLevelOfDetail::LIGHT}; |
275 base::Bind(&RequestGlobalDumpCallback, run_loop.QuitClosure())); | 251 auto on_memory_dump_done = |
276 | 252 [](base::Closure quit_closure, uint64_t dump_guid, bool success, |
| 253 const base::Optional<base::trace_event::MemoryDumpCallbackResult>&) { |
| 254 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure); |
| 255 ASSERT_TRUE(success); |
| 256 }; |
| 257 base::trace_event::MemoryDumpManager::GetInstance()->CreateProcessDump( |
| 258 args, base::Bind(on_memory_dump_done, run_loop.QuitClosure())); |
277 run_loop.Run(); | 259 run_loop.Run(); |
278 base::trace_event::TraceLog::GetInstance()->SetDisabled(); | 260 base::trace_event::TraceLog::GetInstance()->SetDisabled(); |
279 std::unique_ptr<trace_analyzer::TraceAnalyzer> analyzer = | 261 std::unique_ptr<trace_analyzer::TraceAnalyzer> analyzer = |
280 GetDeserializedTrace(); | 262 GetDeserializedTrace(); |
281 | 263 |
282 trace_analyzer::TraceEventVector events; | 264 trace_analyzer::TraceEventVector events; |
283 analyzer->FindEvents( | 265 analyzer->FindEvents( |
284 trace_analyzer::Query::EventPhaseIs(TRACE_EVENT_PHASE_MEMORY_DUMP), | 266 trace_analyzer::Query::EventPhaseIs(TRACE_EVENT_PHASE_MEMORY_DUMP), |
285 &events); | 267 &events); |
286 EXPECT_EQ( | 268 EXPECT_EQ( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 base::DictionaryValue* http_stream_factory_dump; | 318 base::DictionaryValue* http_stream_factory_dump; |
337 ASSERT_FALSE(allocator_dumps->GetDictionary( | 319 ASSERT_FALSE(allocator_dumps->GetDictionary( |
338 base::StringPrintf( | 320 base::StringPrintf( |
339 "net/http_network_session_0x%" PRIxPTR "/stream_factory", | 321 "net/http_network_session_0x%" PRIxPTR "/stream_factory", |
340 reinterpret_cast<uintptr_t>( | 322 reinterpret_cast<uintptr_t>( |
341 context()->http_transaction_factory()->GetSession())), | 323 context()->http_transaction_factory()->GetSession())), |
342 &http_stream_factory_dump)); | 324 &http_stream_factory_dump)); |
343 } | 325 } |
344 | 326 |
345 } // namespace net | 327 } // namespace net |
OLD | NEW |