| OLD | NEW |
| 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/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/test/perf_time_logger.h" | 10 #include "base/test/perf_time_logger.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 struct PacPerfTest { | 36 struct PacPerfTest { |
| 37 const char* pac_name; | 37 const char* pac_name; |
| 38 PacQuery queries[100]; | 38 PacQuery queries[100]; |
| 39 | 39 |
| 40 // Returns the actual number of entries in |queries| (assumes NULL sentinel). | 40 // Returns the actual number of entries in |queries| (assumes NULL sentinel). |
| 41 int NumQueries() const; | 41 int NumQueries() const; |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // List of performance tests. | 44 // List of performance tests. |
| 45 static PacPerfTest kPerfTests[] = { | 45 static PacPerfTest kPerfTests[] = { |
| 46 // This test uses an ad-blocker PAC script. This script is very heavily | 46 // This test uses an ad-blocker PAC script. This script is very heavily |
| 47 // regular expression oriented, and has no dependencies on the current | 47 // regular expression oriented, and has no dependencies on the current |
| 48 // IP address, or DNS resolving of hosts. | 48 // IP address, or DNS resolving of hosts. |
| 49 { "no-ads.pac", | 49 { |
| 50 { // queries: | 50 "no-ads.pac", |
| 51 {// queries: |
| 51 {"http://www.google.com", "DIRECT"}, | 52 {"http://www.google.com", "DIRECT"}, |
| 52 {"http://www.imdb.com/photos/cmsicons/x", "PROXY 0.0.0.0:3421"}, | 53 {"http://www.imdb.com/photos/cmsicons/x", "PROXY 0.0.0.0:3421"}, |
| 53 {"http://www.imdb.com/x", "DIRECT"}, | 54 {"http://www.imdb.com/x", "DIRECT"}, |
| 54 {"http://www.staples.com/", "DIRECT"}, | 55 {"http://www.staples.com/", "DIRECT"}, |
| 55 {"http://www.staples.com/pixeltracker/x", "PROXY 0.0.0.0:3421"}, | 56 {"http://www.staples.com/pixeltracker/x", "PROXY 0.0.0.0:3421"}, |
| 56 {"http://www.staples.com/pixel/x", "DIRECT"}, | 57 {"http://www.staples.com/pixel/x", "DIRECT"}, |
| 57 {"http://www.foobar.com", "DIRECT"}, | 58 {"http://www.foobar.com", "DIRECT"}, |
| 58 {"http://www.foobarbaz.com/x/y/z", "DIRECT"}, | 59 {"http://www.foobarbaz.com/x/y/z", "DIRECT"}, |
| 59 {"http://www.testurl1.com/index.html", "DIRECT"}, | 60 {"http://www.testurl1.com/index.html", "DIRECT"}, |
| 60 {"http://www.testurl2.com", "DIRECT"}, | 61 {"http://www.testurl2.com", "DIRECT"}, |
| 61 {"https://www.sample/pirate/arrrrrr", "DIRECT"}, | 62 {"https://www.sample/pirate/arrrrrr", "DIRECT"}, |
| 62 {NULL, NULL} | 63 {NULL, NULL}}, |
| 63 }, | 64 }, |
| 64 }, | |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 int PacPerfTest::NumQueries() const { | 67 int PacPerfTest::NumQueries() const { |
| 68 for (size_t i = 0; i < arraysize(queries); ++i) { | 68 for (size_t i = 0; i < arraysize(queries); ++i) { |
| 69 if (queries[i].query_url == NULL) | 69 if (queries[i].query_url == NULL) |
| 70 return i; | 70 return i; |
| 71 } | 71 } |
| 72 NOTREACHED(); // Bad definition. | 72 NOTREACHED(); // Bad definition. |
| 73 return 0; | 73 return 0; |
| 74 } | 74 } |
| 75 | 75 |
| 76 // The number of URLs to resolve when testing a PAC script. | 76 // The number of URLs to resolve when testing a PAC script. |
| 77 const int kNumIterations = 500; | 77 const int kNumIterations = 500; |
| 78 | 78 |
| 79 // Helper class to run through all the performance tests using the specified | 79 // Helper class to run through all the performance tests using the specified |
| 80 // proxy resolver implementation. | 80 // proxy resolver implementation. |
| 81 class PacPerfSuiteRunner { | 81 class PacPerfSuiteRunner { |
| 82 public: | 82 public: |
| 83 // |resolver_name| is the label used when logging the results. | 83 // |resolver_name| is the label used when logging the results. |
| 84 PacPerfSuiteRunner(net::ProxyResolver* resolver, | 84 PacPerfSuiteRunner(net::ProxyResolver* resolver, |
| 85 const std::string& resolver_name) | 85 const std::string& resolver_name) |
| 86 : resolver_(resolver), | 86 : resolver_(resolver), |
| 87 resolver_name_(resolver_name), | 87 resolver_name_(resolver_name), |
| 88 test_server_( | 88 test_server_(net::SpawnedTestServer::TYPE_HTTP, |
| 89 net::SpawnedTestServer::TYPE_HTTP, | 89 net::SpawnedTestServer::kLocalhost, |
| 90 net::SpawnedTestServer::kLocalhost, | 90 base::FilePath(FILE_PATH_LITERAL( |
| 91 base::FilePath( | 91 "net/data/proxy_resolver_perftest"))) {} |
| 92 FILE_PATH_LITERAL("net/data/proxy_resolver_perftest"))) { | |
| 93 } | |
| 94 | 92 |
| 95 void RunAllTests() { | 93 void RunAllTests() { |
| 96 ASSERT_TRUE(test_server_.Start()); | 94 ASSERT_TRUE(test_server_.Start()); |
| 97 for (size_t i = 0; i < arraysize(kPerfTests); ++i) { | 95 for (size_t i = 0; i < arraysize(kPerfTests); ++i) { |
| 98 const PacPerfTest& test_data = kPerfTests[i]; | 96 const PacPerfTest& test_data = kPerfTests[i]; |
| 99 RunTest(test_data.pac_name, | 97 RunTest(test_data.pac_name, test_data.queries, test_data.NumQueries()); |
| 100 test_data.queries, | |
| 101 test_data.NumQueries()); | |
| 102 } | 98 } |
| 103 } | 99 } |
| 104 | 100 |
| 105 private: | 101 private: |
| 106 void RunTest(const std::string& script_name, | 102 void RunTest(const std::string& script_name, |
| 107 const PacQuery* queries, | 103 const PacQuery* queries, |
| 108 int queries_len) { | 104 int queries_len) { |
| 109 if (!resolver_->expects_pac_bytes()) { | 105 if (!resolver_->expects_pac_bytes()) { |
| 110 GURL pac_url = | 106 GURL pac_url = test_server_.GetURL(std::string("files/") + script_name); |
| 111 test_server_.GetURL(std::string("files/") + script_name); | |
| 112 int rv = resolver_->SetPacScript( | 107 int rv = resolver_->SetPacScript( |
| 113 net::ProxyResolverScriptData::FromURL(pac_url), | 108 net::ProxyResolverScriptData::FromURL(pac_url), |
| 114 net::CompletionCallback()); | 109 net::CompletionCallback()); |
| 115 EXPECT_EQ(net::OK, rv); | 110 EXPECT_EQ(net::OK, rv); |
| 116 } else { | 111 } else { |
| 117 LoadPacScriptIntoResolver(script_name); | 112 LoadPacScriptIntoResolver(script_name); |
| 118 } | 113 } |
| 119 | 114 |
| 120 // Do a query to warm things up. In the case of internal-fetch proxy | 115 // Do a query to warm things up. In the case of internal-fetch proxy |
| 121 // resolvers, the first resolve will be slow since it has to download | 116 // resolvers, the first resolve will be slow since it has to download |
| 122 // the PAC script. | 117 // the PAC script. |
| 123 { | 118 { |
| 124 net::ProxyInfo proxy_info; | 119 net::ProxyInfo proxy_info; |
| 125 int result = resolver_->GetProxyForURL( | 120 int result = resolver_->GetProxyForURL(GURL("http://www.warmup.com"), |
| 126 GURL("http://www.warmup.com"), &proxy_info, net::CompletionCallback(), | 121 &proxy_info, |
| 127 NULL, net::BoundNetLog()); | 122 net::CompletionCallback(), |
| 123 NULL, |
| 124 net::BoundNetLog()); |
| 128 ASSERT_EQ(net::OK, result); | 125 ASSERT_EQ(net::OK, result); |
| 129 } | 126 } |
| 130 | 127 |
| 131 // Start the perf timer. | 128 // Start the perf timer. |
| 132 std::string perf_test_name = resolver_name_ + "_" + script_name; | 129 std::string perf_test_name = resolver_name_ + "_" + script_name; |
| 133 base::PerfTimeLogger timer(perf_test_name.c_str()); | 130 base::PerfTimeLogger timer(perf_test_name.c_str()); |
| 134 | 131 |
| 135 for (int i = 0; i < kNumIterations; ++i) { | 132 for (int i = 0; i < kNumIterations; ++i) { |
| 136 // Round-robin between URLs to resolve. | 133 // Round-robin between URLs to resolve. |
| 137 const PacQuery& query = queries[i % queries_len]; | 134 const PacQuery& query = queries[i % queries_len]; |
| 138 | 135 |
| 139 // Resolve. | 136 // Resolve. |
| 140 net::ProxyInfo proxy_info; | 137 net::ProxyInfo proxy_info; |
| 141 int result = resolver_->GetProxyForURL( | 138 int result = resolver_->GetProxyForURL(GURL(query.query_url), |
| 142 GURL(query.query_url), &proxy_info, net::CompletionCallback(), NULL, | 139 &proxy_info, |
| 143 net::BoundNetLog()); | 140 net::CompletionCallback(), |
| 141 NULL, |
| 142 net::BoundNetLog()); |
| 144 | 143 |
| 145 // Check that the result was correct. Note that ToPacString() and | 144 // Check that the result was correct. Note that ToPacString() and |
| 146 // ASSERT_EQ() are fast, so they won't skew the results. | 145 // ASSERT_EQ() are fast, so they won't skew the results. |
| 147 ASSERT_EQ(net::OK, result); | 146 ASSERT_EQ(net::OK, result); |
| 148 ASSERT_EQ(query.expected_result, proxy_info.ToPacString()); | 147 ASSERT_EQ(query.expected_result, proxy_info.ToPacString()); |
| 149 } | 148 } |
| 150 | 149 |
| 151 // Print how long the test ran for. | 150 // Print how long the test ran for. |
| 152 timer.Done(); | 151 timer.Done(); |
| 153 } | 152 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 net::ProxyResolverMac resolver; | 191 net::ProxyResolverMac resolver; |
| 193 PacPerfSuiteRunner runner(&resolver, "ProxyResolverMac"); | 192 PacPerfSuiteRunner runner(&resolver, "ProxyResolverMac"); |
| 194 runner.RunAllTests(); | 193 runner.RunAllTests(); |
| 195 } | 194 } |
| 196 #endif | 195 #endif |
| 197 | 196 |
| 198 class MockJSBindings : public net::ProxyResolverV8::JSBindings { | 197 class MockJSBindings : public net::ProxyResolverV8::JSBindings { |
| 199 public: | 198 public: |
| 200 MockJSBindings() {} | 199 MockJSBindings() {} |
| 201 | 200 |
| 202 virtual void Alert(const base::string16& message) OVERRIDE { | 201 virtual void Alert(const base::string16& message) OVERRIDE { CHECK(false); } |
| 203 CHECK(false); | |
| 204 } | |
| 205 | 202 |
| 206 virtual bool ResolveDns(const std::string& host, | 203 virtual bool ResolveDns(const std::string& host, |
| 207 ResolveDnsOperation op, | 204 ResolveDnsOperation op, |
| 208 std::string* output, | 205 std::string* output, |
| 209 bool* terminate) OVERRIDE { | 206 bool* terminate) OVERRIDE { |
| 210 CHECK(false); | 207 CHECK(false); |
| 211 return false; | 208 return false; |
| 212 } | 209 } |
| 213 | 210 |
| 214 virtual void OnError(int line_number, | 211 virtual void OnError(int line_number, |
| 215 const base::string16& message) OVERRIDE { | 212 const base::string16& message) OVERRIDE { |
| 216 CHECK(false); | 213 CHECK(false); |
| 217 } | 214 } |
| 218 }; | 215 }; |
| 219 | 216 |
| 220 TEST(ProxyResolverPerfTest, ProxyResolverV8) { | 217 TEST(ProxyResolverPerfTest, ProxyResolverV8) { |
| 221 net::ProxyResolverV8::EnsureIsolateCreated(); | 218 net::ProxyResolverV8::EnsureIsolateCreated(); |
| 222 | 219 |
| 223 MockJSBindings js_bindings; | 220 MockJSBindings js_bindings; |
| 224 net::ProxyResolverV8 resolver; | 221 net::ProxyResolverV8 resolver; |
| 225 resolver.set_js_bindings(&js_bindings); | 222 resolver.set_js_bindings(&js_bindings); |
| 226 PacPerfSuiteRunner runner(&resolver, "ProxyResolverV8"); | 223 PacPerfSuiteRunner runner(&resolver, "ProxyResolverV8"); |
| 227 runner.RunAllTests(); | 224 runner.RunAllTests(); |
| 228 } | 225 } |
| OLD | NEW |