diff options
author | asvitkine <asvitkine@chromium.org> | 2015-05-26 22:22:14 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-27 05:22:45 +0000 |
commit | 24d3e9aba9f8c4d8d3c9963d3da678a51981c2fa (patch) | |
tree | fe64afcc0bbf8d4c5079092ce4fbb3f9aefc96ce | |
parent | e88fe07b4fd9c8146fb541b4cda6775105ecc2e4 (diff) | |
download | chromium_src-24d3e9aba9f8c4d8d3c9963d3da678a51981c2fa.zip chromium_src-24d3e9aba9f8c4d8d3c9963d3da678a51981c2fa.tar.gz chromium_src-24d3e9aba9f8c4d8d3c9963d3da678a51981c2fa.tar.bz2 |
Clean up base histograms code.
Cleans up some existing style issues as well as switching
to some cleaner C++11 constructs (e.g. new for loops),
and removing using declarations for std:: classes, which
Chromium typically avoids.
BUG=none
Review URL: https://codereview.chromium.org/1158043002
Cr-Commit-Position: refs/heads/master@{#331535}
-rw-r--r-- | base/metrics/histogram.cc | 71 | ||||
-rw-r--r-- | base/metrics/histogram_snapshot_manager.cc | 5 | ||||
-rw-r--r-- | base/metrics/histogram_unittest.cc | 19 | ||||
-rw-r--r-- | base/metrics/sample_map.cc | 13 | ||||
-rw-r--r-- | base/metrics/sample_map_unittest.cc | 3 | ||||
-rw-r--r-- | base/metrics/sample_vector.cc | 4 | ||||
-rw-r--r-- | base/metrics/sample_vector_unittest.cc | 7 | ||||
-rw-r--r-- | base/metrics/sparse_histogram.cc | 22 | ||||
-rw-r--r-- | base/metrics/sparse_histogram_unittest.cc | 3 | ||||
-rw-r--r-- | base/metrics/statistics_recorder.cc | 62 |
10 files changed, 86 insertions, 123 deletions
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc index 42ced3d..1550420 100644 --- a/base/metrics/histogram.cc +++ b/base/metrics/histogram.cc @@ -25,15 +25,12 @@ #include "base/synchronization/lock.h" #include "base/values.h" -using std::string; -using std::vector; - namespace base { namespace { bool ReadHistogramArguments(PickleIterator* iter, - string* histogram_name, + std::string* histogram_name, int* flags, int* declared_min, int* declared_max, @@ -84,7 +81,7 @@ typedef HistogramBase::Sample Sample; // static const size_t Histogram::kBucketCount_MAX = 16384u; -HistogramBase* Histogram::FactoryGet(const string& name, +HistogramBase* Histogram::FactoryGet(const std::string& name, Sample minimum, Sample maximum, size_t bucket_count, @@ -123,7 +120,7 @@ HistogramBase* Histogram::FactoryGet(const string& name, return histogram; } -HistogramBase* Histogram::FactoryTimeGet(const string& name, +HistogramBase* Histogram::FactoryTimeGet(const std::string& name, TimeDelta minimum, TimeDelta maximum, size_t bucket_count, @@ -216,7 +213,7 @@ size_t Histogram::bucket_count() const { } // static -bool Histogram::InspectConstructionArguments(const string& name, +bool Histogram::InspectConstructionArguments(const std::string& name, Sample* minimum, Sample* maximum, size_t* bucket_count) { @@ -280,14 +277,14 @@ bool Histogram::AddSamplesFromPickle(PickleIterator* iter) { } // The following methods provide a graphical histogram display. -void Histogram::WriteHTMLGraph(string* output) const { +void Histogram::WriteHTMLGraph(std::string* output) const { // TBD(jar) Write a nice HTML bar chart, with divs an mouse-overs etc. output->append("<PRE>"); WriteAsciiImpl(true, "<br>", output); output->append("</PRE>"); } -void Histogram::WriteAscii(string* output) const { +void Histogram::WriteAscii(std::string* output) const { WriteAsciiImpl(true, "\n", output); } @@ -301,7 +298,7 @@ bool Histogram::SerializeInfoImpl(Pickle* pickle) const { pickle->WriteUInt32(bucket_ranges()->checksum()); } -Histogram::Histogram(const string& name, +Histogram::Histogram(const std::string& name, Sample minimum, Sample maximum, const BucketRanges* ranges) @@ -334,7 +331,7 @@ double Histogram::GetBucketSize(Count current, size_t i) const { return current/denominator; } -const string Histogram::GetAsciiBucketRange(size_t i) const { +const std::string Histogram::GetAsciiBucketRange(size_t i) const { return GetSimpleAsciiBucketRange(ranges(i)); } @@ -343,7 +340,7 @@ const string Histogram::GetAsciiBucketRange(size_t i) const { // static HistogramBase* Histogram::DeserializeInfoImpl(PickleIterator* iter) { - string histogram_name; + std::string histogram_name; int flags; int declared_min; int declared_max; @@ -373,8 +370,8 @@ scoped_ptr<SampleVector> Histogram::SnapshotSampleVector() const { } void Histogram::WriteAsciiImpl(bool graph_it, - const string& newline, - string* output) const { + const std::string& newline, + std::string* output) const { // Get local (stack) copies of all effectively volatile class data so that we // are consistent across our output activities. scoped_ptr<SampleVector> snapshot = SnapshotSampleVector(); @@ -415,7 +412,7 @@ void Histogram::WriteAsciiImpl(bool graph_it, if (!current && !PrintEmptyBucket(i)) continue; remaining -= current; - string range = GetAsciiBucketRange(i); + std::string range = GetAsciiBucketRange(i); output->append(range); for (size_t j = 0; range.size() + j < print_width + 1; ++j) output->push_back(' '); @@ -451,7 +448,7 @@ double Histogram::GetPeakBucketSize(const SampleVector& samples) const { void Histogram::WriteAsciiHeader(const SampleVector& samples, Count sample_count, - string* output) const { + std::string* output) const { StringAppendF(output, "Histogram: %s recorded %d samples", histogram_name().c_str(), @@ -471,7 +468,7 @@ void Histogram::WriteAsciiBucketContext(const int64 past, const Count current, const int64 remaining, const size_t i, - string* output) const { + std::string* output) const { double scaled_sum = (past + current + remaining) / 100.0; WriteAsciiBucketValue(current, scaled_sum, output); if (0 < i) { @@ -515,7 +512,7 @@ void Histogram::GetCountAndBucketData(Count* count, LinearHistogram::~LinearHistogram() {} -HistogramBase* LinearHistogram::FactoryGet(const string& name, +HistogramBase* LinearHistogram::FactoryGet(const std::string& name, Sample minimum, Sample maximum, size_t bucket_count, @@ -524,7 +521,7 @@ HistogramBase* LinearHistogram::FactoryGet(const string& name, name, minimum, maximum, bucket_count, flags, NULL); } -HistogramBase* LinearHistogram::FactoryTimeGet(const string& name, +HistogramBase* LinearHistogram::FactoryTimeGet(const std::string& name, TimeDelta minimum, TimeDelta maximum, size_t bucket_count, @@ -587,7 +584,7 @@ HistogramType LinearHistogram::GetHistogramType() const { return LINEAR_HISTOGRAM; } -LinearHistogram::LinearHistogram(const string& name, +LinearHistogram::LinearHistogram(const std::string& name, Sample minimum, Sample maximum, const BucketRanges* ranges) @@ -602,7 +599,7 @@ double LinearHistogram::GetBucketSize(Count current, size_t i) const { return current/denominator; } -const string LinearHistogram::GetAsciiBucketRange(size_t i) const { +const std::string LinearHistogram::GetAsciiBucketRange(size_t i) const { int range = ranges(i); BucketDescriptionMap::const_iterator it = bucket_description_.find(range); if (it == bucket_description_.end()) @@ -632,7 +629,7 @@ void LinearHistogram::InitializeBucketRanges(Sample minimum, // static HistogramBase* LinearHistogram::DeserializeInfoImpl(PickleIterator* iter) { - string histogram_name; + std::string histogram_name; int flags; int declared_min; int declared_max; @@ -657,7 +654,8 @@ HistogramBase* LinearHistogram::DeserializeInfoImpl(PickleIterator* iter) { // This section provides implementation for BooleanHistogram. //------------------------------------------------------------------------------ -HistogramBase* BooleanHistogram::FactoryGet(const string& name, int32 flags) { +HistogramBase* BooleanHistogram::FactoryGet(const std::string& name, + int32 flags) { HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); if (!histogram) { // To avoid racy destruction at shutdown, the following will be leaked. @@ -682,12 +680,12 @@ HistogramType BooleanHistogram::GetHistogramType() const { return BOOLEAN_HISTOGRAM; } -BooleanHistogram::BooleanHistogram(const string& name, +BooleanHistogram::BooleanHistogram(const std::string& name, const BucketRanges* ranges) : LinearHistogram(name, 1, 2, ranges) {} HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) { - string histogram_name; + std::string histogram_name; int flags; int declared_min; int declared_max; @@ -712,9 +710,10 @@ HistogramBase* BooleanHistogram::DeserializeInfoImpl(PickleIterator* iter) { // CustomHistogram: //------------------------------------------------------------------------------ -HistogramBase* CustomHistogram::FactoryGet(const string& name, - const vector<Sample>& custom_ranges, - int32 flags) { +HistogramBase* CustomHistogram::FactoryGet( + const std::string& name, + const std::vector<Sample>& custom_ranges, + int32 flags) { CHECK(ValidateCustomRanges(custom_ranges)); HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); @@ -742,9 +741,9 @@ HistogramType CustomHistogram::GetHistogramType() const { } // static -vector<Sample> CustomHistogram::ArrayToCustomRanges( +std::vector<Sample> CustomHistogram::ArrayToCustomRanges( const Sample* values, size_t num_values) { - vector<Sample> all_values; + std::vector<Sample> all_values; for (size_t i = 0; i < num_values; ++i) { Sample value = values[i]; all_values.push_back(value); @@ -756,7 +755,7 @@ vector<Sample> CustomHistogram::ArrayToCustomRanges( return all_values; } -CustomHistogram::CustomHistogram(const string& name, +CustomHistogram::CustomHistogram(const std::string& name, const BucketRanges* ranges) : Histogram(name, ranges->range(1), @@ -782,7 +781,7 @@ double CustomHistogram::GetBucketSize(Count current, size_t i) const { // static HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) { - string histogram_name; + std::string histogram_name; int flags; int declared_min; int declared_max; @@ -795,7 +794,7 @@ HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) { } // First and last ranges are not serialized. - vector<Sample> sample_ranges(bucket_count - 1); + std::vector<Sample> sample_ranges(bucket_count - 1); for (size_t i = 0; i < sample_ranges.size(); ++i) { if (!iter->ReadInt(&sample_ranges[i])) @@ -813,7 +812,7 @@ HistogramBase* CustomHistogram::DeserializeInfoImpl(PickleIterator* iter) { // static bool CustomHistogram::ValidateCustomRanges( - const vector<Sample>& custom_ranges) { + const std::vector<Sample>& custom_ranges) { bool has_valid_range = false; for (size_t i = 0; i < custom_ranges.size(); i++) { Sample sample = custom_ranges[i]; @@ -827,9 +826,9 @@ bool CustomHistogram::ValidateCustomRanges( // static BucketRanges* CustomHistogram::CreateBucketRangesFromCustomRanges( - const vector<Sample>& custom_ranges) { + const std::vector<Sample>& custom_ranges) { // Remove the duplicates in the custom ranges array. - vector<int> ranges = custom_ranges; + std::vector<int> ranges = custom_ranges; ranges.push_back(0); // Ensure we have a zero value. ranges.push_back(HistogramBase::kSampleType_MAX); std::sort(ranges.begin(), ranges.end()); diff --git a/base/metrics/histogram_snapshot_manager.cc b/base/metrics/histogram_snapshot_manager.cc index b1e26da..a7605aa 100644 --- a/base/metrics/histogram_snapshot_manager.cc +++ b/base/metrics/histogram_snapshot_manager.cc @@ -10,9 +10,6 @@ #include "base/metrics/statistics_recorder.h" #include "base/stl_util.h" -using std::map; -using std::string; - namespace base { HistogramSnapshotManager::HistogramSnapshotManager( @@ -78,7 +75,7 @@ void HistogramSnapshotManager::PrepareDelta(const HistogramBase& histogram) { } HistogramSamples* to_log; - map<string, HistogramSamples*>::iterator it = + std::map<std::string, HistogramSamples*>::iterator it = logged_samples_.find(histogram_name); if (it == logged_samples_.end()) { to_log = snapshot.release(); diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc index df43e65..2e3a1ee 100644 --- a/base/metrics/histogram_unittest.cc +++ b/base/metrics/histogram_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Test of Histogram class +#include "base/metrics/histogram.h" #include <climits> #include <algorithm> @@ -11,15 +11,12 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/metrics/bucket_ranges.h" -#include "base/metrics/histogram.h" #include "base/metrics/sample_vector.h" #include "base/metrics/statistics_recorder.h" #include "base/pickle.h" #include "base/time/time.h" #include "testing/gtest/include/gtest/gtest.h" -using std::vector; - namespace base { class HistogramTest : public testing::Test { @@ -55,7 +52,7 @@ TEST_F(HistogramTest, BasicTest) { "TestLinearHistogram", 1, 1000, 10, HistogramBase::kNoFlags); EXPECT_TRUE(linear_histogram); - vector<int> custom_ranges; + std::vector<int> custom_ranges; custom_ranges.push_back(1); custom_ranges.push_back(5); HistogramBase* custom_histogram = CustomHistogram::FactoryGet( @@ -157,7 +154,7 @@ TEST_F(HistogramTest, LinearRangesTest) { TEST_F(HistogramTest, ArrayToCustomRangesTest) { const HistogramBase::Sample ranges[3] = {5, 10, 20}; - vector<HistogramBase::Sample> ranges_vec = + std::vector<HistogramBase::Sample> ranges_vec = CustomHistogram::ArrayToCustomRanges(ranges, 3); ASSERT_EQ(6u, ranges_vec.size()); EXPECT_EQ(5, ranges_vec[0]); @@ -170,7 +167,7 @@ TEST_F(HistogramTest, ArrayToCustomRangesTest) { TEST_F(HistogramTest, CustomHistogramTest) { // A well prepared custom ranges. - vector<HistogramBase::Sample> custom_ranges; + std::vector<HistogramBase::Sample> custom_ranges; custom_ranges.push_back(1); custom_ranges.push_back(2); @@ -220,7 +217,7 @@ TEST_F(HistogramTest, CustomHistogramWithOnly2Buckets) { // We should probably change the restriction on the base class (or not inherit // the base class!). - vector<HistogramBase::Sample> custom_ranges; + std::vector<HistogramBase::Sample> custom_ranges; custom_ranges.push_back(4); Histogram* histogram = static_cast<Histogram*>( @@ -256,7 +253,7 @@ TEST_F(HistogramTest, BoundsTest) { EXPECT_EQ(0, samples->GetCountAtIndex(array_size - 2)); EXPECT_EQ(2, samples->GetCountAtIndex(array_size - 1)); - vector<int> custom_ranges; + std::vector<int> custom_ranges; custom_ranges.push_back(10); custom_ranges.push_back(50); custom_ranges.push_back(100); @@ -405,7 +402,7 @@ TEST_F(HistogramTest, HistogramSerializeInfo) { } TEST_F(HistogramTest, CustomHistogramSerializeInfo) { - vector<int> custom_ranges; + std::vector<int> custom_ranges; custom_ranges.push_back(10); custom_ranges.push_back(100); @@ -484,7 +481,7 @@ TEST(HistogramDeathTest, BadRangesTest) { linear_histogram->HasConstructionArguments( 1, HistogramBase::kSampleType_MAX - 1, 8)); - vector<int> custom_ranges; + std::vector<int> custom_ranges; custom_ranges.push_back(0); custom_ranges.push_back(5); Histogram* custom_histogram = static_cast<Histogram*>( diff --git a/base/metrics/sample_map.cc b/base/metrics/sample_map.cc index 42468cb..00ac939 100644 --- a/base/metrics/sample_map.cc +++ b/base/metrics/sample_map.cc @@ -6,8 +6,6 @@ #include "base/logging.h" -using std::map; - namespace base { typedef HistogramBase::Count Count; @@ -24,7 +22,7 @@ void SampleMap::Accumulate(Sample value, Count count) { } Count SampleMap::GetCount(Sample value) const { - map<Sample, Count>::const_iterator it = sample_counts_.find(value); + std::map<Sample, Count>::const_iterator it = sample_counts_.find(value); if (it == sample_counts_.end()) return 0; return it->second; @@ -32,10 +30,8 @@ Count SampleMap::GetCount(Sample value) const { Count SampleMap::TotalCount() const { Count count = 0; - for (map<Sample, Count>::const_iterator it = sample_counts_.begin(); - it != sample_counts_.end(); - ++it) { - count += it->second; + for (const auto& entry : sample_counts_) { + count += entry.second; } return count; } @@ -53,7 +49,8 @@ bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, iter->Get(&min, &max, &count); if (min + 1 != max) return false; // SparseHistogram only supports bucket with size 1. - sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; + + sample_counts_[min] += (op == HistogramSamples::ADD) ? count : -count; } return true; } diff --git a/base/metrics/sample_map_unittest.cc b/base/metrics/sample_map_unittest.cc index 1a53ee7..772c3da 100644 --- a/base/metrics/sample_map_unittest.cc +++ b/base/metrics/sample_map_unittest.cc @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/memory/scoped_ptr.h" #include "base/metrics/sample_map.h" + +#include "base/memory/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" namespace base { diff --git a/base/metrics/sample_vector.cc b/base/metrics/sample_vector.cc index ca3205e..1202527 100644 --- a/base/metrics/sample_vector.cc +++ b/base/metrics/sample_vector.cc @@ -7,8 +7,6 @@ #include "base/logging.h" #include "base/metrics/bucket_ranges.h" -using std::vector; - namespace base { typedef HistogramBase::Count Count; @@ -111,7 +109,7 @@ size_t SampleVector::GetBucketIndex(Sample value) const { return mid; } -SampleVectorIterator::SampleVectorIterator(const vector<Count>* counts, +SampleVectorIterator::SampleVectorIterator(const std::vector<Count>* counts, const BucketRanges* bucket_ranges) : counts_(counts), bucket_ranges_(bucket_ranges), diff --git a/base/metrics/sample_vector_unittest.cc b/base/metrics/sample_vector_unittest.cc index 9c7ba96..fd42376 100644 --- a/base/metrics/sample_vector_unittest.cc +++ b/base/metrics/sample_vector_unittest.cc @@ -2,16 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/metrics/sample_vector.h" + #include <vector> #include "base/memory/scoped_ptr.h" #include "base/metrics/bucket_ranges.h" #include "base/metrics/histogram.h" -#include "base/metrics/sample_vector.h" #include "testing/gtest/include/gtest/gtest.h" -using std::vector; - namespace base { namespace { @@ -179,7 +178,7 @@ TEST(SampleVectorIteratorTest, IterateTest) { ranges.set_range(3, 3); ranges.set_range(4, 4); - vector<HistogramBase::Count> counts(3); + std::vector<HistogramBase::Count> counts(3); counts[0] = 1; counts[1] = 0; // Iterator will bypass this empty bucket. counts[2] = 2; diff --git a/base/metrics/sparse_histogram.cc b/base/metrics/sparse_histogram.cc index 773eeb6..e5cdb43 100644 --- a/base/metrics/sparse_histogram.cc +++ b/base/metrics/sparse_histogram.cc @@ -10,16 +10,14 @@ #include "base/strings/stringprintf.h" #include "base/synchronization/lock.h" -using std::map; -using std::string; - namespace base { typedef HistogramBase::Count Count; typedef HistogramBase::Sample Sample; // static -HistogramBase* SparseHistogram::FactoryGet(const string& name, int32 flags) { +HistogramBase* SparseHistogram::FactoryGet(const std::string& name, + int32 flags) { HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); if (!histogram) { @@ -70,13 +68,13 @@ bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) { return samples_.AddFromPickle(iter); } -void SparseHistogram::WriteHTMLGraph(string* output) const { +void SparseHistogram::WriteHTMLGraph(std::string* output) const { output->append("<PRE>"); WriteAsciiImpl(true, "<br>", output); output->append("</PRE>"); } -void SparseHistogram::WriteAscii(string* output) const { +void SparseHistogram::WriteAscii(std::string* output) const { WriteAsciiImpl(true, "\n", output); } @@ -84,11 +82,11 @@ bool SparseHistogram::SerializeInfoImpl(Pickle* pickle) const { return pickle->WriteString(histogram_name()) && pickle->WriteInt(flags()); } -SparseHistogram::SparseHistogram(const string& name) +SparseHistogram::SparseHistogram(const std::string& name) : HistogramBase(name) {} HistogramBase* SparseHistogram::DeserializeInfoImpl(PickleIterator* iter) { - string histogram_name; + std::string histogram_name; int flags; if (!iter->ReadString(&histogram_name) || !iter->ReadInt(&flags)) { DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name; @@ -129,8 +127,7 @@ void SparseHistogram::WriteAsciiImpl(bool graph_it, Count largest_count = 0; Sample largest_sample = 0; scoped_ptr<SampleCountIterator> it = snapshot->Iterator(); - while (!it->Done()) - { + while (!it->Done()) { Sample min; Sample max; Count count; @@ -145,15 +142,14 @@ void SparseHistogram::WriteAsciiImpl(bool graph_it, // iterate over each item and display them it = snapshot->Iterator(); - while (!it->Done()) - { + while (!it->Done()) { Sample min; Sample max; Count count; it->Get(&min, &max, &count); // value is min, so display it - string range = GetSimpleAsciiBucketRange(min); + std::string range = GetSimpleAsciiBucketRange(min); output->append(range); for (size_t j = 0; range.size() + j < print_width + 1; ++j) output->push_back(' '); diff --git a/base/metrics/sparse_histogram_unittest.cc b/base/metrics/sparse_histogram_unittest.cc index c29dd5e..fca4d59 100644 --- a/base/metrics/sparse_histogram_unittest.cc +++ b/base/metrics/sparse_histogram_unittest.cc @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/metrics/sparse_histogram.h" + #include <string> #include "base/memory/scoped_ptr.h" #include "base/metrics/histogram_base.h" #include "base/metrics/histogram_samples.h" #include "base/metrics/sample_map.h" -#include "base/metrics/sparse_histogram.h" #include "base/metrics/statistics_recorder.h" #include "base/pickle.h" #include "base/strings/stringprintf.h" diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc index fb069a5..85408e1 100644 --- a/base/metrics/statistics_recorder.cc +++ b/base/metrics/statistics_recorder.cc @@ -14,9 +14,6 @@ #include "base/synchronization/lock.h" #include "base/values.h" -using std::list; -using std::string; - namespace { // Initialize histogram statistics gathering system. base::LazyInstance<base::StatisticsRecorder>::Leaky g_statistics_recorder_ = @@ -59,7 +56,7 @@ HistogramBase* StatisticsRecorder::RegisterOrDeleteDuplicate( if (histograms_ == NULL) { histogram_to_return = histogram; } else { - const string& name = histogram->histogram_name(); + const std::string& name = histogram->histogram_name(); HistogramMap::iterator it = histograms_->find(name); if (histograms_->end() == it) { (*histograms_)[name] = histogram; @@ -96,22 +93,18 @@ const BucketRanges* StatisticsRecorder::RegisterOrDeleteDuplicateRanges( return ranges; } - list<const BucketRanges*>* checksum_matching_list; + std::list<const BucketRanges*>* checksum_matching_list; RangesMap::iterator ranges_it = ranges_->find(ranges->checksum()); if (ranges_->end() == ranges_it) { // Add a new matching list to map. - checksum_matching_list = new list<const BucketRanges*>(); + checksum_matching_list = new std::list<const BucketRanges*>(); ANNOTATE_LEAKING_OBJECT_PTR(checksum_matching_list); (*ranges_)[ranges->checksum()] = checksum_matching_list; } else { checksum_matching_list = ranges_it->second; } - list<const BucketRanges*>::iterator checksum_matching_list_it; - for (checksum_matching_list_it = checksum_matching_list->begin(); - checksum_matching_list_it != checksum_matching_list->end(); - ++checksum_matching_list_it) { - const BucketRanges* existing_ranges = *checksum_matching_list_it; + for (const BucketRanges* existing_ranges : *checksum_matching_list) { if (existing_ranges->Equals(ranges)) { if (existing_ranges == ranges) { return ranges; @@ -135,10 +128,8 @@ void StatisticsRecorder::WriteHTMLGraph(const std::string& query, Histograms snapshot; GetSnapshot(query, &snapshot); - for (Histograms::iterator it = snapshot.begin(); - it != snapshot.end(); - ++it) { - (*it)->WriteHTMLGraph(output); + for (const HistogramBase* histogram : snapshot) { + histogram->WriteHTMLGraph(output); output->append("<br><hr><br>"); } } @@ -155,10 +146,8 @@ void StatisticsRecorder::WriteGraph(const std::string& query, Histograms snapshot; GetSnapshot(query, &snapshot); - for (Histograms::iterator it = snapshot.begin(); - it != snapshot.end(); - ++it) { - (*it)->WriteAscii(output); + for (const HistogramBase* histogram : snapshot) { + histogram->WriteAscii(output); output->append("\n"); } } @@ -179,14 +168,13 @@ std::string StatisticsRecorder::ToJSON(const std::string& query) { GetSnapshot(query, &snapshot); output += "\"histograms\":["; bool first_histogram = true; - for (Histograms::const_iterator it = snapshot.begin(); it != snapshot.end(); - ++it) { + for (const HistogramBase* histogram : snapshot) { if (first_histogram) first_histogram = false; else output += ","; std::string json; - (*it)->WriteJSON(&json); + histogram->WriteJSON(&json); output += json; } output += "]}"; @@ -201,11 +189,9 @@ void StatisticsRecorder::GetHistograms(Histograms* output) { if (histograms_ == NULL) return; - for (HistogramMap::iterator it = histograms_->begin(); - histograms_->end() != it; - ++it) { - DCHECK_EQ(it->first, it->second->histogram_name()); - output->push_back(it->second); + for (const auto& entry : *histograms_) { + DCHECK_EQ(entry.first, entry.second->histogram_name()); + output->push_back(entry.second); } } @@ -218,15 +204,9 @@ void StatisticsRecorder::GetBucketRanges( if (ranges_ == NULL) return; - for (RangesMap::iterator it = ranges_->begin(); - ranges_->end() != it; - ++it) { - list<const BucketRanges*>* ranges_list = it->second; - list<const BucketRanges*>::iterator ranges_list_it; - for (ranges_list_it = ranges_list->begin(); - ranges_list_it != ranges_list->end(); - ++ranges_list_it) { - output->push_back(*ranges_list_it); + for (const auto& entry : *ranges_) { + for (const auto& range_entry : *entry.second) { + output->push_back(range_entry); } } } @@ -254,11 +234,9 @@ void StatisticsRecorder::GetSnapshot(const std::string& query, if (histograms_ == NULL) return; - for (HistogramMap::iterator it = histograms_->begin(); - histograms_->end() != it; - ++it) { - if (it->first.find(query) != std::string::npos) - snapshot->push_back(it->second); + for (const auto& entry : *histograms_) { + if (entry.first.find(query) != std::string::npos) + snapshot->push_back(entry.second); } } @@ -286,7 +264,7 @@ StatisticsRecorder::StatisticsRecorder() { // static void StatisticsRecorder::DumpHistogramsToVlog(void* instance) { - string output; + std::string output; StatisticsRecorder::WriteGraph(std::string(), &output); VLOG(1) << output; } |