Commit 82aed06f authored by gavinp@chromium.org's avatar gavinp@chromium.org

Add histogram for HTTP response codes

This adds an histogram to the HTTP response header parser.  I reviewed
the code, and I've convinced myself that this captures the two main
cases of HTTP header parsing (tunneling, and normal HTTP), and that
double-calls aren't occuring.  I liked having all the code in the one
translation unit.  But, I might have missed one, and we might still
be getting called twice for the same load: so the statistics might be off.

Alternatively, I could put a static function on HttpResponseHeader, to
be called from the site of parse.  But this might miss a parse.

All in all, I wanted to be sure to catch all distinct response codes
we get, so we can be sure not to stomp on anything.  So I chose the
approach using the HttpResponseHeaders constructor.

TEST=none
BUG=70428

Review URL: http://codereview.chromium.org/6317011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72801 0039d316-1c4b-4281-b951-d872f2087c98
parent 665acb17
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <algorithm> #include <algorithm>
#include "base/logging.h" #include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/string_util.h" #include "base/string_util.h"
...@@ -85,6 +86,34 @@ bool ShouldUpdateHeader(const std::string::const_iterator& name_begin, ...@@ -85,6 +86,34 @@ bool ShouldUpdateHeader(const std::string::const_iterator& name_begin,
return true; return true;
} }
// Functions for histogram initialization. The code 0 is put in the
// response map to track response codes that are invalid.
// TODO(gavinp): Greatly prune the collected codes once we learn which
// ones are not sent in practice, to reduce upload size & memory use.
enum {
HISTOGRAM_MIN_HTTP_RESPONSE_CODE = 100,
HISTOGRAM_MAX_HTTP_RESPONSE_CODE = 599,
};
std::vector<int> GetAllHttpResponseCodes() {
std::vector<int> codes;
codes.reserve(
HISTOGRAM_MAX_HTTP_RESPONSE_CODE - HISTOGRAM_MIN_HTTP_RESPONSE_CODE + 2);
codes.push_back(0);
for (int i = HISTOGRAM_MIN_HTTP_RESPONSE_CODE;
i <= HISTOGRAM_MAX_HTTP_RESPONSE_CODE; ++i)
codes.push_back(i);
return codes;
}
int MapHttpResponseCode(int code) {
if (HISTOGRAM_MIN_HTTP_RESPONSE_CODE <= code &&
code <= HISTOGRAM_MAX_HTTP_RESPONSE_CODE)
return code;
return 0;
}
} // namespace } // namespace
struct HttpResponseHeaders::ParsedHeader { struct HttpResponseHeaders::ParsedHeader {
...@@ -103,6 +132,23 @@ struct HttpResponseHeaders::ParsedHeader { ...@@ -103,6 +132,23 @@ struct HttpResponseHeaders::ParsedHeader {
HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input) HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input)
: response_code_(-1) { : response_code_(-1) {
Parse(raw_input); Parse(raw_input);
// The most important thing to do with this histogram is find out
// the existence of unusual HTTP response codes. As it happens
// right now, there aren't double-constructions of response headers
// using this constructor, so our counts should also be accurate,
// without instantiating the histogram in two places. It is also
// important that this histogram not collect data in the other
// constructor, which rebuilds an histogram from a pickle, since
// that would actually create a double call between the original
// HttpResponseHeader that was serialized, and initialization of the
// new object from that pickle.
UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.HttpResponseCode",
MapHttpResponseCode(response_code_),
// Note the third argument is only
// evaluated once, see macro
// definition for details.
GetAllHttpResponseCodes());
} }
HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter) HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment