OLD | NEW |
| (Empty) |
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 | |
8 #include <stddef.h> | |
9 | |
10 #include <memory> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/test/test_io_thread.h" | |
15 #include "base/threading/thread_task_runner_handle.h" | |
16 #include "build/build_config.h" | |
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 IPCChannelMojoTestBase { | |
39 public: | |
40 IPCChannelPerfTestBase(); | |
41 ~IPCChannelPerfTestBase() override; | |
42 | |
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); | |
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: | |
57 std::unique_ptr<base::TestIOThread> io_thread_; | |
58 }; | |
59 | |
60 class PingPongTestClient { | |
61 public: | |
62 PingPongTestClient(); | |
63 virtual ~PingPongTestClient(); | |
64 | |
65 virtual std::unique_ptr<Channel> CreateChannel(Listener* listener) = 0; | |
66 int RunMain(); | |
67 scoped_refptr<base::TaskRunner> task_runner(); | |
68 | |
69 private: | |
70 base::MessageLoopForIO main_message_loop_; | |
71 std::unique_ptr<ChannelReflectorListener> listener_; | |
72 std::unique_ptr<Channel> channel_; | |
73 }; | |
74 | |
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 | |
96 } | |
97 } | |
98 | |
99 #endif // IPC_IPC_PERFTEST_SUPPORT_H_ | |
OLD | NEW |