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

Unified Diff: base/metrics/statistics_recorder.cc

Issue 1866423002: Use strings for keys in the histogram map. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments by Alexei Created 4 years, 8 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/statistics_recorder.h ('k') | no next file » | 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 460c75e8491c9c853389a0744172e08315066c4a..b19a897a96c1ab6e2d7737bd2648100c9bd10281 100644
--- a/base/metrics/statistics_recorder.cc
+++ b/base/metrics/statistics_recorder.cc
@@ -113,11 +113,11 @@ HistogramBase* StatisticsRecorder::RegisterOrDeleteDuplicate(
histogram_to_return = histogram;
} else {
const std::string& name = histogram->histogram_name();
- const uint64_t name_hash = histogram->name_hash();
- DCHECK_NE(0U, name_hash);
- HistogramMap::iterator it = histograms_->find(name_hash);
+ HistogramMap::iterator it = histograms_->find(name);
if (histograms_->end() == it) {
- (*histograms_)[name_hash] = histogram;
+ // The StringKey references the name within |histogram| rather than
+ // making a copy.
+ (*histograms_)[name] = histogram;
ANNOTATE_LEAKING_OBJECT_PTR(histogram); // see crbug.com/79322
// If there are callbacks for this histogram, we set the kCallbackExists
// flag.
@@ -261,7 +261,6 @@ void StatisticsRecorder::GetHistograms(Histograms* output) {
return;
for (const auto& entry : *histograms_) {
- DCHECK_EQ(entry.first, entry.second->name_hash());
output->push_back(entry.second);
}
}
@@ -298,10 +297,9 @@ HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) {
if (allocator)
allocator->ImportHistogramsToStatisticsRecorder();
- HistogramMap::iterator it = histograms_->find(HashMetricName(name));
+ HistogramMap::iterator it = histograms_->find(name);
if (histograms_->end() == it)
return NULL;
- DCHECK_EQ(name, it->second->histogram_name()) << "hash collision";
return it->second;
}
@@ -346,11 +344,9 @@ bool StatisticsRecorder::SetCallback(
return false;
callbacks_->insert(std::make_pair(name, cb));
- auto it = histograms_->find(HashMetricName(name));
- if (it != histograms_->end()) {
- DCHECK_EQ(name, it->second->histogram_name()) << "hash collision";
+ auto it = histograms_->find(name);
+ if (it != histograms_->end())
it->second->SetFlags(HistogramBase::kCallbackExists);
- }
return true;
}
@@ -366,11 +362,9 @@ void StatisticsRecorder::ClearCallback(const std::string& name) {
callbacks_->erase(name);
// We also clear the flag from the histogram (if it exists).
- auto it = histograms_->find(HashMetricName(name));
- if (it != histograms_->end()) {
- DCHECK_EQ(name, it->second->histogram_name()) << "hash collision";
+ auto it = histograms_->find(name);
+ if (it != histograms_->end())
it->second->ClearFlags(HistogramBase::kCallbackExists);
- }
}
// static
@@ -407,7 +401,7 @@ void StatisticsRecorder::ResetForTesting() {
// static
void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) {
if (histograms_)
- histograms_->erase(HashMetricName(name.as_string()));
+ histograms_->erase(name);
}
// This singleton instance should be started during the single threaded portion
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698