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

Side by Side Diff: net/tools/flip_server/loadtime_measurement.h

Issue 93793004: Format and Refactor Flip Server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years 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
« no previous file with comments | « net/tools/flip_server/http_message_constants.cc ('k') | net/tools/flip_server/mem_cache.h » ('j') | 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) 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 26 matching lines...) Expand all
37 // each url, and the test is completed. 37 // each url, and the test is completed.
38 void ProcessRequest(const std::string& uri, std::string& output) { 38 void ProcessRequest(const std::string& uri, std::string& output) {
39 // remove "/testing/" from uri to get the action 39 // remove "/testing/" from uri to get the action
40 std::string action = uri.substr(9); 40 std::string action = uri.substr(9);
41 if (pageload_html_file_.find(action) != std::string::npos) { 41 if (pageload_html_file_.find(action) != std::string::npos) {
42 read_file_to_string(pageload_html_file_.c_str(), &output); 42 read_file_to_string(pageload_html_file_.c_str(), &output);
43 return; 43 return;
44 } 44 }
45 if (action.find("get_total_iteration") == 0) { 45 if (action.find("get_total_iteration") == 0) {
46 char buffer[16]; 46 char buffer[16];
47 snprintf(buffer, 16, "%d", num_urls_); 47 snprintf(buffer, sizeof(buffer), "%d", num_urls_);
48 output.append(buffer, strlen(buffer)); 48 output.append(buffer, strlen(buffer));
49 return; 49 return;
50 } 50 }
51 if (action.find("geturl") == 0) { 51 if (action.find("geturl") == 0) {
52 size_t b = action.find_first_of('='); 52 size_t b = action.find_first_of('=');
53 if (b != std::string::npos) { 53 if (b != std::string::npos) {
54 int num = atoi(action.substr(b + 1).c_str()); 54 int num = atoi(action.substr(b + 1).c_str());
55 if (num < num_urls_) { 55 if (num < num_urls_) {
56 output.append(urls_[num]); 56 output.append(urls_[num]);
57 } 57 }
58 } 58 }
59 return; 59 return;
60 } 60 }
61 if (action.find("test_complete") == 0) { 61 if (action.find("test_complete") == 0) {
62 for (std::map<std::string, int>::const_iterator it = loadtimes_.begin(); 62 for (std::map<std::string, int>::const_iterator it = loadtimes_.begin();
63 it != loadtimes_.end(); ++it) { 63 it != loadtimes_.end();
64 ++it) {
64 LOG(INFO) << it->first << " " << it->second; 65 LOG(INFO) << it->first << " " << it->second;
65 } 66 }
66 loadtimes_.clear(); 67 loadtimes_.clear();
67 output.append("OK"); 68 output.append("OK");
68 return; 69 return;
69 } 70 }
70 if (action.find("record_page_load") == 0) { 71 if (action.find("record_page_load") == 0) {
71 std::vector<std::string> query; 72 std::vector<std::string> query;
72 split_string(action, '?', &query); 73 split_string(action, '?', &query);
73 std::vector<std::string> params; 74 std::vector<std::string> params;
(...skipping 18 matching lines...) Expand all
92 ssize_t read_status = read(fd, buffer, sizeof(buffer)); 93 ssize_t read_status = read(fd, buffer, sizeof(buffer));
93 while (read_status > 0) { 94 while (read_status > 0) {
94 output->append(buffer, static_cast<size_t>(read_status)); 95 output->append(buffer, static_cast<size_t>(read_status));
95 do { 96 do {
96 read_status = read(fd, buffer, sizeof(buffer)); 97 read_status = read(fd, buffer, sizeof(buffer));
97 } while (read_status <= 0 && errno == EINTR); 98 } while (read_status <= 0 && errno == EINTR);
98 } 99 }
99 close(fd); 100 close(fd);
100 } 101 }
101 102
102 void split_string(std::string& str, char sepa, 103 void split_string(const std::string& str,
104 char sepa,
103 std::vector<std::string>* sub_strs) { 105 std::vector<std::string>* sub_strs) {
104 size_t b = 0; 106 size_t b = 0;
105 size_t e = str.find_first_of(sepa, b); 107 size_t e = str.find_first_of(sepa, b);
106 while (e != std::string::npos && e > b) { 108 while (e != std::string::npos && e > b) {
107 sub_strs->push_back(str.substr(b, e - b)); 109 sub_strs->push_back(str.substr(b, e - b));
108 b = e + 1; 110 b = e + 1;
109 e = str.find_first_of(sepa, b); 111 e = str.find_first_of(sepa, b);
110 } 112 }
111 if (b < str.size()) { 113 if (b < str.size()) {
112 sub_strs->push_back(str.substr(b)); 114 sub_strs->push_back(str.substr(b));
113 } 115 }
114 } 116 }
115 117
116 int num_urls_; 118 int num_urls_;
117 std::vector<std::string> urls_; 119 std::vector<std::string> urls_;
118 std::map<std::string, int> loadtimes_; 120 std::map<std::string, int> loadtimes_;
119 const std::string pageload_html_file_; 121 const std::string pageload_html_file_;
120 }; 122 };
121 123
122 #endif // NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H__ 124 #endif // NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H__
123
OLDNEW
« no previous file with comments | « net/tools/flip_server/http_message_constants.cc ('k') | net/tools/flip_server/mem_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698