| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "mojo/public/cpp/bindings/binding.h" | 11 #include "mojo/public/cpp/bindings/binding.h" |
| 12 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
| 13 #include "mojo/public/cpp/bindings/lib/message_builder.h" |
| 14 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 15 #include "mojo/public/cpp/bindings/lib/router.h" |
| 16 #include "mojo/public/cpp/bindings/message.h" |
| 12 #include "mojo/public/cpp/test_support/test_support.h" | 17 #include "mojo/public/cpp/test_support/test_support.h" |
| 13 #include "mojo/public/cpp/test_support/test_utils.h" | 18 #include "mojo/public/cpp/test_support/test_utils.h" |
| 14 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" | 19 #include "mojo/public/interfaces/bindings/tests/ping_service.mojom.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 21 |
| 17 namespace mojo { | 22 namespace mojo { |
| 18 namespace { | 23 namespace { |
| 19 | 24 |
| 20 const double kMojoTicksPerSecond = 1000000.0; | 25 const double kMojoTicksPerSecond = 1000000.0; |
| 21 | 26 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); | 131 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); |
| 127 test::LogPerfResult( | 132 test::LogPerfResult( |
| 128 "InProcessPingPong", "1000_Inactive", | 133 "InProcessPingPong", "1000_Inactive", |
| 129 kIterations / MojoTicksToSeconds(end_time - start_time), | 134 kIterations / MojoTicksToSeconds(end_time - start_time), |
| 130 "pings/second"); | 135 "pings/second"); |
| 131 | 136 |
| 132 delete[] inactive_services; | 137 delete[] inactive_services; |
| 133 } | 138 } |
| 134 } | 139 } |
| 135 | 140 |
| 141 class PingPongPaddle : public MessageReceiverWithResponderStatus { |
| 142 public: |
| 143 PingPongPaddle(MessageReceiver* sender) : sender_(sender) {} |
| 144 |
| 145 void set_sender(MessageReceiver* sender) { sender_ = sender; } |
| 146 |
| 147 bool Accept(Message* message) override { |
| 148 uint32_t count = message->header()->name; |
| 149 if (!quit_closure_.is_null()) { |
| 150 count++; |
| 151 if (count >= expected_count_) { |
| 152 quit_closure_.Run(); |
| 153 return true; |
| 154 } |
| 155 } |
| 156 |
| 157 internal::MessageBuilder builder(count, 8); |
| 158 bool result = sender_->Accept(builder.message()); |
| 159 DCHECK(result); |
| 160 return true; |
| 161 } |
| 162 |
| 163 bool AcceptWithResponder(Message* message, |
| 164 MessageReceiverWithStatus* responder) override { |
| 165 NOTREACHED(); |
| 166 return true; |
| 167 } |
| 168 |
| 169 void Serve(uint32_t expected_count) { |
| 170 base::RunLoop run_loop; |
| 171 |
| 172 expected_count_ = expected_count; |
| 173 quit_closure_ = run_loop.QuitClosure(); |
| 174 |
| 175 internal::MessageBuilder builder(0, 8); |
| 176 bool result = sender_->Accept(builder.message()); |
| 177 DCHECK(result); |
| 178 |
| 179 run_loop.Run(); |
| 180 } |
| 181 |
| 182 private: |
| 183 uint32_t expected_count_ = 0; |
| 184 MessageReceiver* sender_; |
| 185 base::Closure quit_closure_; |
| 186 }; |
| 187 |
| 188 TEST_F(MojoBindingsPerftest, RouterPingPong) { |
| 189 MessagePipe pipe; |
| 190 internal::Router router0(std::move(pipe.handle0), FilterChain(), false, |
| 191 base::ThreadTaskRunnerHandle::Get(), 0u); |
| 192 internal::Router router1(std::move(pipe.handle1), FilterChain(), false, |
| 193 base::ThreadTaskRunnerHandle::Get(), 0u); |
| 194 PingPongPaddle paddle0(&router0); |
| 195 router0.set_incoming_receiver(&paddle0); |
| 196 PingPongPaddle paddle1(&router1); |
| 197 router1.set_incoming_receiver(&paddle1); |
| 198 |
| 199 static const uint32_t kWarmUpIterations = 1000; |
| 200 static const uint32_t kTestIterations = 100000; |
| 201 |
| 202 paddle0.Serve(kWarmUpIterations); |
| 203 |
| 204 const MojoTimeTicks start_time = MojoGetTimeTicksNow(); |
| 205 paddle0.Serve(kTestIterations); |
| 206 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); |
| 207 |
| 208 test::LogPerfResult( |
| 209 "RouterPingPong", nullptr, |
| 210 kTestIterations / MojoTicksToSeconds(end_time - start_time), |
| 211 "pings/second"); |
| 212 } |
| 213 |
| 214 TEST_F(MojoBindingsPerftest, MultiplexRouterPingPong) { |
| 215 MessagePipe pipe; |
| 216 scoped_refptr<internal::MultiplexRouter> router0( |
| 217 new internal::MultiplexRouter(true, std::move(pipe.handle0), |
| 218 base::ThreadTaskRunnerHandle::Get())); |
| 219 scoped_refptr<internal::MultiplexRouter> router1( |
| 220 new internal::MultiplexRouter(false, std::move(pipe.handle1), |
| 221 base::ThreadTaskRunnerHandle::Get())); |
| 222 |
| 223 PingPongPaddle paddle0(nullptr); |
| 224 PingPongPaddle paddle1(nullptr); |
| 225 |
| 226 InterfaceEndpointClient client0( |
| 227 router0->CreateLocalEndpointHandle(kMasterInterfaceId), &paddle0, |
| 228 base::MakeUnique<PassThroughFilter>(), false, |
| 229 base::ThreadTaskRunnerHandle::Get(), 0u); |
| 230 InterfaceEndpointClient client1( |
| 231 router1->CreateLocalEndpointHandle(kMasterInterfaceId), &paddle1, |
| 232 base::MakeUnique<PassThroughFilter>(), false, |
| 233 base::ThreadTaskRunnerHandle::Get(), 0u); |
| 234 |
| 235 paddle0.set_sender(&client0); |
| 236 paddle1.set_sender(&client1); |
| 237 |
| 238 static const uint32_t kWarmUpIterations = 1000; |
| 239 static const uint32_t kTestIterations = 100000; |
| 240 |
| 241 paddle0.Serve(kWarmUpIterations); |
| 242 |
| 243 const MojoTimeTicks start_time = MojoGetTimeTicksNow(); |
| 244 paddle0.Serve(kTestIterations); |
| 245 const MojoTimeTicks end_time = MojoGetTimeTicksNow(); |
| 246 |
| 247 test::LogPerfResult( |
| 248 "MultiplexRouterPingPong", nullptr, |
| 249 kTestIterations / MojoTicksToSeconds(end_time - start_time), |
| 250 "pings/second"); |
| 251 } |
| 252 |
| 136 } // namespace | 253 } // namespace |
| 137 } // namespace mojo | 254 } // namespace mojo |
| OLD | NEW |