Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: ipc/ipc_perftests.cc

Issue 12051048: Refactor (many) IPC tests, notably most of the multiprocess tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_multiprocess_test.cc ('k') | ipc/ipc_send_fds_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN)
8 #include <windows.h>
9 #elif defined(OS_POSIX)
10 #include <sys/types.h>
11 #include <unistd.h>
12 #endif
13
14 #include <algorithm> 7 #include <algorithm>
15 #include <string> 8 #include <string>
16 9
17 #include "base/basictypes.h" 10 #include "base/basictypes.h"
18 #include "base/logging.h" 11 #include "base/logging.h"
19 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
20 #include "base/perftimer.h" 13 #include "base/perftimer.h"
21 #include "base/pickle.h" 14 #include "base/pickle.h"
22 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
23 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
24 #include "base/time.h" 17 #include "base/time.h"
25 #include "ipc/ipc_descriptors.h" 18 #include "ipc/ipc_descriptors.h"
26 #include "ipc/ipc_channel.h" 19 #include "ipc/ipc_channel.h"
27 #include "ipc/ipc_channel_proxy.h" 20 #include "ipc/ipc_channel_proxy.h"
28 #include "ipc/ipc_message_utils.h" 21 #include "ipc/ipc_message_utils.h"
29 #include "ipc/ipc_multiprocess_test.h"
30 #include "ipc/ipc_sender.h" 22 #include "ipc/ipc_sender.h"
31 #include "ipc/ipc_test_base.h" 23 #include "ipc/ipc_test_base.h"
32 24
33 namespace { 25 namespace {
34 26
35 // This test times the roundtrip IPC message cycle. 27 // This test times the roundtrip IPC message cycle.
36 // 28 //
37 // TODO(brettw): Make this test run by default. 29 // TODO(brettw): Make this test run by default.
38 30
39 class IPCChannelPerfTest : public IPCTestBase { 31 class IPCChannelPerfTest : public IPCTestBase {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 msg->WriteString(payload); 128 msg->WriteString(payload);
137 channel_->Send(msg); 129 channel_->Send(msg);
138 return true; 130 return true;
139 } 131 }
140 132
141 private: 133 private:
142 IPC::Channel* channel_; 134 IPC::Channel* channel_;
143 EventTimeTracker latency_tracker_; 135 EventTimeTracker latency_tracker_;
144 }; 136 };
145 137
146 class ChannelPerfListener : public IPC::Listener { 138 class PerformanceChannelListener : public IPC::Listener {
147 public: 139 public:
148 ChannelPerfListener() 140 PerformanceChannelListener()
149 : channel_(NULL), 141 : channel_(NULL),
150 msg_count_(0), 142 msg_count_(0),
151 msg_size_(0), 143 msg_size_(0),
152 count_down_(0), 144 count_down_(0),
153 latency_tracker_("Server messages") { 145 latency_tracker_("Server messages") {
154 VLOG(1) << "Server listener up"; 146 VLOG(1) << "Server listener up";
155 } 147 }
156 148
157 ~ChannelPerfListener() { 149 ~PerformanceChannelListener() {
158 VLOG(1) << "Server listener down"; 150 VLOG(1) << "Server listener down";
159 } 151 }
160 152
161 void Init(IPC::Channel* channel) { 153 void Init(IPC::Channel* channel) {
162 DCHECK(!channel_); 154 DCHECK(!channel_);
163 channel_ = channel; 155 channel_ = channel;
164 } 156 }
165 157
166 // Call this before running the message loop. 158 // Call this before running the message loop.
167 void SetTestParams(int msg_count, size_t msg_size) { 159 void SetTestParams(int msg_count, size_t msg_size) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 int msg_count_; 214 int msg_count_;
223 size_t msg_size_; 215 size_t msg_size_;
224 216
225 int count_down_; 217 int count_down_;
226 std::string payload_; 218 std::string payload_;
227 EventTimeTracker latency_tracker_; 219 EventTimeTracker latency_tracker_;
228 scoped_ptr<PerfTimeLogger> perf_logger_; 220 scoped_ptr<PerfTimeLogger> perf_logger_;
229 }; 221 };
230 222
231 TEST_F(IPCChannelPerfTest, Performance) { 223 TEST_F(IPCChannelPerfTest, Performance) {
232 // Setup IPC channel. 224 Init("PerformanceClient");
233 ChannelPerfListener perf_listener;
234 IPC::Channel chan(kReflectorChannel, IPC::Channel::MODE_SERVER,
235 &perf_listener);
236 perf_listener.Init(&chan);
237 ASSERT_TRUE(chan.Connect());
238 225
239 base::ProcessHandle process_handle = SpawnChild(TEST_REFLECTOR, &chan); 226 // Set up IPC channel and start client.
240 ASSERT_TRUE(process_handle); 227 PerformanceChannelListener listener;
228 CreateChannel(&listener);
229 listener.Init(channel());
230 ASSERT_TRUE(ConnectChannel());
231 ASSERT_TRUE(StartClient());
241 232
242 const size_t kMsgSizeBase = 12; 233 const size_t kMsgSizeBase = 12;
243 const int kMsgSizeMaxExp = 5; 234 const int kMsgSizeMaxExp = 5;
244 int msg_count = 100000; 235 int msg_count = 100000;
245 size_t msg_size = kMsgSizeBase; 236 size_t msg_size = kMsgSizeBase;
246 for (int i = 1; i <= kMsgSizeMaxExp; i++) { 237 for (int i = 1; i <= kMsgSizeMaxExp; i++) {
247 perf_listener.SetTestParams(msg_count, msg_size); 238 listener.SetTestParams(msg_count, msg_size);
248 239
249 // This initial message will kick-start the ping-pong of messages. 240 // This initial message will kick-start the ping-pong of messages.
250 IPC::Message* message = 241 IPC::Message* message =
251 new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL); 242 new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
252 message->WriteInt64(base::TimeTicks::Now().ToInternalValue()); 243 message->WriteInt64(base::TimeTicks::Now().ToInternalValue());
253 message->WriteInt(-1); 244 message->WriteInt(-1);
254 message->WriteString("hello"); 245 message->WriteString("hello");
255 chan.Send(message); 246 sender()->Send(message);
256 247
257 // Run message loop. 248 // Run message loop.
258 MessageLoop::current()->Run(); 249 MessageLoop::current()->Run();
259 250
260 msg_size *= kMsgSizeBase; 251 msg_size *= kMsgSizeBase;
261 } 252 }
262 253
263 // Send quit message. 254 // Send quit message.
264 IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL); 255 IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
265 message->WriteInt64(base::TimeTicks::Now().ToInternalValue()); 256 message->WriteInt64(base::TimeTicks::Now().ToInternalValue());
266 message->WriteInt(-1); 257 message->WriteInt(-1);
267 message->WriteString("quit"); 258 message->WriteString("quit");
268 chan.Send(message); 259 sender()->Send(message);
269 260
270 // Clean up child process. 261 EXPECT_TRUE(WaitForClientShutdown());
271 EXPECT_TRUE(base::WaitForSingleProcess(process_handle, 262 DestroyChannel();
272 base::TimeDelta::FromSeconds(5)));
273 base::CloseProcessHandle(process_handle);
274 } 263 }
275 264
276 // This message loop bounces all messages back to the sender. 265 // This message loop bounces all messages back to the sender.
277 MULTIPROCESS_IPC_TEST_MAIN(RunReflector) { 266 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
278 MessageLoopForIO main_message_loop; 267 MessageLoopForIO main_message_loop;
279 ChannelReflectorListener channel_reflector_listener; 268 ChannelReflectorListener listener;
280 IPC::Channel chan(kReflectorChannel, IPC::Channel::MODE_CLIENT, 269 IPC::Channel channel(IPCTestBase::GetChannelName("PerformanceClient"),
281 &channel_reflector_listener); 270 IPC::Channel::MODE_CLIENT,
282 channel_reflector_listener.Init(&chan); 271 &listener);
283 CHECK(chan.Connect()); 272 listener.Init(&channel);
273 CHECK(channel.Connect());
284 274
285 MessageLoop::current()->Run(); 275 MessageLoop::current()->Run();
286 return 0; 276 return 0;
287 } 277 }
288 278
289 } // namespace 279 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_multiprocess_test.cc ('k') | ipc/ipc_send_fds_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698