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

Unified Diff: chrome/browser/net/network_stats.h

Issue 7056031: Collect stats to investigate the viability of UDP (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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
Index: chrome/browser/net/network_stats.h
===================================================================
--- chrome/browser/net/network_stats.h (revision 0)
+++ chrome/browser/net/network_stats.h (revision 0)
@@ -0,0 +1,170 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NET_NETWORK_STATS_H_
+#define CHROME_BROWSER_NET_NETWORK_STATS_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/scoped_ptr.h"
+#include "base/time.h"
+#include "net/base/completion_callback.h"
+#include "net/base/host_port_pair.h"
+#include "net/base/io_buffer.h"
+#include "net/base/ip_endpoint.h"
+#include "net/base/test_data_stream.h"
+#include "net/socket/socket.h"
+
+namespace chrome_browser_net {
+
+// This class is used for live experiment of network connectivity (either TCP or
+// UDP) metrics. A small percentage of users participate in this experiment. All
+// users (who are in the experiment) must have enabled "UMA upload".
+//
+// This class collects the following stats from users who have opted in.
+// a) What percentage of users can get a message end-to-end to a UDP server?
+// b) What percentage of users can get a message end-to-end to a TCP server?
+// c) What is the latency for UDP and TCP.
+// d) If connectivity failed, at what stage (Connect or Write or Read) did it
+// fail?
+
+class NetworkStats : public base::RefCounted<NetworkStats> {
+ public:
+ enum Status { // Used in HISTOGRAM_ENUMERATION.
+ SUCCESS, // Successfully received bytes from the server.
+ IP_STRING_PARSE_FAIL, // Parsing of IP string failed.
+ RESOLVE_FAIL, // Host resolution failed.
+ CONNECT_FAIL, // Connection to the server failed.
+ WRITE_FAIL, // Sending an echo message to the server failed.
+ READ_FAIL, // Reading the reply from the server failed.
+ READ_VERIFY_FAIL, // Verification of data failed.
+ STATUS_MAX, // Bounding value.
+ };
+
+ // Constructs an NetworkStats object that collects metrics for network
+ // connectivity (either TCP or UDP).
+ NetworkStats();
+ virtual ~NetworkStats();
+
+ // Returns the number of errors this server encountered.
+ int error_count() { return errors_; }
+
+ protected:
+ static const int kMaxMessage = 1024;
+
+ // Callbacks when an internal IO is completed.
+ virtual void OnReadComplete(int result);
+ virtual void OnWriteComplete(int result);
+
+ // Reads data from server until an error occurs.
+ virtual void ReadData();
+
+ // Sends data to server until an error occurs.
+ virtual void SendData();
+
+ // Collects network connectivity stats. This is called when all the data from
+ // server is read or when there is a failure during connect/read/write.
+ virtual void Finish(Status status, int result) {}
+
+ // The socket handle for this session.
+ net::Socket* socket_;
+
+ // The read buffer used to read data from the socket.
+ scoped_refptr<net::IOBuffer> read_buffer_;
+
+ // The write buffer used to write data to the socket.
+ scoped_refptr<net::DrainableIOBuffer> write_buffer_;
+
+ // Some counters for the session.
+ int errors_;
+ int bytes_to_read_;
+ int bytes_to_send_;
+
+ // Streams of generated data to be sent to the server.
+ net::TestDataStream sent_stream_;
+
+ // Streams of data received from the server that can be independently verified
+ // as the correct stream of data.
+ net::TestDataStream received_stream_;
Mike Belshe 2011/05/27 21:27:00 BTW - I think you only need one stream of test dat
ramant (doing other things) 2011/05/31 21:25:36 Done.
+
+ // Callback to call when data is read from the server.
+ net::CompletionCallbackImpl<NetworkStats> read_callback_;
+
+ // Callback to call when data is sent to the server.
+ net::CompletionCallbackImpl<NetworkStats> write_callback_;
+
+ // Callback to call when echo protocol is successefully finished or whenever
+ // there is an error (this allows unittests to wait until echo protocol's
+ // round trip is finished).
+ net::CompletionCallback* finished_callback_;
+
+ // The time when the session was started.
+ base::TimeTicks start_time_;
+};
+
+class UDPStatsClient : public NetworkStats {
+ public:
+ // Constructs an UDPStatsClient object that collects metrics for UDP
+ // connectivity.
+ UDPStatsClient();
+ virtual ~UDPStatsClient();
+
+ // Starts the client, connecting to |server|.
+ // Client will send |bytes_to_send| bytes to |server|.
+ // When client has received all echoed bytes from the server, or
+ // when an error occurs causing the client to stop, |Finish| will be
+ // called with a net status code.
+ // |Finish| will collect histogram stats.
+ // Returns true if successful in starting the client.
+ bool Start(const std::string& ip_str,
+ int port,
+ int bytes_to_send,
+ net::CompletionCallback* callback);
+
+ protected:
+ // Collects stats for UDP connectivity. This is called when all the data from
+ // server is read or when there is a failure during connect/read/write.
+ virtual void Finish(Status status, int result);
+};
+
+class TCPStatsClient : public NetworkStats {
+ public:
+ // Constructs a TCPStatsClient object that collects metrics for TCP
+ // connectivity.
+ TCPStatsClient();
+ virtual ~TCPStatsClient();
+
+ // Starts the client, connecting to |server|.
+ // Client will send |bytes_to_send| bytes.
+ // When the client has received all echoed bytes from the server, or
+ // when an error occurs causing the client to stop, |Finish| will be
+ // called with a net status code.
+ // |Finish| will collect histogram stats.
+ // Returns true if successful in starting the client.
+ bool Start(const net::HostPortPair& server,
+ int bytes_to_send,
+ net::CompletionCallback* callback);
+
+ protected:
+ // Callback that is called when connect is completed.
+ void OnConnectComplete(int result);
+
+ // Collects stats for TCP connectivity. This is called when all the data from
+ // server is read or when there is a failure during connect/read/write.
+ virtual void Finish(Status status, int result);
+
+ // Callback to call when connect is completed.
+ net::CompletionCallbackImpl<TCPStatsClient> connect_callback_;
+};
+
+// This collects the network connectivity stats for UDP and TCP for small
+// percentage of users who are participating in the experiment. All users must
+// have enabled "UMA upload".
+void CollectNetworkStats(const std::string& network_stats_server_url);
+
+} // namespace chrome_browser_net
+
+#endif // CHROME_BROWSER_NET_NETWORK_STATS_H_

Powered by Google App Engine
This is Rietveld 408576698