diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 17:18:22 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 17:18:22 +0000 |
commit | d725d2c5bffbf92b2117696aa4812d4d36c63c40 (patch) | |
tree | cd4a2cfe086f8756768d3192532f77ca3ed7965f /net/disk_cache | |
parent | 62c293e4b24a1a4305a02807dd3dc36d72ff3a17 (diff) | |
download | chromium_src-d725d2c5bffbf92b2117696aa4812d4d36c63c40.zip chromium_src-d725d2c5bffbf92b2117696aa4812d4d36c63c40.tar.gz chromium_src-d725d2c5bffbf92b2117696aa4812d4d36c63c40.tar.bz2 |
Disk cache: Allow the disk cache histograms to generate
more than one name so that we can move a user from one
group to another within the same session.
BUG=none
TEST=unittest
Review URL: http://codereview.chromium.org/2044007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46931 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 13 | ||||
-rw-r--r-- | net/disk_cache/histogram_macros.h | 68 |
2 files changed, 71 insertions, 10 deletions
diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 2297b9f..41c8069 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -13,6 +13,7 @@ #include "net/disk_cache/backend_impl.h" #include "net/disk_cache/disk_cache_test_base.h" #include "net/disk_cache/disk_cache_test_util.h" +#include "net/disk_cache/histogram_macros.h" #include "net/disk_cache/mapped_file.h" #include "testing/gtest/include/gtest/gtest.h" @@ -1612,3 +1613,15 @@ TEST_F(DiskCacheTest, AutomaticMaxSize) { EXPECT_EQ(kint32max, disk_cache::PreferedCacheSize(largest_size * 10000)); } + +// Tests that we can "migrate" a running instance from one experiment group to +// another. +TEST_F(DiskCacheBackendTest, Histograms) { + SetDirectMode(); + InitCache(); + disk_cache::BackendImpl* backend_ = cache_impl_; // Needed be the macro. + + for (int i = 1; i < 3; i++) { + CACHE_UMA(HOURS, "FillupTime", i, 28); + } +} diff --git a/net/disk_cache/histogram_macros.h b/net/disk_cache/histogram_macros.h index 8d5966c..bbea303 100644 --- a/net/disk_cache/histogram_macros.h +++ b/net/disk_cache/histogram_macros.h @@ -11,22 +11,70 @@ #ifndef NET_DISK_CACHE_HISTOGRAM_MACROS_H_ #define NET_DISK_CACHE_HISTOGRAM_MACROS_H_ +// ----------------------------------------------------------------------------- + +// These histograms follow the definition of UMA_HISTOGRAMN_XXX except that +// whenever the name changes (the experiment group changes), the histrogram +// object is re-created. + +#define CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, min, max, bucket_count) \ + do { \ + static scoped_refptr<Histogram> counter; \ + if (!counter || name != counter->histogram_name()) \ + counter = Histogram::FactoryGet(name, min, max, bucket_count, \ + Histogram::kUmaTargetedHistogramFlag); \ + counter->Add(sample); \ + } while (0) + +#define CACHE_HISTOGRAM_COUNTS(name, sample) CACHE_HISTOGRAM_CUSTOM_COUNTS( \ + name, sample, 1, 1000000, 50) + +#define CACHE_HISTOGRAM_COUNTS_10000(name, sample) \ + CACHE_HISTOGRAM_CUSTOM_COUNTS(name, sample, 1, 10000, 50) + +#define CACHE_HISTOGRAM_CUSTOM_TIMES(name, sample, min, max, bucket_count) \ + do { \ + static scoped_refptr<Histogram> counter; \ + if (!counter || name != counter->histogram_name()) \ + counter = Histogram::FactoryGet(name, min, max, bucket_count, \ + Histogram::kUmaTargetedHistogramFlag); \ + counter->AddTime(sample); \ + } while (0) + +#define CACHE_HISTOGRAM_TIMES(name, sample) CACHE_HISTOGRAM_CUSTOM_TIMES( \ + name, sample, base::TimeDelta::FromMilliseconds(1), \ + base::TimeDelta::FromSeconds(10), 50) + +#define CACHE_HISTOGRAM_ENUMERATION(name, sample, boundary_value) do { \ + static scoped_refptr<Histogram> counter; \ + if (!counter || name != counter->histogram_name()) \ + counter = LinearHistogram::FactoryGet( \ + name, 1, boundary_value, boundary_value + 1, \ + Histogram::kUmaTargetedHistogramFlag); \ + counter->Add(sample); \ + } while (0) + +#define CACHE_HISTOGRAM_PERCENTAGE(name, under_one_hundred) \ + CACHE_HISTOGRAM_ENUMERATION(name, under_one_hundred, 101) + +// ----------------------------------------------------------------------------- + // HISTOGRAM_HOURS will collect time related data with a granularity of hours // and normal values of a few months. -#define UMA_HISTOGRAM_HOURS UMA_HISTOGRAM_COUNTS_10000 +#define CACHE_HISTOGRAM_HOURS CACHE_HISTOGRAM_COUNTS_10000 // HISTOGRAM_AGE will collect time elapsed since |initial_time|, with a // granularity of hours and normal values of a few months. -#define UMA_HISTOGRAM_AGE(name, initial_time) \ - UMA_HISTOGRAM_COUNTS_10000(name, (Time::Now() - initial_time).InHours()) +#define CACHE_HISTOGRAM_AGE(name, initial_time) \ + CACHE_HISTOGRAM_COUNTS_10000(name, (Time::Now() - initial_time).InHours()) // HISTOGRAM_AGE_MS will collect time elapsed since |initial_time|, with the // normal resolution of the UMA_HISTOGRAM_TIMES. -#define UMA_HISTOGRAM_AGE_MS(name, initial_time)\ - UMA_HISTOGRAM_TIMES(name, TimeTicks::Now() - initial_time) +#define CACHE_HISTOGRAM_AGE_MS(name, initial_time)\ + CACHE_HISTOGRAM_TIMES(name, TimeTicks::Now() - initial_time) -#define UMA_HISTOGRAM_CACHE_ERROR(name, sample) \ - UMA_HISTOGRAM_ENUMERATION(name, sample, 50) +#define CACHE_HISTOGRAM_CACHE_ERROR(name, sample) \ + CACHE_HISTOGRAM_ENUMERATION(name, sample, 50) #ifdef NET_DISK_CACHE_BACKEND_IMPL_CC_ #define BACKEND_OBJ this @@ -48,13 +96,13 @@ const std::string my_name = BACKEND_OBJ->HistogramName(name, experiment);\ switch (BACKEND_OBJ->cache_type()) {\ case net::DISK_CACHE:\ - UMA_HISTOGRAM_##type(my_name.data(), sample);\ + CACHE_HISTOGRAM_##type(my_name.data(), sample);\ break;\ case net::MEDIA_CACHE:\ - UMA_HISTOGRAM_##type(my_name.data(), sample);\ + CACHE_HISTOGRAM_##type(my_name.data(), sample);\ break;\ case net::APP_CACHE:\ - UMA_HISTOGRAM_##type(my_name.data(), sample);\ + CACHE_HISTOGRAM_##type(my_name.data(), sample);\ break;\ default:\ NOTREACHED();\ |