Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/persistent_histogram_allocator.h" | 5 #include "base/metrics/persistent_histogram_allocator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 890 // be open elsewhere. Open handles will continue to operate normally but | 890 // be open elsewhere. Open handles will continue to operate normally but |
| 891 // new opens will not be possible. | 891 // new opens will not be possible. |
| 892 File file(persistent_location_, | 892 File file(persistent_location_, |
| 893 File::FLAG_OPEN | File::FLAG_READ | File::FLAG_DELETE_ON_CLOSE); | 893 File::FLAG_OPEN | File::FLAG_READ | File::FLAG_DELETE_ON_CLOSE); |
| 894 #endif | 894 #endif |
| 895 } | 895 } |
| 896 | 896 |
| 897 GlobalHistogramAllocator::GlobalHistogramAllocator( | 897 GlobalHistogramAllocator::GlobalHistogramAllocator( |
| 898 std::unique_ptr<PersistentMemoryAllocator> memory) | 898 std::unique_ptr<PersistentMemoryAllocator> memory) |
| 899 : PersistentHistogramAllocator(std::move(memory)), | 899 : PersistentHistogramAllocator(std::move(memory)), |
| 900 import_iterator_(this) {} | 900 import_iterator_(this) { |
| 901 StatisticsRecorder::Initialize(); | |
|
bcwhite
2016/09/21 19:35:11
Let's add a comment:
Make sure the StatisticsReco
scottmg
2016/09/21 19:37:56
Done.
| |
| 902 } | |
| 901 | 903 |
| 902 void GlobalHistogramAllocator::ImportHistogramsToStatisticsRecorder() { | 904 void GlobalHistogramAllocator::ImportHistogramsToStatisticsRecorder() { |
| 903 // Skip the import if it's the histogram that was last created. Should a | 905 // Skip the import if it's the histogram that was last created. Should a |
| 904 // race condition cause the "last created" to be overwritten before it | 906 // race condition cause the "last created" to be overwritten before it |
| 905 // is recognized here then the histogram will be created and be ignored | 907 // is recognized here then the histogram will be created and be ignored |
| 906 // when it is detected as a duplicate by the statistics-recorder. This | 908 // when it is detected as a duplicate by the statistics-recorder. This |
| 907 // simple check reduces the time of creating persistent histograms by | 909 // simple check reduces the time of creating persistent histograms by |
| 908 // about 40%. | 910 // about 40%. |
| 909 Reference record_to_ignore = last_created(); | 911 Reference record_to_ignore = last_created(); |
| 910 | 912 |
| 911 // There is no lock on this because the iterator is lock-free while still | 913 // There is no lock on this because the iterator is lock-free while still |
| 912 // guaranteed to only return each entry only once. The StatisticsRecorder | 914 // guaranteed to only return each entry only once. The StatisticsRecorder |
| 913 // has its own lock so the Register operation is safe. | 915 // has its own lock so the Register operation is safe. |
| 914 while (true) { | 916 while (true) { |
| 915 std::unique_ptr<HistogramBase> histogram = | 917 std::unique_ptr<HistogramBase> histogram = |
| 916 import_iterator_.GetNextWithIgnore(record_to_ignore); | 918 import_iterator_.GetNextWithIgnore(record_to_ignore); |
| 917 if (!histogram) | 919 if (!histogram) |
| 918 break; | 920 break; |
| 919 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); | 921 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); |
| 920 } | 922 } |
| 921 } | 923 } |
| 922 | 924 |
| 923 } // namespace base | 925 } // namespace base |
| OLD | NEW |