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

Side by Side Diff: mojo/edk/system/message_pipe_perftest.cc

Issue 728553002: Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stdint.h> 5 #include <stdint.h>
6 #include <stdio.h> 6 #include <stdio.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 29 matching lines...) Expand all
40 void SetUpMeasurement(int message_count, size_t message_size) { 40 void SetUpMeasurement(int message_count, size_t message_size) {
41 message_count_ = message_count; 41 message_count_ = message_count;
42 message_size_ = message_size; 42 message_size_ = message_size;
43 payload_ = Pickle(); 43 payload_ = Pickle();
44 payload_.WriteString(std::string(message_size, '*')); 44 payload_.WriteString(std::string(message_size, '*'));
45 read_buffer_.resize(message_size * 2); 45 read_buffer_.resize(message_size * 2);
46 } 46 }
47 47
48 protected: 48 protected:
49 void WriteWaitThenRead(scoped_refptr<MessagePipe> mp) { 49 void WriteWaitThenRead(scoped_refptr<MessagePipe> mp) {
50 CHECK_EQ(mp->WriteMessage(0, 50 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(payload_.data()),
51 UserPointer<const void>(payload_.data()), 51 static_cast<uint32_t>(payload_.size()), nullptr,
52 static_cast<uint32_t>(payload_.size()),
53 nullptr,
54 MOJO_WRITE_MESSAGE_FLAG_NONE), 52 MOJO_WRITE_MESSAGE_FLAG_NONE),
55 MOJO_RESULT_OK); 53 MOJO_RESULT_OK);
56 HandleSignalsState hss; 54 HandleSignalsState hss;
57 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss), 55 CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
58 MOJO_RESULT_OK); 56 MOJO_RESULT_OK);
59 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer_.size()); 57 uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer_.size());
60 CHECK_EQ(mp->ReadMessage(0, 58 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer_[0]),
61 UserPointer<void>(&read_buffer_[0]), 59 MakeUserPointer(&read_buffer_size), nullptr,
62 MakeUserPointer(&read_buffer_size), 60 nullptr, MOJO_READ_MESSAGE_FLAG_NONE),
63 nullptr,
64 nullptr,
65 MOJO_READ_MESSAGE_FLAG_NONE),
66 MOJO_RESULT_OK); 61 MOJO_RESULT_OK);
67 CHECK_EQ(read_buffer_size, static_cast<uint32_t>(payload_.size())); 62 CHECK_EQ(read_buffer_size, static_cast<uint32_t>(payload_.size()));
68 } 63 }
69 64
70 void SendQuitMessage(scoped_refptr<MessagePipe> mp) { 65 void SendQuitMessage(scoped_refptr<MessagePipe> mp) {
71 CHECK_EQ(mp->WriteMessage(0, 66 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(""), 0, nullptr,
72 UserPointer<const void>(""),
73 0,
74 nullptr,
75 MOJO_WRITE_MESSAGE_FLAG_NONE), 67 MOJO_WRITE_MESSAGE_FLAG_NONE),
76 MOJO_RESULT_OK); 68 MOJO_RESULT_OK);
77 } 69 }
78 70
79 void Measure(scoped_refptr<MessagePipe> mp) { 71 void Measure(scoped_refptr<MessagePipe> mp) {
80 // Have one ping-pong to ensure channel being established. 72 // Have one ping-pong to ensure channel being established.
81 WriteWaitThenRead(mp); 73 WriteWaitThenRead(mp);
82 74
83 std::string test_name = 75 std::string test_name =
84 base::StringPrintf("IPC_Perf_%dx_%u", 76 base::StringPrintf("IPC_Perf_%dx_%u", message_count_,
85 message_count_,
86 static_cast<unsigned>(message_size_)); 77 static_cast<unsigned>(message_size_));
87 base::PerfTimeLogger logger(test_name.c_str()); 78 base::PerfTimeLogger logger(test_name.c_str());
88 79
89 for (int i = 0; i < message_count_; ++i) 80 for (int i = 0; i < message_count_; ++i)
90 WriteWaitThenRead(mp); 81 WriteWaitThenRead(mp);
91 82
92 logger.Done(); 83 logger.Done();
93 } 84 }
94 85
95 private: 86 private:
(...skipping 24 matching lines...) Expand all
120 // Wait for our end of the message pipe to be readable. 111 // Wait for our end of the message pipe to be readable.
121 HandleSignalsState hss; 112 HandleSignalsState hss;
122 MojoResult result = 113 MojoResult result =
123 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss); 114 test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss);
124 if (result != MOJO_RESULT_OK) { 115 if (result != MOJO_RESULT_OK) {
125 rv = result; 116 rv = result;
126 break; 117 break;
127 } 118 }
128 119
129 uint32_t read_size = static_cast<uint32_t>(buffer.size()); 120 uint32_t read_size = static_cast<uint32_t>(buffer.size());
130 CHECK_EQ(mp->ReadMessage(0, 121 CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&buffer[0]),
131 UserPointer<void>(&buffer[0]), 122 MakeUserPointer(&read_size), nullptr, nullptr,
132 MakeUserPointer(&read_size),
133 nullptr,
134 nullptr,
135 MOJO_READ_MESSAGE_FLAG_NONE), 123 MOJO_READ_MESSAGE_FLAG_NONE),
136 MOJO_RESULT_OK); 124 MOJO_RESULT_OK);
137 125
138 // Empty message indicates quitting 126 // Empty message indicates quitting
139 if (0 == read_size) 127 if (0 == read_size)
140 break; 128 break;
141 129
142 CHECK_EQ(mp->WriteMessage(0, 130 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(&buffer[0]),
143 UserPointer<const void>(&buffer[0]), 131 static_cast<uint32_t>(read_size), nullptr,
144 static_cast<uint32_t>(read_size),
145 nullptr,
146 MOJO_WRITE_MESSAGE_FLAG_NONE), 132 MOJO_WRITE_MESSAGE_FLAG_NONE),
147 MOJO_RESULT_OK); 133 MOJO_RESULT_OK);
148 } 134 }
149 135
150 mp->Close(0); 136 mp->Close(0);
151 return rv; 137 return rv;
152 } 138 }
153 139
154 // Repeatedly sends messages as previous one got replied by the child. 140 // Repeatedly sends messages as previous one got replied by the child.
155 // Waits for the child to close its end before quitting once specified 141 // Waits for the child to close its end before quitting once specified
(...skipping 15 matching lines...) Expand all
171 } 157 }
172 158
173 SendQuitMessage(mp); 159 SendQuitMessage(mp);
174 mp->Close(0); 160 mp->Close(0);
175 EXPECT_EQ(0, helper()->WaitForChildShutdown()); 161 EXPECT_EQ(0, helper()->WaitForChildShutdown());
176 } 162 }
177 163
178 } // namespace 164 } // namespace
179 } // namespace system 165 } // namespace system
180 } // namespace mojo 166 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher_unittest.cc ('k') | mojo/edk/system/message_pipe_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698