We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / tools / flip_server / loadtime_measurement.h
blobd18ac2f897d47e86a262149078a5df492fc739b5
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
3 // found in the LICENSE file.
5 #ifndef NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_
6 #define NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <stdio.h>
11 #include <sys/types.h>
12 #include <unistd.h>
14 #include <map>
15 #include <string>
16 #include <vector>
18 #include "base/files/file_util.h"
19 #include "base/strings/string_split.h"
21 // Class to handle loadtime measure related urls, which all start with testing
22 // The in memory server has a singleton object of this class. It includes a
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
25 // measure and start with downloading the html file from browser.
26 class LoadtimeMeasurement {
27 public:
28 LoadtimeMeasurement(const std::string& urls_file,
29 const std::string& pageload_html_file)
30 : num_urls_(0), pageload_html_file_(pageload_html_file) {
31 std::string urls_string;
32 base::ReadFileToString(urls_file, &urls_string);
33 base::SplitString(urls_string, '\n', &urls_);
34 num_urls_ = urls_.size();
37 // 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 // of urls in the urls file, get each url, report the loadtime for
40 // each url, and the test is completed.
41 void ProcessRequest(const std::string& uri, std::string& output) {
42 // remove "/testing/" from uri to get the action
43 std::string action = uri.substr(9);
44 if (pageload_html_file_.find(action) != std::string::npos) {
45 base::ReadFileToString(pageload_html_file_, &output);
46 return;
48 if (action.find("get_total_iteration") == 0) {
49 char buffer[16];
50 snprintf(buffer, sizeof(buffer), "%d", num_urls_);
51 output.append(buffer, strlen(buffer));
52 return;
54 if (action.find("geturl") == 0) {
55 size_t b = action.find_first_of('=');
56 if (b != std::string::npos) {
57 int num = atoi(action.substr(b + 1).c_str());
58 if (num < num_urls_) {
59 output.append(urls_[num]);
62 return;
64 if (action.find("test_complete") == 0) {
65 for (std::map<std::string, int>::const_iterator it = loadtimes_.begin();
66 it != loadtimes_.end();
67 ++it) {
68 LOG(INFO) << it->first << " " << it->second;
70 loadtimes_.clear();
71 output.append("OK");
72 return;
74 if (action.find("record_page_load") == 0) {
75 std::vector<std::string> query;
76 base::SplitString(action, '?', &query);
77 std::vector<std::string> params;
78 base::SplitString(query[1], '&', &params);
79 std::vector<std::string> url;
80 std::vector<std::string> loadtime;
81 base::SplitString(params[1], '=', &url);
82 base::SplitString(params[2], '=', &loadtime);
83 loadtimes_[url[1]] = atoi(loadtime[1].c_str());
84 output.append("OK");
85 return;
89 private:
90 int num_urls_;
91 std::vector<std::string> urls_;
92 std::map<std::string, int> loadtimes_;
93 const std::string pageload_html_file_;
96 #endif // NET_TOOLS_FLIP_SERVER_LOADTIME_MEASUREMENT_H_