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

Unified Diff: ipc/ipc_perftest_support.cc

Issue 536213002: Add ipc_mojo_perftests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed garbage Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/ipc_perftest_support.h ('k') | ipc/ipc_perftests.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_perftest_support.cc
diff --git a/ipc/ipc_perftests.cc b/ipc/ipc_perftest_support.cc
similarity index 76%
copy from ipc/ipc_perftests.cc
copy to ipc/ipc_perftest_support.cc
index 08a8d701eb61d2769de476bd0995370fd7f981c2..b82642044524f26811ffe6cff4cea92b74fba048 100644
--- a/ipc/ipc_perftests.cc
+++ b/ipc/ipc_perftest_support.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "build/build_config.h"
+#include "ipc/ipc_perftest_support.h"
#include <algorithm>
#include <string>
@@ -16,21 +16,15 @@
#include "base/test/test_io_thread.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
+#include "build/build_config.h"
#include "ipc/ipc_channel.h"
#include "ipc/ipc_channel_proxy.h"
#include "ipc/ipc_descriptors.h"
#include "ipc/ipc_message_utils.h"
#include "ipc/ipc_sender.h"
-#include "ipc/ipc_test_base.h"
-
-namespace {
-// This test times the roundtrip IPC message cycle.
-//
-// TODO(brettw): Make this test run by default.
-
-class IPCChannelPerfTest : public IPCTestBase {
-};
+namespace IPC {
+namespace test {
// This class simply collects stats about abstract "events" (each of which has a
// start time and an end time).
@@ -79,7 +73,7 @@ class EventTimeTracker {
// This channel listener just replies to all messages with the exact same
// message. It assumes each message has one string parameter. When the string
// "quit" is sent, it will exit.
-class ChannelReflectorListener : public IPC::Listener {
+class ChannelReflectorListener : public Listener {
public:
ChannelReflectorListener()
: channel_(NULL),
@@ -92,12 +86,12 @@ class ChannelReflectorListener : public IPC::Listener {
latency_tracker_.ShowResults();
}
- void Init(IPC::Channel* channel) {
+ void Init(Channel* channel) {
DCHECK(!channel_);
channel_ = channel;
}
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
+ virtual bool OnMessageReceived(const Message& message) OVERRIDE {
CHECK(channel_);
PickleIterator iter(message);
@@ -123,7 +117,7 @@ class ChannelReflectorListener : public IPC::Listener {
base::TimeTicks::FromInternalValue(time_internal), now);
}
- IPC::Message* msg = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
+ Message* msg = new Message(0, 2, Message::PRIORITY_NORMAL);
msg->WriteInt64(base::TimeTicks::Now().ToInternalValue());
msg->WriteInt(msgid);
msg->WriteString(payload);
@@ -132,11 +126,11 @@ class ChannelReflectorListener : public IPC::Listener {
}
private:
- IPC::Channel* channel_;
+ Channel* channel_;
EventTimeTracker latency_tracker_;
};
-class PerformanceChannelListener : public IPC::Listener {
+class PerformanceChannelListener : public Listener {
public:
explicit PerformanceChannelListener(const std::string& label)
: label_(label),
@@ -152,7 +146,7 @@ class PerformanceChannelListener : public IPC::Listener {
VLOG(1) << "Server listener down";
}
- void Init(IPC::Sender* sender) {
+ void Init(Sender* sender) {
DCHECK(!sender_);
sender_ = sender;
}
@@ -166,7 +160,7 @@ class PerformanceChannelListener : public IPC::Listener {
payload_ = std::string(msg_size_, 'a');
}
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
+ virtual bool OnMessageReceived(const Message& message) OVERRIDE {
CHECK(sender_);
PickleIterator iter(message);
@@ -206,7 +200,7 @@ class PerformanceChannelListener : public IPC::Listener {
}
}
- IPC::Message* msg = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
+ Message* msg = new Message(0, 2, Message::PRIORITY_NORMAL);
msg->WriteInt64(base::TimeTicks::Now().ToInternalValue());
msg->WriteInt(count_down_);
msg->WriteString(payload_);
@@ -216,7 +210,7 @@ class PerformanceChannelListener : public IPC::Listener {
private:
std::string label_;
- IPC::Sender* sender_;
+ Sender* sender_;
int msg_count_;
size_t msg_size_;
@@ -226,7 +220,21 @@ class PerformanceChannelListener : public IPC::Listener {
scoped_ptr<base::PerfTimeLogger> perf_logger_;
};
-TEST_F(IPCChannelPerfTest, ChannelPingPong) {
+std::vector<PingPongTestParams>
+IPCChannelPerfTestBase::GetDefaultTestParams() {
+ // Test several sizes. We use 12^N for message size, and limit the message
+ // count to keep the test duration reasonable.
+ std::vector<PingPongTestParams> list;
+ list.push_back(PingPongTestParams(12, 50000));
+ list.push_back(PingPongTestParams(144, 50000));
+ list.push_back(PingPongTestParams(1728, 50000));
+ list.push_back(PingPongTestParams(20736, 12000));
+ list.push_back(PingPongTestParams(248832, 100));
+ return list;
+}
+
+void IPCChannelPerfTestBase::RunTestChannelPingPong(
+ const std::vector<PingPongTestParams>& params) {
Init("PerformanceClient");
// Set up IPC channel and start client.
@@ -236,17 +244,13 @@ TEST_F(IPCChannelPerfTest, ChannelPingPong) {
ASSERT_TRUE(ConnectChannel());
ASSERT_TRUE(StartClient());
- // Test several sizes. We use 12^N for message size, and limit the message
- // count to keep the test duration reasonable.
- const size_t kMsgSize[5] = {12, 144, 1728, 20736, 248832};
- const int kMessageCount[5] = {50000, 50000, 50000, 12000, 1000};
-
- for (size_t i = 0; i < 5; i++) {
- listener.SetTestParams(kMessageCount[i], kMsgSize[i]);
+ for (size_t i = 0; i < params.size(); i++) {
+ listener.SetTestParams(params[i].message_count(),
+ params[i].message_size());
// This initial message will kick-start the ping-pong of messages.
- IPC::Message* message =
- new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
+ Message* message =
+ new Message(0, 2, Message::PRIORITY_NORMAL);
message->WriteInt64(base::TimeTicks::Now().ToInternalValue());
message->WriteInt(-1);
message->WriteString("hello");
@@ -257,7 +261,7 @@ TEST_F(IPCChannelPerfTest, ChannelPingPong) {
}
// Send quit message.
- IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
+ Message* message = new Message(0, 2, Message::PRIORITY_NORMAL);
message->WriteInt64(base::TimeTicks::Now().ToInternalValue());
message->WriteInt(-1);
message->WriteString("quit");
@@ -267,20 +271,8 @@ TEST_F(IPCChannelPerfTest, ChannelPingPong) {
DestroyChannel();
}
-// This message loop bounces all messages back to the sender.
-MULTIPROCESS_IPC_TEST_CLIENT_MAIN(PerformanceClient) {
- base::MessageLoopForIO main_message_loop;
- ChannelReflectorListener listener;
- scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient(
- IPCTestBase::GetChannelName("PerformanceClient"), &listener));
- listener.Init(channel.get());
- CHECK(channel->Connect());
-
- base::MessageLoop::current()->Run();
- return 0;
-}
-
-TEST_F(IPCChannelPerfTest, ChannelProxyPingPong) {
+void IPCChannelPerfTestBase::RunTestChannelProxyPingPong(
+ const std::vector<PingPongTestParams>& params) {
InitWithCustomMessageLoop("PerformanceClient",
make_scoped_ptr(new base::MessageLoop()));
@@ -292,17 +284,13 @@ TEST_F(IPCChannelPerfTest, ChannelProxyPingPong) {
listener.Init(channel_proxy());
ASSERT_TRUE(StartClient());
- // Test several sizes. We use 12^N for message size, and limit the message
- // count to keep the test duration reasonable.
- const size_t kMsgSize[5] = {12, 144, 1728, 20736, 248832};
- const int kMessageCount[5] = {50000, 50000, 50000, 12000, 1000};
-
- for (size_t i = 0; i < 5; i++) {
- listener.SetTestParams(kMessageCount[i], kMsgSize[i]);
+ for (size_t i = 0; i < params.size(); i++) {
+ listener.SetTestParams(params[i].message_count(),
+ params[i].message_size());
// This initial message will kick-start the ping-pong of messages.
- IPC::Message* message =
- new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
+ Message* message =
+ new Message(0, 2, Message::PRIORITY_NORMAL);
message->WriteInt64(base::TimeTicks::Now().ToInternalValue());
message->WriteInt(-1);
message->WriteString("hello");
@@ -313,7 +301,7 @@ TEST_F(IPCChannelPerfTest, ChannelProxyPingPong) {
}
// Send quit message.
- IPC::Message* message = new IPC::Message(0, 2, IPC::Message::PRIORITY_NORMAL);
+ Message* message = new Message(0, 2, Message::PRIORITY_NORMAL);
message->WriteInt64(base::TimeTicks::Now().ToInternalValue());
message->WriteInt(-1);
message->WriteString("quit");
@@ -323,4 +311,32 @@ TEST_F(IPCChannelPerfTest, ChannelProxyPingPong) {
DestroyChannelProxy();
}
-} // namespace
+
+PingPongTestClient::PingPongTestClient()
+ : listener_(new ChannelReflectorListener()) {
+}
+
+PingPongTestClient::~PingPongTestClient() {
+}
+
+scoped_ptr<Channel> PingPongTestClient::CreateChannel(
+ Listener* listener) {
+ return Channel::CreateClient(
+ IPCTestBase::GetChannelName("PerformanceClient"), listener);
+}
+
+int PingPongTestClient::RunMain() {
+ scoped_ptr<Channel> channel = CreateChannel(listener_.get());
+ listener_->Init(channel.get());
+ CHECK(channel->Connect());
+
+ base::MessageLoop::current()->Run();
+ return 0;
+}
+
+scoped_refptr<base::TaskRunner> PingPongTestClient::task_runner() {
+ return main_message_loop_.message_loop_proxy();
+}
+
+} // namespace test
+} // namespace IPC
« no previous file with comments | « ipc/ipc_perftest_support.h ('k') | ipc/ipc_perftests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698