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

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

Issue 1748403003: Log histograms on shutdown when verbose logging is on (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added comment and friend Created 4 years, 5 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 <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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 StatisticsRecorder::HistogramIterator StatisticsRecorder::end() { 331 StatisticsRecorder::HistogramIterator StatisticsRecorder::end() {
332 HistogramMap::iterator iter_end; 332 HistogramMap::iterator iter_end;
333 { 333 {
334 base::AutoLock auto_lock(*lock_); 334 base::AutoLock auto_lock(*lock_);
335 iter_end = histograms_->end(); 335 iter_end = histograms_->end();
336 } 336 }
337 return HistogramIterator(iter_end, true); 337 return HistogramIterator(iter_end, true);
338 } 338 }
339 339
340 // static 340 // static
341 void StatisticsRecorder::InitLogOnShutdown() {
342 if (lock_ == nullptr)
343 return;
344 base::AutoLock auto_lock(*lock_);
345 g_statistics_recorder_.Get().InitLogOnShutdownWithoutLock();
346 }
347
348 // static
341 void StatisticsRecorder::GetSnapshot(const std::string& query, 349 void StatisticsRecorder::GetSnapshot(const std::string& query,
342 Histograms* snapshot) { 350 Histograms* snapshot) {
343 if (lock_ == NULL) 351 if (lock_ == NULL)
344 return; 352 return;
345 base::AutoLock auto_lock(*lock_); 353 base::AutoLock auto_lock(*lock_);
346 if (histograms_ == NULL) 354 if (histograms_ == NULL)
347 return; 355 return;
348 356
349 for (const auto& entry : *histograms_) { 357 for (const auto& entry : *histograms_) {
350 if (entry.second->histogram_name().find(query) != std::string::npos) 358 if (entry.second->histogram_name().find(query) != std::string::npos)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 base::AutoLock auto_lock(*lock_); 483 base::AutoLock auto_lock(*lock_);
476 484
477 existing_histograms_.reset(histograms_); 485 existing_histograms_.reset(histograms_);
478 existing_callbacks_.reset(callbacks_); 486 existing_callbacks_.reset(callbacks_);
479 existing_ranges_.reset(ranges_); 487 existing_ranges_.reset(ranges_);
480 488
481 histograms_ = new HistogramMap; 489 histograms_ = new HistogramMap;
482 callbacks_ = new CallbackMap; 490 callbacks_ = new CallbackMap;
483 ranges_ = new RangesMap; 491 ranges_ = new RangesMap;
484 492
485 if (VLOG_IS_ON(1)) 493 InitLogOnShutdownWithoutLock();
494 }
495
496 void StatisticsRecorder::InitLogOnShutdownWithoutLock() {
497 if (!vlog_initialized_ && VLOG_IS_ON(1)) {
498 vlog_initialized_ = true;
486 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); 499 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this);
500 }
487 } 501 }
488 502
489 // static 503 // static
490 void StatisticsRecorder::Reset() { 504 void StatisticsRecorder::Reset() {
491 // If there's no lock then there is nothing to reset. 505 // If there's no lock then there is nothing to reset.
492 if (!lock_) 506 if (!lock_)
493 return; 507 return;
494 508
495 std::unique_ptr<HistogramMap> histograms_deleter; 509 std::unique_ptr<HistogramMap> histograms_deleter;
496 std::unique_ptr<CallbackMap> callbacks_deleter; 510 std::unique_ptr<CallbackMap> callbacks_deleter;
(...skipping 23 matching lines...) Expand all
520 // static 534 // static
521 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 535 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
522 // static 536 // static
523 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; 537 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL;
524 // static 538 // static
525 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; 539 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL;
526 // static 540 // static
527 base::Lock* StatisticsRecorder::lock_ = NULL; 541 base::Lock* StatisticsRecorder::lock_ = NULL;
528 542
529 } // namespace base 543 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698