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

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

Issue 2794073002: De-duplicate ranges information in persistent memory. (Closed)
Patch Set: addressed final review comments Created 3 years, 8 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/persistent_histogram_allocator_unittest.cc ('k') | no next file » | 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 <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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 // static 424 // static
425 size_t StatisticsRecorder::GetHistogramCount() { 425 size_t StatisticsRecorder::GetHistogramCount() {
426 base::AutoLock auto_lock(lock_.Get()); 426 base::AutoLock auto_lock(lock_.Get());
427 if (!histograms_) 427 if (!histograms_)
428 return 0; 428 return 0;
429 return histograms_->size(); 429 return histograms_->size();
430 } 430 }
431 431
432 // static 432 // static
433 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) { 433 void StatisticsRecorder::ForgetHistogramForTesting(base::StringPiece name) {
434 if (histograms_) 434 if (!histograms_)
435 histograms_->erase(name); 435 return;
436
437 HistogramMap::iterator found = histograms_->find(name);
438 if (found == histograms_->end())
439 return;
440
441 HistogramBase* base = found->second;
442 if (base->GetHistogramType() != SPARSE_HISTOGRAM) {
443 // When forgetting a histogram, it's likely that other information is
444 // also becoming invalid. Clear the persistent reference that may no
445 // longer be valid. There's no danger in this as, at worst, duplicates
446 // will be created in persistent memory.
447 Histogram* histogram = static_cast<Histogram*>(base);
448 histogram->bucket_ranges()->set_persistent_reference(0);
449 }
450
451 histograms_->erase(found);
436 } 452 }
437 453
438 // static 454 // static
439 std::unique_ptr<StatisticsRecorder> 455 std::unique_ptr<StatisticsRecorder>
440 StatisticsRecorder::CreateTemporaryForTesting() { 456 StatisticsRecorder::CreateTemporaryForTesting() {
441 return WrapUnique(new StatisticsRecorder()); 457 return WrapUnique(new StatisticsRecorder());
442 } 458 }
443 459
444 // static 460 // static
445 void StatisticsRecorder::UninitializeForTesting() { 461 void StatisticsRecorder::UninitializeForTesting() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = nullptr; 549 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = nullptr;
534 // static 550 // static
535 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = nullptr; 551 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = nullptr;
536 // static 552 // static
537 StatisticsRecorder::HistogramProviders* StatisticsRecorder::providers_; 553 StatisticsRecorder::HistogramProviders* StatisticsRecorder::providers_;
538 // static 554 // static
539 base::LazyInstance<base::Lock>::Leaky StatisticsRecorder::lock_ = 555 base::LazyInstance<base::Lock>::Leaky StatisticsRecorder::lock_ =
540 LAZY_INSTANCE_INITIALIZER; 556 LAZY_INSTANCE_INITIALIZER;
541 557
542 } // namespace base 558 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/persistent_histogram_allocator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698