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

Unified Diff: base/metrics/statistics_recorder.cc

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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
« no previous file with comments | « base/metrics/sparse_histogram_unittest.cc ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/statistics_recorder.cc
diff --git a/base/metrics/statistics_recorder.cc b/base/metrics/statistics_recorder.cc
index fb069a5cdac94c619a16f8c9350587e12c219c65..85408e1fa496dec8dae7574213a3f3b21a1b123d 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;
}
« no previous file with comments | « base/metrics/sparse_histogram_unittest.cc ('k') | base/metrics/statistics_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698