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

Side by Side Diff: base/metrics/statistics_recorder.cc

Issue 1719363002: Collect information about failing histogram factory calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/statistics_recorder.h" 5 #include "base/metrics/statistics_recorder.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/debug/alias.h"
8 #include "base/debug/leak_annotations.h" 9 #include "base/debug/leak_annotations.h"
9 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
13 #include "base/metrics/metrics_hashes.h" 14 #include "base/metrics/metrics_hashes.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
17 #include "base/values.h" 18 #include "base/values.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 histogram->SetFlags(HistogramBase::kCallbackExists); 126 histogram->SetFlags(HistogramBase::kCallbackExists);
126 else 127 else
127 histogram->ClearFlags(HistogramBase::kCallbackExists); 128 histogram->ClearFlags(HistogramBase::kCallbackExists);
128 } 129 }
129 histogram_to_return = histogram; 130 histogram_to_return = histogram;
130 } else if (histogram == it->second) { 131 } else if (histogram == it->second) {
131 // The histogram was registered before. 132 // The histogram was registered before.
132 histogram_to_return = histogram; 133 histogram_to_return = histogram;
133 } else { 134 } else {
134 // We already have one histogram with this name. 135 // We already have one histogram with this name.
135 DCHECK_EQ(histogram->histogram_name(), 136 CHECK_EQ(histogram->histogram_name(),
136 it->second->histogram_name()) << "hash collision"; 137 it->second->histogram_name()) << "hash collision";
137 histogram_to_return = it->second; 138 histogram_to_return = it->second;
138 histogram_to_delete = histogram; 139 histogram_to_delete = histogram;
139 } 140 }
141 base::debug::Alias(&it);
142 base::debug::Alias(&name);
143 base::debug::Alias(&name_hash);
140 } 144 }
141 } 145 }
146 base::debug::Alias(&histogram);
142 delete histogram_to_delete; 147 delete histogram_to_delete;
143 return histogram_to_return; 148 return histogram_to_return;
144 } 149 }
145 150
146 // static 151 // static
147 const BucketRanges* StatisticsRecorder::RegisterOrDeleteDuplicateRanges( 152 const BucketRanges* StatisticsRecorder::RegisterOrDeleteDuplicateRanges(
148 const BucketRanges* ranges) { 153 const BucketRanges* ranges) {
149 DCHECK(ranges->HasValidChecksum()); 154 DCHECK(ranges->HasValidChecksum());
150 scoped_ptr<const BucketRanges> ranges_deleter; 155 scoped_ptr<const BucketRanges> ranges_deleter;
151 156
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 286 }
282 287
283 // static 288 // static
284 HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) { 289 HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) {
285 if (lock_ == NULL) 290 if (lock_ == NULL)
286 return NULL; 291 return NULL;
287 base::AutoLock auto_lock(*lock_); 292 base::AutoLock auto_lock(*lock_);
288 if (histograms_ == NULL) 293 if (histograms_ == NULL)
289 return NULL; 294 return NULL;
290 295
291 HistogramMap::iterator it = histograms_->find(HashMetricName(name)); 296 const uint64_t lookup_hash = HashMetricName(name);
297 HistogramMap::iterator it = histograms_->find(lookup_hash);
292 if (histograms_->end() == it) 298 if (histograms_->end() == it)
293 return NULL; 299 return NULL;
294 DCHECK_EQ(name, it->second->histogram_name()) << "hash collision"; 300
301 const uint64_t existing_hash = it->first;
302 const char* existing_name = it->second->histogram_name().c_str();
303 HistogramMap* histograms = histograms_;
304 CHECK_EQ(name, it->second->histogram_name()) << "hash collision";
305 base::debug::Alias(&lookup_hash);
306 base::debug::Alias(&existing_hash);
307 base::debug::Alias(&name);
308 base::debug::Alias(&existing_name);
309 base::debug::Alias(&it);
310 base::debug::Alias(&histograms);
311
295 return it->second; 312 return it->second;
296 } 313 }
297 314
298 // static 315 // static
299 StatisticsRecorder::HistogramIterator StatisticsRecorder::begin( 316 StatisticsRecorder::HistogramIterator StatisticsRecorder::begin(
300 bool include_persistent) { 317 bool include_persistent) {
301 return HistogramIterator(histograms_->begin(), include_persistent); 318 return HistogramIterator(histograms_->begin(), include_persistent);
302 } 319 }
303 320
304 // static 321 // static
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 // static 474 // static
458 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 475 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
459 // static 476 // static
460 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; 477 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL;
461 // static 478 // static
462 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; 479 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL;
463 // static 480 // static
464 base::Lock* StatisticsRecorder::lock_ = NULL; 481 base::Lock* StatisticsRecorder::lock_ = NULL;
465 482
466 } // namespace base 483 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_histogram_allocator.cc ('k') | chrome/browser/extensions/api/metrics_private/metrics_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698