blob: f719db4368c7c9fac6b549f523994bb4d36fc7d2 [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
avi246998d82015-12-22 02:39:048#include <stddef.h>
9
danakj03de39b22016-04-23 04:21:0910#include <memory>
morrita373af03b2014-09-09 19:35:2411#include <vector>
12
avi246998d82015-12-22 02:39:0413#include "base/macros.h"
sammce4d0abd2016-03-07 22:38:0414#include "base/test/test_io_thread.h"
gabf08ccc02016-05-11 18:51:1115#include "base/threading/thread_task_runner_handle.h"
avi246998d82015-12-22 02:39:0416#include "build/build_config.h"
morrita373af03b2014-09-09 19:35:2417#include "ipc/ipc_test_base.h"
18
19namespace IPC {
20namespace test {
21
22class ChannelReflectorListener;
23
24class 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
38class IPCChannelPerfTestBase : public IPCTestBase {
39 public:
sammce4d0abd2016-03-07 22:38:0440 IPCChannelPerfTestBase();
41 ~IPCChannelPerfTestBase() override;
42
morrita373af03b2014-09-09 19:35:2443 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);
sammce4d0abd2016-03-07 22:38:0449
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:
danakj03de39b22016-04-23 04:21:0957 std::unique_ptr<base::TestIOThread> io_thread_;
morrita373af03b2014-09-09 19:35:2458};
59
60class PingPongTestClient {
61 public:
62 PingPongTestClient();
63 virtual ~PingPongTestClient();
64
danakj03de39b22016-04-23 04:21:0965 virtual std::unique_ptr<Channel> CreateChannel(Listener* listener);
morrita373af03b2014-09-09 19:35:2466 int RunMain();
67 scoped_refptr<base::TaskRunner> task_runner();
68
69 private:
70 base::MessageLoopForIO main_message_loop_;
danakj03de39b22016-04-23 04:21:0971 std::unique_ptr<ChannelReflectorListener> listener_;
72 std::unique_ptr<Channel> channel_;
morrita373af03b2014-09-09 19:35:2473};
74
brucedawsonaa3d0c52015-02-12 22:33:2275// 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.
80class 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
morrita373af03b2014-09-09 19:35:2496}
97}
98
99#endif // IPC_IPC_PERFTEST_SUPPORT_H_