blob: 578256f8b1152758c6c5804408732459e0f10bd0 [file] [log] [blame]
morrita373af03b2014-09-09 19:35:241// 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 <vector>
9
10#include "ipc/ipc_test_base.h"
11
12namespace IPC {
13namespace test {
14
15class ChannelReflectorListener;
16
17class PingPongTestParams {
18 public:
19 PingPongTestParams(size_t size, int count)
20 : message_size_(size), message_count_(count) {
21 }
22
23 size_t message_size() const { return message_size_; }
24 int message_count() const { return message_count_; }
25
26 private:
27 size_t message_size_;
28 int message_count_;
29};
30
31class IPCChannelPerfTestBase : public IPCTestBase {
32 public:
33 static std::vector<PingPongTestParams> GetDefaultTestParams();
34
35 void RunTestChannelPingPong(
36 const std::vector<PingPongTestParams>& params_list);
37 void RunTestChannelProxyPingPong(
38 const std::vector<PingPongTestParams>& params_list);
39};
40
41class PingPongTestClient {
42 public:
43 PingPongTestClient();
44 virtual ~PingPongTestClient();
45
46 virtual scoped_ptr<Channel> CreateChannel(Listener* listener);
47 int RunMain();
48 scoped_refptr<base::TaskRunner> task_runner();
49
50 private:
51 base::MessageLoopForIO main_message_loop_;
52 scoped_ptr<ChannelReflectorListener> listener_;
53 scoped_ptr<Channel> channel_;
54};
55
brucedawsonaa3d0c52015-02-12 22:33:2256// This class locks the current thread to a particular CPU core. This is
57// important because otherwise the different threads and processes of these
58// tests end up on different CPU cores which means that all of the cores are
59// lightly loaded so the OS (Windows and Linux) fails to ramp up the CPU
60// frequency, leading to unpredictable and often poor performance.
61class LockThreadAffinity {
62 public:
63 explicit LockThreadAffinity(int cpu_number);
64 ~LockThreadAffinity();
65
66 private:
67 bool affinity_set_ok_;
68#if defined(OS_WIN)
69 DWORD_PTR old_affinity_;
70#elif defined(OS_LINUX)
71 cpu_set_t old_cpuset_;
72#endif
73
74 DISALLOW_COPY_AND_ASSIGN(LockThreadAffinity);
75};
76
morrita373af03b2014-09-09 19:35:2477}
78}
79
80#endif // IPC_IPC_PERFTEST_SUPPORT_H_