diff options
author | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-06 00:09:37 +0000 |
---|---|---|
committer | jar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-06 00:09:37 +0000 |
commit | e8829a1981a2d9d849c377c28f9444fdefee0f44 (patch) | |
tree | 3cfe522cf76d308dec9fca773d3f9495e12abc5e /net | |
parent | 4f3b65a30cad88c1f1e482f7bda69ef50f8e1364 (diff) | |
download | chromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.zip chromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.tar.gz chromium_src-e8829a1981a2d9d849c377c28f9444fdefee0f44.tar.bz2 |
Use factory to create histograms, and refcounts to track lifetimes
This is CL patch 377028 by Raman Tenneti, with minor changes to
make the try-bots happier.
It is cleanup that better ensures lifetimes of histograms (making it harder
for users to abuse them).
bug=16495 (repairs leak induced by the first landing)
bug=18840 (should make leaks less possible)
tbr=raman.tenneti
Review URL: http://codereview.chromium.org/462027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33933 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/connection_type_histograms.cc | 22 | ||||
-rw-r--r-- | net/base/mime_sniffer.cc | 86 | ||||
-rw-r--r-- | net/base/sdch_manager.cc | 9 | ||||
-rw-r--r-- | net/disk_cache/histogram_macros.h | 8 | ||||
-rw-r--r-- | net/disk_cache/stats.cc | 3 | ||||
-rw-r--r-- | net/disk_cache/stats.h | 2 | ||||
-rw-r--r-- | net/disk_cache/stats_histogram.cc | 31 | ||||
-rw-r--r-- | net/disk_cache/stats_histogram.h | 16 | ||||
-rw-r--r-- | net/ftp/ftp_network_transaction.cc | 22 | ||||
-rw-r--r-- | net/ftp/ftp_server_type_histograms.cc | 22 | ||||
-rw-r--r-- | net/http/http_network_transaction.cc | 49 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_metrics.cc | 22 |
12 files changed, 179 insertions, 113 deletions
diff --git a/net/base/connection_type_histograms.cc b/net/base/connection_type_histograms.cc index 6e4a929..d200bde 100644 --- a/net/base/connection_type_histograms.cc +++ b/net/base/connection_type_histograms.cc @@ -22,22 +22,24 @@ namespace net { // expansion. void UpdateConnectionTypeHistograms(ConnectionType type) { static bool had_connection_type[NUM_OF_CONNECTION_TYPES]; - static LinearHistogram counter1("Net.HadConnectionType", - 1, NUM_OF_CONNECTION_TYPES, - NUM_OF_CONNECTION_TYPES + 1); - static LinearHistogram counter2("Net.ConnectionTypeCount", - 1, NUM_OF_CONNECTION_TYPES, - NUM_OF_CONNECTION_TYPES + 1); + static scoped_refptr<Histogram> counter1 = + LinearHistogram::LinearHistogramFactoryGet("Net.HadConnectionType", + 1, NUM_OF_CONNECTION_TYPES, + NUM_OF_CONNECTION_TYPES + 1); + static scoped_refptr<Histogram> counter2 = + LinearHistogram::LinearHistogramFactoryGet("Net.ConnectionTypeCount", + 1, NUM_OF_CONNECTION_TYPES, + NUM_OF_CONNECTION_TYPES + 1); if (type >= 0 && type < NUM_OF_CONNECTION_TYPES) { if (!had_connection_type[type]) { had_connection_type[type] = true; - counter1.SetFlags(kUmaTargetedHistogramFlag); - counter1.Add(type); + counter1->SetFlags(kUmaTargetedHistogramFlag); + counter1->Add(type); } } - counter2.SetFlags(kUmaTargetedHistogramFlag); - counter2.Add(type); + counter2->SetFlags(kUmaTargetedHistogramFlag); + counter2->Add(type); } } // namespace net diff --git a/net/base/mime_sniffer.cc b/net/base/mime_sniffer.cc index 07feb33..211cf8c 100644 --- a/net/base/mime_sniffer.cc +++ b/net/base/mime_sniffer.cc @@ -99,18 +99,6 @@ #include "googleurl/src/gurl.h" #include "net/base/mime_util.h" -namespace { - -class SnifferHistogram : public LinearHistogram { - public: - SnifferHistogram(const char* name, int array_size) - : LinearHistogram(name, 0, array_size - 1, array_size) { - SetFlags(kUmaTargetedHistogramFlag); - } -}; - -} // namespace - namespace net { // We aren't interested in looking at more than 512 bytes of content @@ -218,6 +206,15 @@ static const MagicNumber kSniffableTags[] = { MAGIC_HTML_TAG("p") // Mozilla }; +static scoped_refptr<Histogram> UMASnifferHistogramGet(const char* name, + int array_size) { + scoped_refptr<Histogram> counter = + LinearHistogram::LinearHistogramFactoryGet( + name, 1, array_size - 1, array_size); + counter->SetFlags(kUmaTargetedHistogramFlag); + return counter; +} + static bool MatchMagicNumber(const char* content, size_t size, const MagicNumber* magic_entry, std::string* result) { @@ -273,22 +270,24 @@ static bool SniffForHTML(const char* content, size_t size, if (!IsAsciiWhitespace(*pos)) break; } - static SnifferHistogram counter("mime_sniffer.kSniffableTags2", - arraysize(kSniffableTags)); + static scoped_refptr<Histogram> counter = + UMASnifferHistogramGet("mime_sniffer.kSniffableTags2", + arraysize(kSniffableTags)); // |pos| now points to first non-whitespace character (or at end). return CheckForMagicNumbers(pos, end - pos, kSniffableTags, arraysize(kSniffableTags), - &counter, result); + counter.get(), result); } static bool SniffForMagicNumbers(const char* content, size_t size, std::string* result) { // Check our big table of Magic Numbers - static SnifferHistogram counter("mime_sniffer.kMagicNumbers2", - arraysize(kMagicNumbers)); + static scoped_refptr<Histogram> counter = + UMASnifferHistogramGet("mime_sniffer.kMagicNumbers2", + arraysize(kMagicNumbers)); return CheckForMagicNumbers(content, size, kMagicNumbers, arraysize(kMagicNumbers), - &counter, result); + counter.get(), result); } // Byte order marks @@ -320,8 +319,9 @@ static bool SniffXML(const char* content, size_t size, std::string* result) { // We want to skip XML processing instructions (of the form "<?xml ...") // and stop at the first "plain" tag, then make a decision on the mime-type // based on the name (or possibly attributes) of that tag. - static SnifferHistogram counter("mime_sniffer.kMagicXML2", - arraysize(kMagicXML)); + static scoped_refptr<Histogram> counter = + UMASnifferHistogramGet("mime_sniffer.kMagicXML2", + arraysize(kMagicXML)); const int kMaxTagIterations = 5; for (int i = 0; i < kMaxTagIterations && pos < end; ++i) { pos = reinterpret_cast<const char*>(memchr(pos, '<', end - pos)); @@ -341,7 +341,7 @@ static bool SniffXML(const char* content, size_t size, std::string* result) { if (CheckForMagicNumbers(pos, end - pos, kMagicXML, arraysize(kMagicXML), - &counter, result)) + counter.get(), result)) return true; // TODO(evanm): handle RSS 1.0, which is an RDF format and more difficult @@ -388,12 +388,13 @@ static char kByteLooksBinary[] = { static bool LooksBinary(const char* content, size_t size) { // First, we look for a BOM. - static SnifferHistogram counter("mime_sniffer.kByteOrderMark2", - arraysize(kByteOrderMark)); + static scoped_refptr<Histogram> counter = + UMASnifferHistogramGet("mime_sniffer.kByteOrderMark2", + arraysize(kByteOrderMark)); std::string unused; if (CheckForMagicNumbers(content, size, kByteOrderMark, arraysize(kByteOrderMark), - &counter, &unused)) { + counter.get(), &unused)) { // If there is BOM, we think the buffer is not binary. return false; } @@ -422,17 +423,18 @@ static bool IsUnknownMimeType(const std::string& mime_type) { // Firefox rejects a mime type if it is exactly */* "*/*", }; - static SnifferHistogram counter("mime_sniffer.kUnknownMimeTypes2", - arraysize(kUnknownMimeTypes) + 1); + static scoped_refptr<Histogram> counter = + UMASnifferHistogramGet("mime_sniffer.kUnknownMimeTypes2", + arraysize(kUnknownMimeTypes) + 1); for (size_t i = 0; i < arraysize(kUnknownMimeTypes); ++i) { if (mime_type == kUnknownMimeTypes[i]) { - counter.Add(i); + counter->Add(i); return true; } } if (mime_type.find('/') == std::string::npos) { // Firefox rejects a mime type if it does not contain a slash - counter.Add(arraysize(kUnknownMimeTypes)); + counter->Add(arraysize(kUnknownMimeTypes)); return true; } return false; @@ -441,7 +443,8 @@ static bool IsUnknownMimeType(const std::string& mime_type) { // Sniff a crx (chrome extension) file. static bool SniffCRX(const char* content, size_t content_size, const GURL& url, const std::string& type_hint, std::string* result) { - static SnifferHistogram counter("mime_sniffer.kSniffCRX", 3); + static scoped_refptr<Histogram> counter = + UMASnifferHistogramGet("mime_sniffer.kSniffCRX", 3); // Technically, the crx magic number is just Cr24, but the bytes after that // are a version number which changes infrequently. Including it in the @@ -459,7 +462,7 @@ static bool SniffCRX(const char* content, size_t content_size, const GURL& url, const int kExtensionLength = arraysize(kCRXExtension) - 1; // ignore null if (url.path().rfind(kCRXExtension, std::string::npos, kExtensionLength) == url.path().size() - kExtensionLength) { - counter.Add(1); + counter->Add(1); } else { return false; } @@ -467,7 +470,7 @@ static bool SniffCRX(const char* content, size_t content_size, const GURL& url, if (CheckForMagicNumbers(content, content_size, kCRXMagicNumbers, arraysize(kCRXMagicNumbers), NULL, result)) { - counter.Add(2); + counter->Add(2); } else { return false; } @@ -476,15 +479,15 @@ static bool SniffCRX(const char* content, size_t content_size, const GURL& url, } bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) { - static SnifferHistogram should_sniff_counter( - "mime_sniffer.ShouldSniffMimeType2", 3); + static scoped_refptr<Histogram> should_sniff_counter = + UMASnifferHistogramGet("mime_sniffer.ShouldSniffMimeType2", 3); // We are willing to sniff the mime type for HTTP, HTTPS, and FTP bool sniffable_scheme = url.is_empty() || url.SchemeIs("http") || url.SchemeIs("https") || url.SchemeIs("ftp"); if (!sniffable_scheme) { - should_sniff_counter.Add(1); + should_sniff_counter->Add(1); return false; } @@ -501,23 +504,24 @@ bool ShouldSniffMimeType(const GURL& url, const std::string& mime_type) { "text/xml", "application/xml", }; - static SnifferHistogram counter("mime_sniffer.kSniffableTypes2", - arraysize(kSniffableTypes) + 1); + static scoped_refptr<Histogram> counter = + UMASnifferHistogramGet("mime_sniffer.kSniffableTypes2", + arraysize(kSniffableTypes) + 1); for (size_t i = 0; i < arraysize(kSniffableTypes); ++i) { if (mime_type == kSniffableTypes[i]) { - counter.Add(i); - should_sniff_counter.Add(2); + counter->Add(i); + should_sniff_counter->Add(2); return true; } } if (IsUnknownMimeType(mime_type)) { // The web server didn't specify a content type or specified a mime // type that we ignore. - counter.Add(arraysize(kSniffableTypes)); - should_sniff_counter.Add(2); + counter->Add(arraysize(kSniffableTypes)); + should_sniff_counter->Add(2); return true; } - should_sniff_counter.Add(1); + should_sniff_counter->Add(1); return false; } diff --git a/net/base/sdch_manager.cc b/net/base/sdch_manager.cc index b30a171..126a1b6 100644 --- a/net/base/sdch_manager.cc +++ b/net/base/sdch_manager.cc @@ -32,10 +32,11 @@ SdchManager* SdchManager::Global() { // static void SdchManager::SdchErrorRecovery(ProblemCodes problem) { - static LinearHistogram histogram("Sdch3.ProblemCodes_4", MIN_PROBLEM_CODE, - MAX_PROBLEM_CODE - 1, MAX_PROBLEM_CODE); - histogram.SetFlags(kUmaTargetedHistogramFlag); - histogram.Add(problem); + static scoped_refptr<Histogram> histogram = + LinearHistogram::LinearHistogramFactoryGet("Sdch3.ProblemCodes_4", + MIN_PROBLEM_CODE + 1, MAX_PROBLEM_CODE - 1, MAX_PROBLEM_CODE); + histogram->SetFlags(kUmaTargetedHistogramFlag); + histogram->Add(problem); } // static diff --git a/net/disk_cache/histogram_macros.h b/net/disk_cache/histogram_macros.h index 6ff66ea..6d63dc8 100644 --- a/net/disk_cache/histogram_macros.h +++ b/net/disk_cache/histogram_macros.h @@ -26,9 +26,11 @@ UMA_HISTOGRAM_TIMES(name, Time::Now() - initial_time) #define UMA_HISTOGRAM_CACHE_ERROR(name, sample) do { \ - static LinearHistogram counter((name), 0, 49, 50); \ - counter.SetFlags(kUmaTargetedHistogramFlag); \ - counter.Add(sample); \ + static scoped_refptr<Histogram> counter = \ + LinearHistogram::LinearHistogramFactoryGet(\ + (name), 1, 49, 50); \ + counter->SetFlags(kUmaTargetedHistogramFlag); \ + counter->Add(sample); \ } while (0) #ifdef NET_DISK_CACHE_BACKEND_IMPL_CC_ diff --git a/net/disk_cache/stats.cc b/net/disk_cache/stats.cc index a351a6c..e69ea00 100644 --- a/net/disk_cache/stats.cc +++ b/net/disk_cache/stats.cc @@ -138,7 +138,8 @@ bool Stats::Init(BackendImpl* backend, uint32* storage_addr) { backend->ShouldReportAgain()) { // Stats may be reused when the cache is re-created, but we want only one // histogram at any given time. - size_histogram_.reset(new StatsHistogram("DiskCache.SizeStats")); + size_histogram_ = + StatsHistogram::StatsHistogramFactoryGet("DiskCache.SizeStats"); size_histogram_->Init(this); } } diff --git a/net/disk_cache/stats.h b/net/disk_cache/stats.h index 1dcd39f..13536b1 100644 --- a/net/disk_cache/stats.h +++ b/net/disk_cache/stats.h @@ -84,7 +84,7 @@ class Stats { uint32 storage_addr_; int data_sizes_[kDataSizesLength]; int64 counters_[MAX_COUNTER]; - scoped_ptr<StatsHistogram> size_histogram_; + scoped_refptr<StatsHistogram> size_histogram_; DISALLOW_COPY_AND_ASSIGN(Stats); }; diff --git a/net/disk_cache/stats_histogram.cc b/net/disk_cache/stats_histogram.cc index f605934..e6eaf90 100644 --- a/net/disk_cache/stats_histogram.cc +++ b/net/disk_cache/stats_histogram.cc @@ -12,6 +12,37 @@ namespace disk_cache { // Static. const Stats* StatsHistogram::stats_ = NULL; +scoped_refptr<StatsHistogram> StatsHistogram::StatsHistogramFactoryGet( + const std::string& name) { + scoped_refptr<Histogram> histogram(NULL); + + Sample minimum = 1; + Sample maximum = disk_cache::Stats::kDataSizesLength - 1; + size_t bucket_count = disk_cache::Stats::kDataSizesLength; + + if (StatisticsRecorder::FindHistogram(name, &histogram)) { + DCHECK(histogram.get() != NULL); + } else { + histogram = new StatsHistogram(name, minimum, maximum, bucket_count); + scoped_refptr<Histogram> registered_histogram(NULL); + StatisticsRecorder::FindHistogram(name, ®istered_histogram); + if (registered_histogram.get() != NULL && + registered_histogram.get() != histogram.get()) + histogram = registered_histogram; + } + + DCHECK(HISTOGRAM == histogram->histogram_type()); + DCHECK(histogram->HasConstructorArguments(minimum, maximum, bucket_count)); + + // We're preparing for an otherwise unsafe upcast by ensuring we have the + // proper class type. + Histogram* temp_histogram = histogram.get(); + StatsHistogram* temp_stats_histogram = + static_cast<StatsHistogram*>(temp_histogram); + scoped_refptr<StatsHistogram> return_histogram = temp_stats_histogram; + return return_histogram; +} + bool StatsHistogram::Init(const Stats* stats) { DCHECK(stats); if (stats_) diff --git a/net/disk_cache/stats_histogram.h b/net/disk_cache/stats_histogram.h index 8db3bb3..995d486 100644 --- a/net/disk_cache/stats_histogram.h +++ b/net/disk_cache/stats_histogram.h @@ -5,6 +5,8 @@ #ifndef NET_DISK_CACHE_STATS_HISTOGRAM_H_ #define NET_DISK_CACHE_STATS_HISTOGRAM_H_ +#include <string> + #include "base/histogram.h" namespace disk_cache { @@ -14,6 +16,10 @@ class Stats; // This class provides support for sending the disk cache size stats as a UMA // histogram. We'll provide our own storage and management for the data, and a // SampleSet with a copy of our data. +// +// Class derivation of Histogram "deprecated," and should not be copied, and +// may eventually go away. +// class StatsHistogram : public Histogram { public: class StatsSamples : public SampleSet { @@ -23,10 +29,14 @@ class StatsHistogram : public Histogram { } }; - explicit StatsHistogram(const char* name) - : Histogram(name, 1, 1, 2), init_(false) {} + explicit StatsHistogram(const std::string& name, Sample minimum, + Sample maximum, size_t bucket_count) + : Histogram(name, minimum, maximum, bucket_count), init_(false) {} ~StatsHistogram(); + static scoped_refptr<StatsHistogram> + StatsHistogramFactoryGet(const std::string& name); + // We'll be reporting data from the given set of cache stats. bool Init(const Stats* stats); @@ -35,6 +45,8 @@ class StatsHistogram : public Histogram { virtual void SnapshotSample(SampleSet* sample) const; private: + friend class Histogram; + bool init_; static const Stats* stats_; DISALLOW_COPY_AND_ASSIGN(StatsHistogram); diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc index 1dfc99b..8014d07 100644 --- a/net/ftp/ftp_network_transaction.cc +++ b/net/ftp/ftp_network_transaction.cc @@ -1162,21 +1162,23 @@ void FtpNetworkTransaction::RecordDataConnectionError(int result) { break; }; static bool had_error_type[NUM_OF_NET_ERROR_TYPES]; - static LinearHistogram error_flagged("Net.FtpDataConnectionErrorHappened", - 1, NUM_OF_NET_ERROR_TYPES, - NUM_OF_NET_ERROR_TYPES + 1); - static LinearHistogram error_counter("Net.FtpDataConnectionErrorCount", - 1, NUM_OF_NET_ERROR_TYPES, - NUM_OF_NET_ERROR_TYPES + 1); + static scoped_refptr<Histogram> error_flagged = + LinearHistogram::LinearHistogramFactoryGet( + "Net.FtpDataConnectionErrorHappened", + 1, NUM_OF_NET_ERROR_TYPES, NUM_OF_NET_ERROR_TYPES + 1); + static scoped_refptr<Histogram> error_counter = + LinearHistogram::LinearHistogramFactoryGet( + "Net.FtpDataConnectionErrorCount", + 1, NUM_OF_NET_ERROR_TYPES, NUM_OF_NET_ERROR_TYPES + 1); DCHECK(type >= 0 && type < NUM_OF_NET_ERROR_TYPES); if (!had_error_type[type]) { had_error_type[type] = true; - error_flagged.SetFlags(kUmaTargetedHistogramFlag); - error_flagged.Add(type); + error_flagged->SetFlags(kUmaTargetedHistogramFlag); + error_flagged->Add(type); } - error_counter.SetFlags(kUmaTargetedHistogramFlag); - error_counter.Add(type); + error_counter->SetFlags(kUmaTargetedHistogramFlag); + error_counter->Add(type); } } // namespace net diff --git a/net/ftp/ftp_server_type_histograms.cc b/net/ftp/ftp_server_type_histograms.cc index 3f419a8..60ab9b9 100644 --- a/net/ftp/ftp_server_type_histograms.cc +++ b/net/ftp/ftp_server_type_histograms.cc @@ -22,22 +22,24 @@ namespace net { // expansion. void UpdateFtpServerTypeHistograms(FtpServerType type) { static bool had_server_type[NUM_OF_SERVER_TYPES]; - static LinearHistogram counter1("Net.HadFtpServerType", - 1, NUM_OF_SERVER_TYPES, - NUM_OF_SERVER_TYPES + 1); - static LinearHistogram counter2("Net.FtpServerTypeCount", - 1, NUM_OF_SERVER_TYPES, - NUM_OF_SERVER_TYPES + 1); + static scoped_refptr<Histogram> counter1 = + LinearHistogram::LinearHistogramFactoryGet("Net.HadFtpServerType", + 1, NUM_OF_SERVER_TYPES, + NUM_OF_SERVER_TYPES + 1); + static scoped_refptr<Histogram> counter2 = + LinearHistogram::LinearHistogramFactoryGet("Net.FtpServerTypeCount", + 1, NUM_OF_SERVER_TYPES, + NUM_OF_SERVER_TYPES + 1); if (type >= 0 && type < NUM_OF_SERVER_TYPES) { if (!had_server_type[type]) { had_server_type[type] = true; - counter1.SetFlags(kUmaTargetedHistogramFlag); - counter1.Add(type); + counter1->SetFlags(kUmaTargetedHistogramFlag); + counter1->Add(type); } } - counter2.SetFlags(kUmaTargetedHistogramFlag); - counter2.Add(type); + counter2->SetFlags(kUmaTargetedHistogramFlag); + counter2->Add(type); } } // namespace net diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index bdf3e3d..7ca82e38 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -996,18 +996,22 @@ void HttpNetworkTransaction::LogTCPConnectedMetrics( 100); } - static LinearHistogram tcp_socket_type_counter( - "Net.TCPSocketType", - 0, ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1); - tcp_socket_type_counter.SetFlags(kUmaTargetedHistogramFlag); - tcp_socket_type_counter.Add(handle.reuse_type()); + static scoped_refptr<Histogram> tcp_socket_type_counter = + LinearHistogram::LinearHistogramFactoryGet( + "Net.TCPSocketType", + 1, ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1); + tcp_socket_type_counter->SetFlags(kUmaTargetedHistogramFlag); + tcp_socket_type_counter->Add(handle.reuse_type()); if (use_late_binding_histogram) { - static LinearHistogram tcp_socket_type_counter2( - FieldTrial::MakeName("Net.TCPSocketType", "SocketLateBinding").data(), - 0, ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1); - tcp_socket_type_counter2.SetFlags(kUmaTargetedHistogramFlag); - tcp_socket_type_counter2.Add(handle.reuse_type()); + static scoped_refptr<Histogram> tcp_socket_type_counter2 = + LinearHistogram::LinearHistogramFactoryGet( + FieldTrial::MakeName("Net.TCPSocketType", + "SocketLateBinding").data(), + 1, ClientSocketHandle::NUM_TYPES, + ClientSocketHandle::NUM_TYPES + 1); + tcp_socket_type_counter2->SetFlags(kUmaTargetedHistogramFlag); + tcp_socket_type_counter2->Add(handle.reuse_type()); } UMA_HISTOGRAM_CLIPPED_TIMES( @@ -1065,19 +1069,22 @@ void HttpNetworkTransaction::LogIOErrorMetrics( static const bool use_late_binding_histogram = !FieldTrial::MakeName("", "SocketLateBinding").empty(); - static LinearHistogram io_error_socket_type_counter( - "Net.IOError_SocketReuseType", - 0, ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1); - io_error_socket_type_counter.SetFlags(kUmaTargetedHistogramFlag); - io_error_socket_type_counter.Add(handle.reuse_type()); + static scoped_refptr<Histogram> io_error_socket_type_counter = + LinearHistogram::LinearHistogramFactoryGet( + "Net.IOError_SocketReuseType", + 1, ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1); + io_error_socket_type_counter->SetFlags(kUmaTargetedHistogramFlag); + io_error_socket_type_counter->Add(handle.reuse_type()); if (use_late_binding_histogram) { - static LinearHistogram io_error_socket_type_counter( - FieldTrial::MakeName("Net.IOError_SocketReuseType", - "SocketLateBinding").data(), - 0, ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1); - io_error_socket_type_counter.SetFlags(kUmaTargetedHistogramFlag); - io_error_socket_type_counter.Add(handle.reuse_type()); + static scoped_refptr<Histogram> io_error_socket_type_counter = + LinearHistogram::LinearHistogramFactoryGet( + FieldTrial::MakeName("Net.IOError_SocketReuseType", + "SocketLateBinding").data(), + 1, ClientSocketHandle::NUM_TYPES, + ClientSocketHandle::NUM_TYPES + 1); + io_error_socket_type_counter->SetFlags(kUmaTargetedHistogramFlag); + io_error_socket_type_counter->Add(handle.reuse_type()); } switch (handle.reuse_type()) { diff --git a/net/socket_stream/socket_stream_metrics.cc b/net/socket_stream/socket_stream_metrics.cc index f7a55a4..6220eb5 100644 --- a/net/socket_stream/socket_stream_metrics.cc +++ b/net/socket_stream/socket_stream_metrics.cc @@ -83,19 +83,21 @@ void SocketStreamMetrics::OnClose() { } void SocketStreamMetrics::CountProtocolType(ProtocolType protocol_type) { - static LinearHistogram counter("Net.SocketStream.ProtocolType", - 0, NUM_PROTOCOL_TYPES, - NUM_PROTOCOL_TYPES + 1); - counter.SetFlags(kUmaTargetedHistogramFlag); - counter.Add(protocol_type); + static scoped_refptr<Histogram> counter = + LinearHistogram::LinearHistogramFactoryGet( + "Net.SocketStream.ProtocolType", + 0, NUM_PROTOCOL_TYPES, NUM_PROTOCOL_TYPES + 1); + counter->SetFlags(kUmaTargetedHistogramFlag); + counter->Add(protocol_type); } void SocketStreamMetrics::CountConnectionType(ConnectionType connection_type) { - static LinearHistogram counter("Net.SocketStream.ConnectionType", - 1, NUM_CONNECTION_TYPES, - NUM_CONNECTION_TYPES + 1); - counter.SetFlags(kUmaTargetedHistogramFlag); - counter.Add(connection_type); + static scoped_refptr<Histogram> counter = + LinearHistogram::LinearHistogramFactoryGet( + "Net.SocketStream.ConnectionType", + 1, NUM_CONNECTION_TYPES, NUM_CONNECTION_TYPES + 1); + counter->SetFlags(kUmaTargetedHistogramFlag); + counter->Add(connection_type); } |