| OLD | NEW |
| 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" | |
| 9 #include "base/debug/leak_annotations.h" | 8 #include "base/debug/leak_annotations.h" |
| 10 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 14 #include "base/metrics/metrics_hashes.h" | 13 #include "base/metrics/metrics_hashes.h" |
| 15 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 17 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 18 #include "base/values.h" | 17 #include "base/values.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 histogram->SetFlags(HistogramBase::kCallbackExists); | 116 histogram->SetFlags(HistogramBase::kCallbackExists); |
| 118 else | 117 else |
| 119 histogram->ClearFlags(HistogramBase::kCallbackExists); | 118 histogram->ClearFlags(HistogramBase::kCallbackExists); |
| 120 } | 119 } |
| 121 histogram_to_return = histogram; | 120 histogram_to_return = histogram; |
| 122 } else if (histogram == it->second) { | 121 } else if (histogram == it->second) { |
| 123 // The histogram was registered before. | 122 // The histogram was registered before. |
| 124 histogram_to_return = histogram; | 123 histogram_to_return = histogram; |
| 125 } else { | 124 } else { |
| 126 // We already have one histogram with this name. | 125 // We already have one histogram with this name. |
| 127 CHECK_EQ(histogram->histogram_name(), | 126 DCHECK_EQ(histogram->histogram_name(), |
| 128 it->second->histogram_name()) << "hash collision"; | 127 it->second->histogram_name()) << "hash collision"; |
| 129 histogram_to_return = it->second; | 128 histogram_to_return = it->second; |
| 130 histogram_to_delete = histogram; | 129 histogram_to_delete = histogram; |
| 131 } | 130 } |
| 132 base::debug::Alias(&it); | |
| 133 base::debug::Alias(&name); | |
| 134 base::debug::Alias(&name_hash); | |
| 135 } | 131 } |
| 136 } | 132 } |
| 137 base::debug::Alias(&histogram); | |
| 138 delete histogram_to_delete; | 133 delete histogram_to_delete; |
| 139 return histogram_to_return; | 134 return histogram_to_return; |
| 140 } | 135 } |
| 141 | 136 |
| 142 // static | 137 // static |
| 143 const BucketRanges* StatisticsRecorder::RegisterOrDeleteDuplicateRanges( | 138 const BucketRanges* StatisticsRecorder::RegisterOrDeleteDuplicateRanges( |
| 144 const BucketRanges* ranges) { | 139 const BucketRanges* ranges) { |
| 145 DCHECK(ranges->HasValidChecksum()); | 140 DCHECK(ranges->HasValidChecksum()); |
| 146 scoped_ptr<const BucketRanges> ranges_deleter; | 141 scoped_ptr<const BucketRanges> ranges_deleter; |
| 147 | 142 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 272 } |
| 278 | 273 |
| 279 // static | 274 // static |
| 280 HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) { | 275 HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) { |
| 281 if (lock_ == NULL) | 276 if (lock_ == NULL) |
| 282 return NULL; | 277 return NULL; |
| 283 base::AutoLock auto_lock(*lock_); | 278 base::AutoLock auto_lock(*lock_); |
| 284 if (histograms_ == NULL) | 279 if (histograms_ == NULL) |
| 285 return NULL; | 280 return NULL; |
| 286 | 281 |
| 287 const uint64_t lookup_hash = HashMetricName(name); | 282 HistogramMap::iterator it = histograms_->find(HashMetricName(name)); |
| 288 HistogramMap::iterator it = histograms_->find(lookup_hash); | |
| 289 if (histograms_->end() == it) | 283 if (histograms_->end() == it) |
| 290 return NULL; | 284 return NULL; |
| 291 | 285 DCHECK_EQ(name, it->second->histogram_name()) << "hash collision"; |
| 292 const uint64_t existing_hash = it->first; | |
| 293 const char* existing_name = it->second->histogram_name().c_str(); | |
| 294 HistogramMap* histograms = histograms_; | |
| 295 CHECK_EQ(name, it->second->histogram_name()) << "hash collision"; | |
| 296 base::debug::Alias(&lookup_hash); | |
| 297 base::debug::Alias(&existing_hash); | |
| 298 base::debug::Alias(&name); | |
| 299 base::debug::Alias(&existing_name); | |
| 300 base::debug::Alias(&it); | |
| 301 base::debug::Alias(&histograms); | |
| 302 | |
| 303 return it->second; | 286 return it->second; |
| 304 } | 287 } |
| 305 | 288 |
| 306 // static | 289 // static |
| 307 StatisticsRecorder::HistogramIterator StatisticsRecorder::begin( | 290 StatisticsRecorder::HistogramIterator StatisticsRecorder::begin( |
| 308 bool include_persistent) { | 291 bool include_persistent) { |
| 309 return HistogramIterator(histograms_->begin(), include_persistent); | 292 return HistogramIterator(histograms_->begin(), include_persistent); |
| 310 } | 293 } |
| 311 | 294 |
| 312 // static | 295 // static |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 // static | 444 // static |
| 462 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 445 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
| 463 // static | 446 // static |
| 464 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; | 447 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; |
| 465 // static | 448 // static |
| 466 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 449 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
| 467 // static | 450 // static |
| 468 base::Lock* StatisticsRecorder::lock_ = NULL; | 451 base::Lock* StatisticsRecorder::lock_ = NULL; |
| 469 | 452 |
| 470 } // namespace base | 453 } // namespace base |
| OLD | NEW |