Add Net.WebSocket.ResponseCode and ErrorCodes UMA
Add histograms to record the response codes seen by all WebSocket
requests, and also the error codes. This will provide more insight into the
reasons for WebSocket connection failures.
BUG=384273
TEST=manually tested with chrome://histograms
Review URL: https://codereview.chromium.org/336753002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278339 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/websockets/websocket_basic_handshake_stream.cc b/net/websockets/websocket_basic_handshake_stream.cc
index a4a634e..a51fee2 100644
--- a/net/websockets/websocket_basic_handshake_stream.cc
+++ b/net/websockets/websocket_basic_handshake_stream.cc
@@ -15,6 +15,7 @@
#include "base/bind.h"
#include "base/containers/hash_tables.h"
#include "base/metrics/histogram.h"
+#include "base/metrics/sparse_histogram.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
@@ -552,9 +553,14 @@
int WebSocketBasicHandshakeStream::ValidateResponse(int rv) {
DCHECK(http_response_info_);
- const HttpResponseHeaders* headers = http_response_info_->headers.get();
+ // Most net errors happen during connection, so they are not seen by this
+ // method. The histogram for error codes is created in
+ // Delegate::OnResponseStarted in websocket_stream.cc instead.
if (rv >= 0) {
- switch (headers->response_code()) {
+ const HttpResponseHeaders* headers = http_response_info_->headers.get();
+ const int response_code = headers->response_code();
+ UMA_HISTOGRAM_SPARSE_SLOWLY("Net.WebSocket.ResponseCode", response_code);
+ switch (response_code) {
case HTTP_SWITCHING_PROTOCOLS:
OnFinishOpeningHandshake();
return ValidateUpgradeResponse(headers);