OLD | NEW |
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 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/stringprintf.h" | |
13 #include "mojo/edk/platform/scoped_platform_handle.h" | 12 #include "mojo/edk/platform/scoped_platform_handle.h" |
14 #include "mojo/edk/system/local_message_pipe_endpoint.h" | 13 #include "mojo/edk/system/local_message_pipe_endpoint.h" |
15 #include "mojo/edk/system/message_pipe.h" | 14 #include "mojo/edk/system/message_pipe.h" |
16 #include "mojo/edk/system/message_pipe_test_utils.h" | 15 #include "mojo/edk/system/message_pipe_test_utils.h" |
17 #include "mojo/edk/system/proxy_message_pipe_endpoint.h" | 16 #include "mojo/edk/system/proxy_message_pipe_endpoint.h" |
18 #include "mojo/edk/system/test/perf_log.h" | 17 #include "mojo/edk/system/test/perf_log.h" |
19 #include "mojo/edk/system/test/stopwatch.h" | 18 #include "mojo/edk/system/test/stopwatch.h" |
20 #include "mojo/edk/test/test_utils.h" | 19 #include "mojo/edk/test/test_utils.h" |
21 #include "mojo/edk/util/ref_ptr.h" | 20 #include "mojo/edk/util/ref_ptr.h" |
| 21 #include "mojo/edk/util/string_printf.h" |
22 #include "mojo/public/cpp/system/macros.h" | 22 #include "mojo/public/cpp/system/macros.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 using mojo::platform::ScopedPlatformHandle; | 25 using mojo::platform::ScopedPlatformHandle; |
26 using mojo::util::RefPtr; | 26 using mojo::util::RefPtr; |
| 27 using mojo::util::StringPrintf; |
27 | 28 |
28 namespace mojo { | 29 namespace mojo { |
29 namespace system { | 30 namespace system { |
30 namespace { | 31 namespace { |
31 | 32 |
32 class MultiprocessMessagePipePerfTest | 33 class MultiprocessMessagePipePerfTest |
33 : public test::MultiprocessMessagePipeTestBase { | 34 : public test::MultiprocessMessagePipeTestBase { |
34 public: | 35 public: |
35 MultiprocessMessagePipePerfTest() : message_count_(0), message_size_(0) {} | 36 MultiprocessMessagePipePerfTest() : message_count_(0), message_size_(0) {} |
36 | 37 |
(...skipping 24 matching lines...) Expand all Loading... |
61 void SendQuitMessage(MessagePipe* mp) { | 62 void SendQuitMessage(MessagePipe* mp) { |
62 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(""), 0, nullptr, | 63 CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(""), 0, nullptr, |
63 MOJO_WRITE_MESSAGE_FLAG_NONE), | 64 MOJO_WRITE_MESSAGE_FLAG_NONE), |
64 MOJO_RESULT_OK); | 65 MOJO_RESULT_OK); |
65 } | 66 } |
66 | 67 |
67 void Measure(MessagePipe* mp) { | 68 void Measure(MessagePipe* mp) { |
68 // Have one ping-pong to ensure channel being established. | 69 // Have one ping-pong to ensure channel being established. |
69 WriteWaitThenRead(mp); | 70 WriteWaitThenRead(mp); |
70 | 71 |
71 std::string test_name = | 72 std::string test_name = StringPrintf("IPC_Perf_%dx_%u", message_count_, |
72 base::StringPrintf("IPC_Perf_%dx_%u", message_count_, | 73 static_cast<unsigned>(message_size_)); |
73 static_cast<unsigned>(message_size_)); | |
74 test::Stopwatch stopwatch; | 74 test::Stopwatch stopwatch; |
75 | 75 |
76 stopwatch.Start(); | 76 stopwatch.Start(); |
77 for (int i = 0; i < message_count_; ++i) | 77 for (int i = 0; i < message_count_; ++i) |
78 WriteWaitThenRead(mp); | 78 WriteWaitThenRead(mp); |
79 test::LogPerfResult(test_name.c_str(), stopwatch.Elapsed() / 1000.0, "ms"); | 79 test::LogPerfResult(test_name.c_str(), stopwatch.Elapsed() / 1000.0, "ms"); |
80 } | 80 } |
81 | 81 |
82 private: | 82 private: |
83 int message_count_; | 83 int message_count_; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 SendQuitMessage(mp.get()); | 162 SendQuitMessage(mp.get()); |
163 mp->Close(0); | 163 mp->Close(0); |
164 EXPECT_EQ(0, helper()->WaitForChildShutdown()); | 164 EXPECT_EQ(0, helper()->WaitForChildShutdown()); |
165 } | 165 } |
166 | 166 |
167 } // namespace | 167 } // namespace |
168 } // namespace system | 168 } // namespace system |
169 } // namespace mojo | 169 } // namespace mojo |
OLD | NEW |