morrita | 373af03b | 2014-09-09 19:35:24 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef IPC_IPC_PERFTEST_SUPPORT_H_ |
| 6 | #define IPC_IPC_PERFTEST_SUPPORT_H_ |
| 7 | |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
danakj | 03de39b2 | 2016-04-23 04:21:09 | [diff] [blame] | 10 | #include <memory> |
morrita | 373af03b | 2014-09-09 19:35:24 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 13 | #include "base/macros.h" |
sammc | e4d0abd | 2016-03-07 22:38:04 | [diff] [blame] | 14 | #include "base/test/test_io_thread.h" |
gab | f08ccc0 | 2016-05-11 18:51:11 | [diff] [blame] | 15 | #include "base/threading/thread_task_runner_handle.h" |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 16 | #include "build/build_config.h" |
morrita | 373af03b | 2014-09-09 19:35:24 | [diff] [blame] | 17 | #include "ipc/ipc_test_base.h" |
| 18 | |
| 19 | namespace IPC { |
| 20 | namespace test { |
| 21 | |
| 22 | class ChannelReflectorListener; |
| 23 | |
| 24 | class PingPongTestParams { |
| 25 | public: |
| 26 | PingPongTestParams(size_t size, int count) |
| 27 | : message_size_(size), message_count_(count) { |
| 28 | } |
| 29 | |
| 30 | size_t message_size() const { return message_size_; } |
| 31 | int message_count() const { return message_count_; } |
| 32 | |
| 33 | private: |
| 34 | size_t message_size_; |
| 35 | int message_count_; |
| 36 | }; |
| 37 | |
| 38 | class IPCChannelPerfTestBase : public IPCTestBase { |
| 39 | public: |
sammc | e4d0abd | 2016-03-07 22:38:04 | [diff] [blame] | 40 | IPCChannelPerfTestBase(); |
| 41 | ~IPCChannelPerfTestBase() override; |
| 42 | |
morrita | 373af03b | 2014-09-09 19:35:24 | [diff] [blame] | 43 | static std::vector<PingPongTestParams> GetDefaultTestParams(); |
| 44 | |
| 45 | void RunTestChannelPingPong( |
| 46 | const std::vector<PingPongTestParams>& params_list); |
| 47 | void RunTestChannelProxyPingPong( |
| 48 | const std::vector<PingPongTestParams>& params_list); |
sammc | e4d0abd | 2016-03-07 22:38:04 | [diff] [blame] | 49 | |
| 50 | scoped_refptr<base::TaskRunner> io_task_runner() { |
| 51 | if (io_thread_) |
| 52 | return io_thread_->task_runner(); |
| 53 | return base::ThreadTaskRunnerHandle::Get(); |
| 54 | } |
| 55 | |
| 56 | private: |
danakj | 03de39b2 | 2016-04-23 04:21:09 | [diff] [blame] | 57 | std::unique_ptr<base::TestIOThread> io_thread_; |
morrita | 373af03b | 2014-09-09 19:35:24 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | class PingPongTestClient { |
| 61 | public: |
| 62 | PingPongTestClient(); |
| 63 | virtual ~PingPongTestClient(); |
| 64 | |
danakj | 03de39b2 | 2016-04-23 04:21:09 | [diff] [blame] | 65 | virtual std::unique_ptr<Channel> CreateChannel(Listener* listener); |
morrita | 373af03b | 2014-09-09 19:35:24 | [diff] [blame] | 66 | int RunMain(); |
| 67 | scoped_refptr<base::TaskRunner> task_runner(); |
| 68 | |
| 69 | private: |
| 70 | base::MessageLoopForIO main_message_loop_; |
danakj | 03de39b2 | 2016-04-23 04:21:09 | [diff] [blame] | 71 | std::unique_ptr<ChannelReflectorListener> listener_; |
| 72 | std::unique_ptr<Channel> channel_; |
morrita | 373af03b | 2014-09-09 19:35:24 | [diff] [blame] | 73 | }; |
| 74 | |
brucedawson | aa3d0c5 | 2015-02-12 22:33:22 | [diff] [blame] | 75 | // This class locks the current thread to a particular CPU core. This is |
| 76 | // important because otherwise the different threads and processes of these |
| 77 | // tests end up on different CPU cores which means that all of the cores are |
| 78 | // lightly loaded so the OS (Windows and Linux) fails to ramp up the CPU |
| 79 | // frequency, leading to unpredictable and often poor performance. |
| 80 | class LockThreadAffinity { |
| 81 | public: |
| 82 | explicit LockThreadAffinity(int cpu_number); |
| 83 | ~LockThreadAffinity(); |
| 84 | |
| 85 | private: |
| 86 | bool affinity_set_ok_; |
| 87 | #if defined(OS_WIN) |
| 88 | DWORD_PTR old_affinity_; |
| 89 | #elif defined(OS_LINUX) |
| 90 | cpu_set_t old_cpuset_; |
| 91 | #endif |
| 92 | |
| 93 | DISALLOW_COPY_AND_ASSIGN(LockThreadAffinity); |
| 94 | }; |
| 95 | |
morrita | 373af03b | 2014-09-09 19:35:24 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | |
| 99 | #endif // IPC_IPC_PERFTEST_SUPPORT_H_ |