| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_ | 5 #ifndef NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_ |
| 6 #define NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_ | 6 #define NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_ |
| 7 | 7 |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <fcntl.h> | 9 #include <fcntl.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // html file containing javascript to go through a list of urls and upload the | 23 // html file containing javascript to go through a list of urls and upload the |
| 24 // loadtime. The users can modify urls.txt to define the urls they want to | 24 // loadtime. The users can modify urls.txt to define the urls they want to |
| 25 // measure and start with downloading the html file from browser. | 25 // measure and start with downloading the html file from browser. |
| 26 class LoadtimeMeasurement { | 26 class LoadtimeMeasurement { |
| 27 public: | 27 public: |
| 28 LoadtimeMeasurement(const std::string& urls_file, | 28 LoadtimeMeasurement(const std::string& urls_file, |
| 29 const std::string& pageload_html_file) | 29 const std::string& pageload_html_file) |
| 30 : num_urls_(0), pageload_html_file_(pageload_html_file) { | 30 : num_urls_(0), pageload_html_file_(pageload_html_file) { |
| 31 std::string urls_string; | 31 std::string urls_string; |
| 32 base::ReadFileToString(urls_file, &urls_string); | 32 base::ReadFileToString(urls_file, &urls_string); |
| 33 base::SplitString(urls_string, '\n', &urls_); | 33 urls_ = base::SplitString(urls_string, "\n", base::TRIM_WHITESPACE, |
| 34 base::SPLIT_WANT_ALL); |
| 34 num_urls_ = urls_.size(); | 35 num_urls_ = urls_.size(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 // This is the entry function for all the loadtime measure related urls | 38 // This is the entry function for all the loadtime measure related urls |
| 38 // It handles the request to html file, get_total_iteration to get number | 39 // It handles the request to html file, get_total_iteration to get number |
| 39 // of urls in the urls file, get each url, report the loadtime for | 40 // of urls in the urls file, get each url, report the loadtime for |
| 40 // each url, and the test is completed. | 41 // each url, and the test is completed. |
| 41 void ProcessRequest(const std::string& uri, std::string& output) { | 42 void ProcessRequest(const std::string& uri, std::string& output) { |
| 42 // remove "/testing/" from uri to get the action | 43 // remove "/testing/" from uri to get the action |
| 43 std::string action = uri.substr(9); | 44 std::string action = uri.substr(9); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 for (std::map<std::string, int>::const_iterator it = loadtimes_.begin(); | 66 for (std::map<std::string, int>::const_iterator it = loadtimes_.begin(); |
| 66 it != loadtimes_.end(); | 67 it != loadtimes_.end(); |
| 67 ++it) { | 68 ++it) { |
| 68 LOG(INFO) << it->first << " " << it->second; | 69 LOG(INFO) << it->first << " " << it->second; |
| 69 } | 70 } |
| 70 loadtimes_.clear(); | 71 loadtimes_.clear(); |
| 71 output.append("OK"); | 72 output.append("OK"); |
| 72 return; | 73 return; |
| 73 } | 74 } |
| 74 if (action.find("record_page_load") == 0) { | 75 if (action.find("record_page_load") == 0) { |
| 75 std::vector<std::string> query; | 76 std::vector<std::string> query = base::SplitString( |
| 76 base::SplitString(action, '?', &query); | 77 action, "?", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 77 std::vector<std::string> params; | 78 std::vector<std::string> params = base::SplitString( |
| 78 base::SplitString(query[1], '&', ¶ms); | 79 query[1], "&", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 79 std::vector<std::string> url; | 80 std::vector<std::string> url = base::SplitString( |
| 80 std::vector<std::string> loadtime; | 81 params[1], "=", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 81 base::SplitString(params[1], '=', &url); | 82 std::vector<std::string> loadtime = base::SplitString( |
| 82 base::SplitString(params[2], '=', &loadtime); | 83 params[2], "=", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 83 loadtimes_[url[1]] = atoi(loadtime[1].c_str()); | 84 loadtimes_[url[1]] = atoi(loadtime[1].c_str()); |
| 84 output.append("OK"); | 85 output.append("OK"); |
| 85 return; | 86 return; |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 | 89 |
| 89 private: | 90 private: |
| 90 int num_urls_; | 91 int num_urls_; |
| 91 std::vector<std::string> urls_; | 92 std::vector<std::string> urls_; |
| 92 std::map<std::string, int> loadtimes_; | 93 std::map<std::string, int> loadtimes_; |
| 93 const std::string pageload_html_file_; | 94 const std::string pageload_html_file_; |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 #endif // NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_ | 97 #endif // NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_ |
| OLD | NEW |