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

Side by Side Diff: ppapi/proxy/ppp_messaging_proxy_perftest.cc

Issue 453003002: PPAPI: Revive ppp_messaging_proxy_perftest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/string_number_conversions.h"
7 #include "base/test/perf_time_logger.h" 7 #include "base/test/perf_time_logger.h"
8 #include "ppapi/c/ppp_messaging.h" 8 #include "ppapi/c/ppp_messaging.h"
9 #include "ppapi/proxy/ppapi_messages.h"
9 #include "ppapi/proxy/ppapi_proxy_test.h" 10 #include "ppapi/proxy/ppapi_proxy_test.h"
10 #include "ppapi/proxy/serialized_var.h" 11 #include "ppapi/proxy/serialized_var.h"
11 #include "ppapi/shared_impl/ppapi_globals.h" 12 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/proxy_lock.h"
12 #include "ppapi/shared_impl/var.h" 14 #include "ppapi/shared_impl/var.h"
13 #include "ppapi/shared_impl/var_tracker.h" 15 #include "ppapi/shared_impl/var_tracker.h"
14 16
15 namespace ppapi { 17 namespace ppapi {
16 namespace proxy { 18 namespace proxy {
17 namespace { 19 namespace {
18 20
19 base::WaitableEvent handle_message_called(false, false); 21 base::WaitableEvent handle_message_called(false, false);
20 22
21 void HandleMessage(PP_Instance /* instance */, PP_Var message_data) { 23 void HandleMessage(PP_Instance /* instance */, PP_Var message_data) {
24 ppapi::ProxyAutoLock lock;
22 StringVar* string_var = StringVar::FromPPVar(message_data); 25 StringVar* string_var = StringVar::FromPPVar(message_data);
23 DCHECK(string_var); 26 DCHECK(string_var);
24 // Retrieve the string to make sure the proxy can't "optimize away" sending 27 // Retrieve the string to make sure the proxy can't "optimize away" sending
25 // the actual contents of the string (e.g., by doing a lazy retrieve or 28 // the actual contents of the string (e.g., by doing a lazy retrieve or
26 // something). Note that this test is for performance only, and assumes 29 // something). Note that this test is for performance only, and assumes
27 // other tests check for correctness. 30 // other tests check for correctness.
28 std::string s = string_var->value(); 31 std::string s = string_var->value();
29 // Do something simple with the string so the compiler won't complain. 32 // Do something simple with the string so the compiler won't complain.
30 if (s.length() > 0) 33 if (s.length() > 0)
31 s[0] = 'a'; 34 s[0] = 'a';
(...skipping 10 matching lines...) Expand all
42 PppMessagingPerfTest() : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { 45 PppMessagingPerfTest() : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) {
43 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, 46 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE,
44 &ppp_messaging_mock); 47 &ppp_messaging_mock);
45 } 48 }
46 }; 49 };
47 50
48 } // namespace 51 } // namespace
49 52
50 // Tests the performance of sending strings through the proxy. 53 // Tests the performance of sending strings through the proxy.
51 TEST_F(PppMessagingPerfTest, StringPerformance) { 54 TEST_F(PppMessagingPerfTest, StringPerformance) {
52 // Grab the host-side proxy of ppp_messaging.
53 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>(
54 host().host_dispatcher()->GetProxiedInterface(
55 PPP_MESSAGING_INTERFACE));
56 const PP_Instance kTestInstance = pp_instance(); 55 const PP_Instance kTestInstance = pp_instance();
57 int seed = 123; 56 int seed = 123;
58 int string_count = 1000; 57 int string_count = 1000;
59 int max_string_size = 1000000; 58 int max_string_size = 1000000;
60 CommandLine* command_line = CommandLine::ForCurrentProcess(); 59 CommandLine* command_line = CommandLine::ForCurrentProcess();
61 if (command_line) { 60 if (command_line) {
62 if (command_line->HasSwitch("seed")) { 61 if (command_line->HasSwitch("seed")) {
63 base::StringToInt(command_line->GetSwitchValueASCII("seed"), 62 base::StringToInt(command_line->GetSwitchValueASCII("seed"),
64 &seed); 63 &seed);
65 } 64 }
66 if (command_line->HasSwitch("string_count")) { 65 if (command_line->HasSwitch("string_count")) {
67 base::StringToInt(command_line->GetSwitchValueASCII("string_count"), 66 base::StringToInt(command_line->GetSwitchValueASCII("string_count"),
68 &string_count); 67 &string_count);
69 } 68 }
70 if (command_line->HasSwitch("max_string_size")) { 69 if (command_line->HasSwitch("max_string_size")) {
71 base::StringToInt(command_line->GetSwitchValueASCII("max_string_size"), 70 base::StringToInt(command_line->GetSwitchValueASCII("max_string_size"),
72 &max_string_size); 71 &max_string_size);
73 } 72 }
74 } 73 }
75 srand(seed); 74 srand(seed);
76 base::PerfTimeLogger logger("PppMessagingPerfTest.StringPerformance"); 75 base::PerfTimeLogger logger("PppMessagingPerfTest.StringPerformance");
77 for (int i = 0; i < string_count; ++i) { 76 for (int i = 0; i < string_count; ++i) {
78 const std::string test_string(rand() % max_string_size, 'a'); 77 const std::string test_string(rand() % max_string_size, 'a');
79 PP_Var host_string = StringVar::StringToPPVar(test_string); 78 PP_Var host_string = StringVar::StringToPPVar(test_string);
80 ppp_messaging->HandleMessage(kTestInstance, host_string); 79 // We don't have a host-side PPP_Messaging interface; just send the message
80 // directly like the proxy does.
81 host().host_dispatcher()->Send(new PpapiMsg_PPPMessaging_HandleMessage(
82 ppapi::API_ID_PPP_MESSAGING,
83 kTestInstance,
84 ppapi::proxy::SerializedVarSendInput(host().host_dispatcher(),
85 host_string)));
81 handle_message_called.Wait(); 86 handle_message_called.Wait();
82 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(host_string); 87 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(host_string);
83 } 88 }
84 } 89 }
85 90
86 } // namespace proxy 91 } // namespace proxy
87 } // namespace ppapi 92 } // namespace ppapi
88 93
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698