| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_perftest_support.h" | 5 #include "ipc/ipc_perftest_support.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/test/test_io_thread.h" | 21 #include "base/test/test_io_thread.h" |
| 22 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "ipc/ipc_channel.h" | 26 #include "ipc/ipc_channel.h" |
| 27 #include "ipc/ipc_channel_proxy.h" | 27 #include "ipc/ipc_channel_proxy.h" |
| 28 #include "ipc/ipc_descriptors.h" | 28 #include "ipc/ipc_descriptors.h" |
| 29 #include "ipc/ipc_message_utils.h" | 29 #include "ipc/ipc_message_utils.h" |
| 30 #include "ipc/ipc_sender.h" | 30 #include "ipc/ipc_sender.h" |
| 31 #include "mojo/edk/test/scoped_ipc_support.h" |
| 31 | 32 |
| 32 namespace IPC { | 33 namespace IPC { |
| 33 namespace test { | 34 namespace test { |
| 34 | 35 |
| 35 // Avoid core 0 due to conflicts with Intel's Power Gadget. | 36 // Avoid core 0 due to conflicts with Intel's Power Gadget. |
| 36 // Setting thread affinity will fail harmlessly on single/dual core machines. | 37 // Setting thread affinity will fail harmlessly on single/dual core machines. |
| 37 const int kSharedCore = 2; | 38 const int kSharedCore = 2; |
| 38 | 39 |
| 39 // This class simply collects stats about abstract "events" (each of which has a | 40 // This class simply collects stats about abstract "events" (each of which has a |
| 40 // start time and an end time). | 41 // start time and an end time). |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 list.push_back(PingPongTestParams(12, 50000)); | 242 list.push_back(PingPongTestParams(12, 50000)); |
| 242 list.push_back(PingPongTestParams(144, 50000)); | 243 list.push_back(PingPongTestParams(144, 50000)); |
| 243 list.push_back(PingPongTestParams(1728, 50000)); | 244 list.push_back(PingPongTestParams(1728, 50000)); |
| 244 list.push_back(PingPongTestParams(20736, 12000)); | 245 list.push_back(PingPongTestParams(20736, 12000)); |
| 245 list.push_back(PingPongTestParams(248832, 1000)); | 246 list.push_back(PingPongTestParams(248832, 1000)); |
| 246 return list; | 247 return list; |
| 247 } | 248 } |
| 248 | 249 |
| 249 void IPCChannelPerfTestBase::RunTestChannelPingPong( | 250 void IPCChannelPerfTestBase::RunTestChannelPingPong( |
| 250 const std::vector<PingPongTestParams>& params) { | 251 const std::vector<PingPongTestParams>& params) { |
| 251 Init("PerformanceClient"); | 252 auto message_loop = base::MakeUnique<base::MessageLoopForIO>(); |
| 253 mojo::edk::test::ScopedIPCSupport ipc_support(message_loop->task_runner()); |
| 254 InitWithCustomMessageLoop("MojoPerfTestClient", std::move(message_loop)); |
| 252 | 255 |
| 253 // Set up IPC channel and start client. | 256 // Set up IPC channel and start client. |
| 254 PerformanceChannelListener listener("Channel"); | 257 PerformanceChannelListener listener("Channel"); |
| 255 CreateChannel(&listener); | 258 CreateChannel(&listener); |
| 256 listener.Init(channel()); | 259 listener.Init(channel()); |
| 257 ASSERT_TRUE(ConnectChannel()); | 260 ASSERT_TRUE(ConnectChannel()); |
| 258 ASSERT_TRUE(StartClient()); | |
| 259 | 261 |
| 260 LockThreadAffinity thread_locker(kSharedCore); | 262 LockThreadAffinity thread_locker(kSharedCore); |
| 261 for (size_t i = 0; i < params.size(); i++) { | 263 for (size_t i = 0; i < params.size(); i++) { |
| 262 listener.SetTestParams(params[i].message_count(), | 264 listener.SetTestParams(params[i].message_count(), |
| 263 params[i].message_size()); | 265 params[i].message_size()); |
| 264 | 266 |
| 265 // This initial message will kick-start the ping-pong of messages. | 267 // This initial message will kick-start the ping-pong of messages. |
| 266 Message* message = | 268 Message* message = |
| 267 new Message(0, 2, Message::PRIORITY_NORMAL); | 269 new Message(0, 2, Message::PRIORITY_NORMAL); |
| 268 message->WriteInt64(base::TimeTicks::Now().ToInternalValue()); | 270 message->WriteInt64(base::TimeTicks::Now().ToInternalValue()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 281 message->WriteString("quit"); | 283 message->WriteString("quit"); |
| 282 sender()->Send(message); | 284 sender()->Send(message); |
| 283 | 285 |
| 284 EXPECT_TRUE(WaitForClientShutdown()); | 286 EXPECT_TRUE(WaitForClientShutdown()); |
| 285 DestroyChannel(); | 287 DestroyChannel(); |
| 286 } | 288 } |
| 287 | 289 |
| 288 void IPCChannelPerfTestBase::RunTestChannelProxyPingPong( | 290 void IPCChannelPerfTestBase::RunTestChannelProxyPingPong( |
| 289 const std::vector<PingPongTestParams>& params) { | 291 const std::vector<PingPongTestParams>& params) { |
| 290 io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart)); | 292 io_thread_.reset(new base::TestIOThread(base::TestIOThread::kAutoStart)); |
| 291 InitWithCustomMessageLoop("PerformanceClient", | 293 { |
| 292 base::MakeUnique<base::MessageLoop>()); | 294 auto message_loop = base::MakeUnique<base::MessageLoopForIO>(); |
| 295 mojo::edk::test::ScopedIPCSupport ipc_support(io_thread_->task_runner()); |
| 296 InitWithCustomMessageLoop("MojoPerfTestClient", std::move(message_loop)); |
| 293 | 297 |
| 294 // Set up IPC channel and start client. | 298 // Set up IPC channel and start client. |
| 295 PerformanceChannelListener listener("ChannelProxy"); | 299 PerformanceChannelListener listener("ChannelProxy"); |
| 296 CreateChannelProxy(&listener, io_thread_->task_runner()); | 300 auto channel_proxy = IPC::ChannelProxy::Create( |
| 297 listener.Init(channel_proxy()); | 301 TakeHandle().release(), IPC::Channel::MODE_SERVER, &listener, |
| 298 ASSERT_TRUE(StartClient()); | 302 io_thread_->task_runner()); |
| 303 listener.Init(channel_proxy.get()); |
| 299 | 304 |
| 300 LockThreadAffinity thread_locker(kSharedCore); | 305 LockThreadAffinity thread_locker(kSharedCore); |
| 301 for (size_t i = 0; i < params.size(); i++) { | 306 for (size_t i = 0; i < params.size(); i++) { |
| 302 listener.SetTestParams(params[i].message_count(), | 307 listener.SetTestParams(params[i].message_count(), |
| 303 params[i].message_size()); | 308 params[i].message_size()); |
| 304 | 309 |
| 305 // This initial message will kick-start the ping-pong of messages. | 310 // This initial message will kick-start the ping-pong of messages. |
| 306 Message* message = | 311 Message* message = new Message(0, 2, Message::PRIORITY_NORMAL); |
| 307 new Message(0, 2, Message::PRIORITY_NORMAL); | 312 message->WriteInt64(base::TimeTicks::Now().ToInternalValue()); |
| 313 message->WriteInt(-1); |
| 314 message->WriteString("hello"); |
| 315 channel_proxy->Send(message); |
| 316 |
| 317 // Run message loop. |
| 318 base::RunLoop().Run(); |
| 319 } |
| 320 |
| 321 // Send quit message. |
| 322 Message* message = new Message(0, 2, Message::PRIORITY_NORMAL); |
| 308 message->WriteInt64(base::TimeTicks::Now().ToInternalValue()); | 323 message->WriteInt64(base::TimeTicks::Now().ToInternalValue()); |
| 309 message->WriteInt(-1); | 324 message->WriteInt(-1); |
| 310 message->WriteString("hello"); | 325 message->WriteString("quit"); |
| 311 sender()->Send(message); | 326 channel_proxy->Send(message); |
| 312 | 327 |
| 313 // Run message loop. | 328 EXPECT_TRUE(WaitForClientShutdown()); |
| 314 base::RunLoop().Run(); | 329 channel_proxy.reset(); |
| 315 } | 330 } |
| 316 | 331 |
| 317 // Send quit message. | |
| 318 Message* message = new Message(0, 2, Message::PRIORITY_NORMAL); | |
| 319 message->WriteInt64(base::TimeTicks::Now().ToInternalValue()); | |
| 320 message->WriteInt(-1); | |
| 321 message->WriteString("quit"); | |
| 322 sender()->Send(message); | |
| 323 | |
| 324 EXPECT_TRUE(WaitForClientShutdown()); | |
| 325 DestroyChannelProxy(); | |
| 326 | |
| 327 io_thread_.reset(); | 332 io_thread_.reset(); |
| 328 } | 333 } |
| 329 | 334 |
| 330 | 335 |
| 331 PingPongTestClient::PingPongTestClient() | 336 PingPongTestClient::PingPongTestClient() |
| 332 : listener_(new ChannelReflectorListener()) { | 337 : listener_(new ChannelReflectorListener()) { |
| 333 } | 338 } |
| 334 | 339 |
| 335 PingPongTestClient::~PingPongTestClient() { | 340 PingPongTestClient::~PingPongTestClient() { |
| 336 } | 341 } |
| 337 | 342 |
| 338 std::unique_ptr<Channel> PingPongTestClient::CreateChannel(Listener* listener) { | |
| 339 return Channel::CreateClient( | |
| 340 IPCTestBase::GetChannelName("PerformanceClient"), listener, | |
| 341 base::ThreadTaskRunnerHandle::Get()); | |
| 342 } | |
| 343 | |
| 344 int PingPongTestClient::RunMain() { | 343 int PingPongTestClient::RunMain() { |
| 345 LockThreadAffinity thread_locker(kSharedCore); | 344 LockThreadAffinity thread_locker(kSharedCore); |
| 346 std::unique_ptr<Channel> channel = CreateChannel(listener_.get()); | 345 std::unique_ptr<Channel> channel = CreateChannel(listener_.get()); |
| 347 listener_->Init(channel.get()); | 346 listener_->Init(channel.get()); |
| 348 CHECK(channel->Connect()); | 347 CHECK(channel->Connect()); |
| 349 | 348 |
| 350 base::RunLoop().Run(); | 349 base::RunLoop().Run(); |
| 351 return 0; | 350 return 0; |
| 352 } | 351 } |
| 353 | 352 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 382 auto set_result = SetThreadAffinityMask(GetCurrentThread(), old_affinity_); | 381 auto set_result = SetThreadAffinityMask(GetCurrentThread(), old_affinity_); |
| 383 DCHECK_NE(0u, set_result); | 382 DCHECK_NE(0u, set_result); |
| 384 #elif defined(OS_LINUX) | 383 #elif defined(OS_LINUX) |
| 385 auto set_result = sched_setaffinity(0, sizeof(old_cpuset_), &old_cpuset_); | 384 auto set_result = sched_setaffinity(0, sizeof(old_cpuset_), &old_cpuset_); |
| 386 DCHECK_EQ(0, set_result); | 385 DCHECK_EQ(0, set_result); |
| 387 #endif | 386 #endif |
| 388 } | 387 } |
| 389 | 388 |
| 390 } // namespace test | 389 } // namespace test |
| 391 } // namespace IPC | 390 } // namespace IPC |
| OLD | NEW |