diff options
author | kaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-18 18:06:30 +0000 |
---|---|---|
committer | kaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-18 18:06:30 +0000 |
commit | 993ae74a7291f89a21ddf7d5436e3e89091cae0d (patch) | |
tree | d4f686676b943b046151431a09dd01aa761abda4 /base/metrics | |
parent | c1f5b4143d01bcfa8a826338eebfe3503a28128e (diff) | |
download | chromium_src-993ae74a7291f89a21ddf7d5436e3e89091cae0d.zip chromium_src-993ae74a7291f89a21ddf7d5436e3e89091cae0d.tar.gz chromium_src-993ae74a7291f89a21ddf7d5436e3e89091cae0d.tar.bz2 |
Change the FindHistogram interface of StatisticsRecorder
Review URL: https://chromiumcodereview.appspot.com/10802002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147269 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/metrics')
-rw-r--r-- | base/metrics/histogram.cc | 20 | ||||
-rw-r--r-- | base/metrics/statistics_recorder.cc | 13 | ||||
-rw-r--r-- | base/metrics/statistics_recorder.h | 5 |
3 files changed, 16 insertions, 22 deletions
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc index e176e8f..97069cc 100644 --- a/base/metrics/histogram.cc +++ b/base/metrics/histogram.cc @@ -79,8 +79,6 @@ Histogram* Histogram::FactoryGet(const std::string& name, Sample maximum, size_t bucket_count, Flags flags) { - Histogram* histogram(NULL); - // Defensive code. if (minimum < 1) minimum = 1; @@ -91,7 +89,8 @@ Histogram* Histogram::FactoryGet(const std::string& name, DCHECK_GT((Sample) bucket_count, 2); DCHECK_LE((Sample) bucket_count, maximum - minimum + 2); - if (!StatisticsRecorder::FindHistogram(name, &histogram)) { + Histogram* histogram = StatisticsRecorder::FindHistogram(name); + if (!histogram) { // Extra variable is not needed... but this keeps this section basically // identical to other derived classes in this file (and compiler will // optimize away the extra variable. @@ -806,8 +805,6 @@ Histogram* LinearHistogram::FactoryGet(const std::string& name, Sample maximum, size_t bucket_count, Flags flags) { - Histogram* histogram(NULL); - if (minimum < 1) minimum = 1; if (maximum > kSampleType_MAX - 1) @@ -817,7 +814,8 @@ Histogram* LinearHistogram::FactoryGet(const std::string& name, DCHECK_GT((Sample) bucket_count, 2); DCHECK_LE((Sample) bucket_count, maximum - minimum + 2); - if (!StatisticsRecorder::FindHistogram(name, &histogram)) { + Histogram* histogram = StatisticsRecorder::FindHistogram(name); + if (!histogram) { // To avoid racy destruction at shutdown, the following will be leaked. LinearHistogram* tentative_histogram = new LinearHistogram(name, minimum, maximum, bucket_count); @@ -907,9 +905,8 @@ bool LinearHistogram::PrintEmptyBucket(size_t index) const { //------------------------------------------------------------------------------ Histogram* BooleanHistogram::FactoryGet(const std::string& name, Flags flags) { - Histogram* histogram(NULL); - - if (!StatisticsRecorder::FindHistogram(name, &histogram)) { + Histogram* histogram = StatisticsRecorder::FindHistogram(name); + if (!histogram) { // To avoid racy destruction at shutdown, the following will be leaked. BooleanHistogram* tentative_histogram = new BooleanHistogram(name); tentative_histogram->InitializeBucketRange(); @@ -941,8 +938,6 @@ BooleanHistogram::BooleanHistogram(const std::string& name) Histogram* CustomHistogram::FactoryGet(const std::string& name, const std::vector<Sample>& custom_ranges, Flags flags) { - Histogram* histogram(NULL); - // Remove the duplicates in the custom ranges array. std::vector<int> ranges = custom_ranges; ranges.push_back(0); // Ensure we have a zero value. @@ -956,7 +951,8 @@ Histogram* CustomHistogram::FactoryGet(const std::string& name, DCHECK_LT(ranges.back(), kSampleType_MAX); - if (!StatisticsRecorder::FindHistogram(name, &histogram)) { + Histogram* histogram = StatisticsRecorder::FindHistogram(name); + if (!histogram) { // To avoid racy destruction at shutdown, the following will be leaked. CustomHistogram* tentative_histogram = new CustomHistogram(name, ranges); tentative_histogram->InitializedCustomBucketRange(ranges); diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc index 37b6f43..384c34f 100644 --- a/base/metrics/statistics_recorder.cc +++ b/base/metrics/statistics_recorder.cc @@ -243,18 +243,17 @@ void StatisticsRecorder::GetHistograms(Histograms* output) { } } -bool StatisticsRecorder::FindHistogram(const std::string& name, - Histogram** histogram) { +// static +Histogram* StatisticsRecorder::FindHistogram(const std::string& name) { if (lock_ == NULL) - return false; + return NULL; base::AutoLock auto_lock(*lock_); if (!histograms_) - return false; + return NULL; HistogramMap::iterator it = histograms_->find(name); if (histograms_->end() == it) - return false; - *histogram = it->second; - return true; + return NULL; + return it->second; } // private static diff --git a/base/metrics/statistics_recorder.h b/base/metrics/statistics_recorder.h index b947c53..ee03f24 100644 --- a/base/metrics/statistics_recorder.h +++ b/base/metrics/statistics_recorder.h @@ -63,9 +63,8 @@ class BASE_EXPORT StatisticsRecorder { static void GetHistograms(Histograms* output); // Find a histogram by name. It matches the exact name. This method is thread - // safe. If a matching histogram is not found, then the |histogram| is - // not changed. - static bool FindHistogram(const std::string& query, Histogram** histogram); + // safe. It returns NULL if a matching histogram is not found. + static Histogram* FindHistogram(const std::string& name); static bool dump_on_exit() { return dump_on_exit_; } |