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

Unified Diff: net/http/http_response_headers.cc

Issue 6317011: Add histogram for HTTP response codes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remediation to review Created 9 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index 85df8d5e15f3c390a663dfad6eecb6857564ee59..674359927efffa66e405feb56ee0ae2c09a2516e 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -12,6 +12,7 @@
#include <algorithm>
#include "base/logging.h"
+#include "base/metrics/histogram.h"
#include "base/pickle.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h"
@@ -85,6 +86,32 @@ bool ShouldUpdateHeader(const std::string::const_iterator& name_begin,
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
+// ares are not sent in practice, to reduce upload size & memory use.
+
+enum { kHistogramMinHttpResponseCode = 100,
+ kHistogramMaxHttpResponseCode = 599 };
wtc 2011/01/25 18:38:00 This should be formatted as enum { kHistogram
gavinp 2011/01/26 01:42:45 Done.
+
+std::vector<int> GetAllHttpResponseCodes() {
+ std::vector<int> codes;
+ codes.reserve(
+ kHistogramMaxHttpResponseCode - kHistogramMinHttpResponseCode + 2);
+ codes.push_back(0);
+ for (int i = kHistogramMinHttpResponseCode;
+ i <= kHistogramMaxHttpResponseCode;++i)
wtc 2011/01/25 18:38:00 Document what the 0 status code added on line 101
gavinp 2011/01/26 01:42:45 Done.
gavinp 2011/01/26 01:42:45 Done.
+ codes.push_back(i);
+ return codes;
+}
+
+int MapHttpResponseCode(const int code) {
wtc 2011/01/25 18:38:00 Nit: remove the 'const' from the function paramete
gavinp 2011/01/26 01:42:45 Done.
+ if (kHistogramMinHttpResponseCode <= code &&
+ code <= kHistogramMaxHttpResponseCode)
+ return code;
+ return 0;
+}
+
} // namespace
struct HttpResponseHeaders::ParsedHeader {
@@ -103,6 +130,15 @@ struct HttpResponseHeaders::ParsedHeader {
HttpResponseHeaders::HttpResponseHeaders(const std::string& raw_input)
: response_code_(-1) {
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.
+ UMA_HISTOGRAM_CUSTOM_ENUMERATION("Net.HttpResponseCode",
+ MapHttpResponseCode(response_code_),
+ GetAllHttpResponseCodes());
wtc 2011/01/25 18:38:00 It is wasteful to build the std::vector<int> of co
gavinp 2011/01/26 01:42:45 Added a comment documenting that this is not what'
}
HttpResponseHeaders::HttpResponseHeaders(const Pickle& pickle, void** iter)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698