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

Side by Side Diff: mojo/message_pump/handle_watcher_perftest.cc

Issue 1538823002: Convert Pass()→std::move() in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « mojo/gles2/gles2_impl.cc ('k') | mojo/message_pump/handle_watcher_unittest.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 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 "mojo/message_pump/handle_watcher.h"
6
7 #include <string> 5 #include <string>
6 #include <utility>
8 7
9 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
12 #include "base/run_loop.h" 11 #include "base/run_loop.h"
13 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "mojo/message_pump/handle_watcher.h"
14 #include "mojo/message_pump/message_pump_mojo.h" 14 #include "mojo/message_pump/message_pump_mojo.h"
15 #include "mojo/public/cpp/test_support/test_support.h" 15 #include "mojo/public/cpp/test_support/test_support.h"
16 #include "mojo/public/cpp/test_support/test_utils.h" 16 #include "mojo/public/cpp/test_support/test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace common { 20 namespace common {
21 namespace test { 21 namespace test {
22 22
23 enum MessageLoopConfig { 23 enum MessageLoopConfig {
24 MESSAGE_LOOP_CONFIG_DEFAULT = 0, 24 MESSAGE_LOOP_CONFIG_DEFAULT = 0,
25 MESSAGE_LOOP_CONFIG_MOJO = 1 25 MESSAGE_LOOP_CONFIG_MOJO = 1
26 }; 26 };
27 27
28 scoped_ptr<base::MessageLoop> CreateMessageLoop(MessageLoopConfig config) { 28 scoped_ptr<base::MessageLoop> CreateMessageLoop(MessageLoopConfig config) {
29 scoped_ptr<base::MessageLoop> loop; 29 scoped_ptr<base::MessageLoop> loop;
30 if (config == MESSAGE_LOOP_CONFIG_DEFAULT) 30 if (config == MESSAGE_LOOP_CONFIG_DEFAULT)
31 loop.reset(new base::MessageLoop()); 31 loop.reset(new base::MessageLoop());
32 else 32 else
33 loop.reset(new base::MessageLoop(MessagePumpMojo::Create())); 33 loop.reset(new base::MessageLoop(MessagePumpMojo::Create()));
34 return loop.Pass(); 34 return loop;
35 } 35 }
36 36
37 void OnWatcherSignaled(const base::Closure& callback, MojoResult /* result */) { 37 void OnWatcherSignaled(const base::Closure& callback, MojoResult /* result */) {
38 callback.Run(); 38 callback.Run();
39 } 39 }
40 40
41 class ScopedPerfTimer { 41 class ScopedPerfTimer {
42 public: 42 public:
43 ScopedPerfTimer(const std::string& test_name, 43 ScopedPerfTimer(const std::string& test_name,
44 const std::string& sub_test_name, 44 const std::string& sub_test_name,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 struct TestData { 109 struct TestData {
110 MessagePipe pipe; 110 MessagePipe pipe;
111 HandleWatcher watcher; 111 HandleWatcher watcher;
112 }; 112 };
113 ScopedVector<TestData> data_vector; 113 ScopedVector<TestData> data_vector;
114 // Create separately from the start/stop loops to avoid affecting the 114 // Create separately from the start/stop loops to avoid affecting the
115 // benchmark. 115 // benchmark.
116 for (uint64_t i = 0; i < kHandles; i++) { 116 for (uint64_t i = 0; i < kHandles; i++) {
117 scoped_ptr<TestData> test_data(new TestData); 117 scoped_ptr<TestData> test_data(new TestData);
118 ASSERT_TRUE(test_data->pipe.handle0.is_valid()); 118 ASSERT_TRUE(test_data->pipe.handle0.is_valid());
119 data_vector.push_back(test_data.Pass()); 119 data_vector.push_back(std::move(test_data));
120 } 120 }
121 121
122 ScopedPerfTimer timer("StartAllThenStop_1000Handles", GetMessageLoopName(), 122 ScopedPerfTimer timer("StartAllThenStop_1000Handles", GetMessageLoopName(),
123 kIterations * kHandles); 123 kIterations * kHandles);
124 for (uint64_t iter = 0; iter < kIterations; iter++) { 124 for (uint64_t iter = 0; iter < kIterations; iter++) {
125 for (uint64_t i = 0; i < kHandles; i++) { 125 for (uint64_t i = 0; i < kHandles; i++) {
126 TestData* test_data = data_vector[i]; 126 TestData* test_data = data_vector[i];
127 test_data->watcher.Start( 127 test_data->watcher.Start(
128 test_data->pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, 128 test_data->pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE,
129 MOJO_DEADLINE_INDEFINITE, base::Bind(&NeverReached)); 129 MOJO_DEADLINE_INDEFINITE, base::Bind(&NeverReached));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 MessagePipe pipe; 171 MessagePipe pipe;
172 HandleWatcher watcher; 172 HandleWatcher watcher;
173 }; 173 };
174 ScopedVector<TestData> data_vector; 174 ScopedVector<TestData> data_vector;
175 for (uint64_t i = 0; i < kWaitingHandles; i++) { 175 for (uint64_t i = 0; i < kWaitingHandles; i++) {
176 scoped_ptr<TestData> test_data(new TestData); 176 scoped_ptr<TestData> test_data(new TestData);
177 ASSERT_TRUE(test_data->pipe.handle0.is_valid()); 177 ASSERT_TRUE(test_data->pipe.handle0.is_valid());
178 test_data->watcher.Start( 178 test_data->watcher.Start(
179 test_data->pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, 179 test_data->pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE,
180 MOJO_DEADLINE_INDEFINITE, base::Bind(&NeverReached)); 180 MOJO_DEADLINE_INDEFINITE, base::Bind(&NeverReached));
181 data_vector.push_back(test_data.Pass()); 181 data_vector.push_back(std::move(test_data));
182 } 182 }
183 183
184 ScopedPerfTimer timer("StartAndSignal_1000Waiting", GetMessageLoopName(), 184 ScopedPerfTimer timer("StartAndSignal_1000Waiting", GetMessageLoopName(),
185 kIterations); 185 kIterations);
186 for (uint64_t i = 0; i < kIterations; i++) { 186 for (uint64_t i = 0; i < kIterations; i++) {
187 base::RunLoop run_loop; 187 base::RunLoop run_loop;
188 watcher.Start(pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, 188 watcher.Start(pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE,
189 MOJO_DEADLINE_INDEFINITE, 189 MOJO_DEADLINE_INDEFINITE,
190 base::Bind(&OnWatcherSignaled, run_loop.QuitClosure())); 190 base::Bind(&OnWatcherSignaled, run_loop.QuitClosure()));
191 ASSERT_TRUE(mojo::test::WriteTextMessage(pipe.handle1.get(), kMessage)); 191 ASSERT_TRUE(mojo::test::WriteTextMessage(pipe.handle1.get(), kMessage));
192 run_loop.Run(); 192 run_loop.Run();
193 watcher.Stop(); 193 watcher.Stop();
194 194
195 ASSERT_TRUE( 195 ASSERT_TRUE(
196 mojo::test::ReadTextMessage(pipe.handle0.get(), &received_message)); 196 mojo::test::ReadTextMessage(pipe.handle0.get(), &received_message));
197 EXPECT_EQ(kMessage, received_message); 197 EXPECT_EQ(kMessage, received_message);
198 received_message.clear(); 198 received_message.clear();
199 } 199 }
200 } 200 }
201 201
202 } // namespace test 202 } // namespace test
203 } // namespace common 203 } // namespace common
204 } // namespace mojo 204 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/gles2/gles2_impl.cc ('k') | mojo/message_pump/handle_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698