summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_perftest_support.h
blob: 578256f8b1152758c6c5804408732459e0f10bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IPC_IPC_PERFTEST_SUPPORT_H_
#define IPC_IPC_PERFTEST_SUPPORT_H_

#include <vector>

#include "ipc/ipc_test_base.h"

namespace IPC {
namespace test {

class ChannelReflectorListener;

class PingPongTestParams {
 public:
  PingPongTestParams(size_t size, int count)
      : message_size_(size), message_count_(count) {
  }

  size_t message_size() const { return message_size_; }
  int message_count() const { return message_count_; }

 private:
  size_t message_size_;
  int message_count_;
};

class IPCChannelPerfTestBase : public IPCTestBase {
 public:
  static std::vector<PingPongTestParams> GetDefaultTestParams();

  void RunTestChannelPingPong(
      const std::vector<PingPongTestParams>& params_list);
  void RunTestChannelProxyPingPong(
      const std::vector<PingPongTestParams>& params_list);
};

class PingPongTestClient {
 public:
  PingPongTestClient();
  virtual ~PingPongTestClient();

  virtual scoped_ptr<Channel> CreateChannel(Listener* listener);
  int RunMain();
  scoped_refptr<base::TaskRunner> task_runner();

 private:
  base::MessageLoopForIO main_message_loop_;
  scoped_ptr<ChannelReflectorListener> listener_;
  scoped_ptr<Channel> channel_;
};

// This class locks the current thread to a particular CPU core. This is
// important because otherwise the different threads and processes of these
// tests end up on different CPU cores which means that all of the cores are
// lightly loaded so the OS (Windows and Linux) fails to ramp up the CPU
// frequency, leading to unpredictable and often poor performance.
class LockThreadAffinity {
 public:
  explicit LockThreadAffinity(int cpu_number);
  ~LockThreadAffinity();

 private:
  bool affinity_set_ok_;
#if defined(OS_WIN)
  DWORD_PTR old_affinity_;
#elif defined(OS_LINUX)
  cpu_set_t old_cpuset_;
#endif

  DISALLOW_COPY_AND_ASSIGN(LockThreadAffinity);
};

}
}

#endif  // IPC_IPC_PERFTEST_SUPPORT_H_