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

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

Issue 1726873002: Report histogram creation results. (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
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | chrome/installer/setup/installer_metrics.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/leak_annotations.h" 8 #include "base/debug/leak_annotations.h"
9 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 if (!include_persistent_ && (iter_->second->flags() & 60 if (!include_persistent_ && (iter_->second->flags() &
61 HistogramBase::kIsPersistent)) { 61 HistogramBase::kIsPersistent)) {
62 continue; 62 continue;
63 } 63 }
64 break; 64 break;
65 } 65 }
66 66
67 return *this; 67 return *this;
68 } 68 }
69 69
70 StatisticsRecorder::~StatisticsRecorder() {
71 DCHECK(lock_);
72 DCHECK(histograms_);
73 DCHECK(ranges_);
74
75 // Global clean up.
76 Reset();
77 }
78
70 // static 79 // static
71 void StatisticsRecorder::Initialize() { 80 void StatisticsRecorder::Initialize() {
72 // Ensure that an instance of the StatisticsRecorder object is created. 81 // Ensure that an instance of the StatisticsRecorder object is created.
73 g_statistics_recorder_.Get(); 82 g_statistics_recorder_.Get();
74 } 83 }
75 84
76 // static 85 // static
77 bool StatisticsRecorder::IsActive() { 86 bool StatisticsRecorder::IsActive() {
78 if (lock_ == NULL) 87 if (lock_ == NULL)
79 return false; 88 return false;
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 base::AutoLock auto_lock(*lock_); 371 base::AutoLock auto_lock(*lock_);
363 if (histograms_ == NULL) 372 if (histograms_ == NULL)
364 return OnSampleCallback(); 373 return OnSampleCallback();
365 374
366 auto callback_iterator = callbacks_->find(name); 375 auto callback_iterator = callbacks_->find(name);
367 return callback_iterator != callbacks_->end() ? callback_iterator->second 376 return callback_iterator != callbacks_->end() ? callback_iterator->second
368 : OnSampleCallback(); 377 : OnSampleCallback();
369 } 378 }
370 379
371 // static 380 // static
381 size_t StatisticsRecorder::GetHistogramCount() {
382 if (!lock_)
383 return 0;
384
385 base::AutoLock auto_lock(*lock_);
386 if (!histograms_)
387 return 0;
388 return histograms_->size();
389 }
390
391 // static
372 void StatisticsRecorder::ResetForTesting() { 392 void StatisticsRecorder::ResetForTesting() {
373 // Just call the private version that is used also by the destructor. 393 // Just call the private version that is used also by the destructor.
374 Reset(); 394 Reset();
375 } 395 }
376 396
377 // static 397 // static
378 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { 398 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) {
379 if (histograms_) 399 if (histograms_)
380 histograms_->erase(HashMetricName(name.as_string())); 400 histograms_->erase(HashMetricName(name.as_string()));
381 } 401 }
(...skipping 14 matching lines...) Expand all
396 } 416 }
397 base::AutoLock auto_lock(*lock_); 417 base::AutoLock auto_lock(*lock_);
398 histograms_ = new HistogramMap; 418 histograms_ = new HistogramMap;
399 callbacks_ = new CallbackMap; 419 callbacks_ = new CallbackMap;
400 ranges_ = new RangesMap; 420 ranges_ = new RangesMap;
401 421
402 if (VLOG_IS_ON(1)) 422 if (VLOG_IS_ON(1))
403 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this); 423 AtExitManager::RegisterCallback(&DumpHistogramsToVlog, this);
404 } 424 }
405 425
406 StatisticsRecorder::~StatisticsRecorder() {
407 DCHECK(histograms_ && ranges_ && lock_);
408
409 // Global clean up.
410 Reset();
411 }
412
413 // static 426 // static
414 void StatisticsRecorder::Reset() { 427 void StatisticsRecorder::Reset() {
415 // If there's no lock then there is nothing to reset. 428 // If there's no lock then there is nothing to reset.
416 if (!lock_) 429 if (!lock_)
417 return; 430 return;
418 431
419 scoped_ptr<HistogramMap> histograms_deleter; 432 scoped_ptr<HistogramMap> histograms_deleter;
420 scoped_ptr<CallbackMap> callbacks_deleter; 433 scoped_ptr<CallbackMap> callbacks_deleter;
421 scoped_ptr<RangesMap> ranges_deleter; 434 scoped_ptr<RangesMap> ranges_deleter;
422 // We don't delete lock_ on purpose to avoid having to properly protect 435 // We don't delete lock_ on purpose to avoid having to properly protect
(...skipping 21 matching lines...) Expand all
444 // static 457 // static
445 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 458 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
446 // static 459 // static
447 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; 460 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL;
448 // static 461 // static
449 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; 462 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL;
450 // static 463 // static
451 base::Lock* StatisticsRecorder::lock_ = NULL; 464 base::Lock* StatisticsRecorder::lock_ = NULL;
452 465
453 } // namespace base 466 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/statistics_recorder.h ('k') | chrome/installer/setup/installer_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698