| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 StatisticsRecorder::HistogramIterator StatisticsRecorder::end() { | 330 StatisticsRecorder::HistogramIterator StatisticsRecorder::end() { |
| 331 HistogramMap::iterator iter_end; | 331 HistogramMap::iterator iter_end; |
| 332 { | 332 { |
| 333 base::AutoLock auto_lock(*lock_); | 333 base::AutoLock auto_lock(*lock_); |
| 334 iter_end = histograms_->end(); | 334 iter_end = histograms_->end(); |
| 335 } | 335 } |
| 336 return HistogramIterator(iter_end, true); | 336 return HistogramIterator(iter_end, true); |
| 337 } | 337 } |
| 338 | 338 |
| 339 // static | 339 // static |
| 340 void StatisticsRecorder::InitLogOnShutdown() { |
| 341 if (lock_ == nullptr) |
| 342 return; |
| 343 base::AutoLock auto_lock(*lock_); |
| 344 g_statistics_recorder_.Get().InitLogOnShutdownWithoutLock(); |
| 345 } |
| 346 |
| 347 // static |
| 340 void StatisticsRecorder::GetSnapshot(const std::string& query, | 348 void StatisticsRecorder::GetSnapshot(const std::string& query, |
| 341 Histograms* snapshot) { | 349 Histograms* snapshot) { |
| 342 if (lock_ == NULL) | 350 if (lock_ == NULL) |
| 343 return; | 351 return; |
| 344 base::AutoLock auto_lock(*lock_); | 352 base::AutoLock auto_lock(*lock_); |
| 345 if (histograms_ == NULL) | 353 if (histograms_ == NULL) |
| 346 return; | 354 return; |
| 347 | 355 |
| 348 for (const auto& entry : *histograms_) { | 356 for (const auto& entry : *histograms_) { |
| 349 if (entry.second->histogram_name().find(query) != std::string::npos) | 357 if (entry.second->histogram_name().find(query) != std::string::npos) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 base::AutoLock auto_lock(*lock_); | 476 base::AutoLock auto_lock(*lock_); |
| 469 | 477 |
| 470 existing_histograms_.reset(histograms_); | 478 existing_histograms_.reset(histograms_); |
| 471 existing_callbacks_.reset(callbacks_); | 479 existing_callbacks_.reset(callbacks_); |
| 472 existing_ranges_.reset(ranges_); | 480 existing_ranges_.reset(ranges_); |
| 473 | 481 |
| 474 histograms_ = new HistogramMap; | 482 histograms_ = new HistogramMap; |
| 475 callbacks_ = new CallbackMap; | 483 callbacks_ = new CallbackMap; |
| 476 ranges_ = new RangesMap; | 484 ranges_ = new RangesMap; |
| 477 | 485 |
| 478 if (VLOG_IS_ON(1)) | 486 InitLogOnShutdownWithoutLock(); |
| 487 } |
| 488 |
| 489 void StatisticsRecorder::InitLogOnShutdownWithoutLock() { |
| 490 if (!vlog_initialized_ && VLOG_IS_ON(1)) { |
| 491 vlog_initialized_ = true; |
| 479 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); | 492 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); |
| 493 } |
| 480 } | 494 } |
| 481 | 495 |
| 482 // static | 496 // static |
| 483 void StatisticsRecorder::Reset() { | 497 void StatisticsRecorder::Reset() { |
| 484 // If there's no lock then there is nothing to reset. | 498 // If there's no lock then there is nothing to reset. |
| 485 if (!lock_) | 499 if (!lock_) |
| 486 return; | 500 return; |
| 487 | 501 |
| 488 std::unique_ptr<HistogramMap> histograms_deleter; | 502 std::unique_ptr<HistogramMap> histograms_deleter; |
| 489 std::unique_ptr<CallbackMap> callbacks_deleter; | 503 std::unique_ptr<CallbackMap> callbacks_deleter; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 513 // static | 527 // static |
| 514 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; | 528 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; |
| 515 // static | 529 // static |
| 516 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; | 530 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; |
| 517 // static | 531 // static |
| 518 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; | 532 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; |
| 519 // static | 533 // static |
| 520 base::Lock* StatisticsRecorder::lock_ = NULL; | 534 base::Lock* StatisticsRecorder::lock_ = NULL; |
| 521 | 535 |
| 522 } // namespace base | 536 } // namespace base |
| OLD | NEW |