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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 568 |
569 void GlobalHistogramAllocator::ImportHistogramsToStatisticsRecorder() { | 569 void GlobalHistogramAllocator::ImportHistogramsToStatisticsRecorder() { |
570 // Skip the import if it's the histogram that was last created. Should a | 570 // Skip the import if it's the histogram that was last created. Should a |
571 // race condition cause the "last created" to be overwritten before it | 571 // race condition cause the "last created" to be overwritten before it |
572 // is recognized here then the histogram will be created and be ignored | 572 // is recognized here then the histogram will be created and be ignored |
573 // when it is detected as a duplicate by the statistics-recorder. This | 573 // when it is detected as a duplicate by the statistics-recorder. This |
574 // simple check reduces the time of creating persistent histograms by | 574 // simple check reduces the time of creating persistent histograms by |
575 // about 40%. | 575 // about 40%. |
576 Reference record_to_ignore = last_created(); | 576 Reference record_to_ignore = last_created(); |
577 | 577 |
578 // There is no lock on this because it's expected to be called only by | 578 // There is no lock on this because the iterator is lock-free while still |
579 // the StatisticsRecorder which has its own lock. | 579 // guaranteed to only return each entry only once. The StatisticsRecorder |
| 580 // has its own lock so the Register operation is safe. |
580 while (true) { | 581 while (true) { |
581 std::unique_ptr<HistogramBase> histogram = | 582 std::unique_ptr<HistogramBase> histogram = |
582 import_iterator_.GetNextWithIgnore(record_to_ignore); | 583 import_iterator_.GetNextWithIgnore(record_to_ignore); |
583 if (!histogram) | 584 if (!histogram) |
584 break; | 585 break; |
585 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); | 586 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); |
586 } | 587 } |
587 } | 588 } |
588 | 589 |
589 } // namespace base | 590 } // namespace base |
OLD | NEW |