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/atomicops.h" | 9 #include "base/atomicops.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/important_file_writer.h" | 12 #include "base/files/important_file_writer.h" |
| 13 #include "base/files/memory_mapped_file.h" | 13 #include "base/files/memory_mapped_file.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/metrics/histogram_base.h" | 18 #include "base/metrics/histogram_base.h" |
| 19 #include "base/metrics/histogram_samples.h" | 19 #include "base/metrics/histogram_samples.h" |
| 20 #include "base/metrics/persistent_sample_map.h" | 20 #include "base/metrics/persistent_sample_map.h" |
| 21 #include "base/metrics/sparse_histogram.h" | 21 #include "base/metrics/sparse_histogram.h" |
| 22 #include "base/metrics/statistics_recorder.h" | 22 #include "base/metrics/statistics_recorder.h" |
| 23 #include "base/pickle.h" | 23 #include "base/pickle.h" |
| 24 #include "base/strings/stringprintf.h" | |
| 24 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
| 25 | 26 |
| 26 namespace base { | 27 namespace base { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 // Name of histogram for storing results of local operations. | 31 // Name of histogram for storing results of local operations. |
| 31 const char kResultHistogram[] = "UMA.CreatePersistentHistogram.Result"; | 32 const char kResultHistogram[] = "UMA.CreatePersistentHistogram.Result"; |
| 32 | 33 |
| 33 // Type identifiers used when storing in persistent memory so they can be | 34 // Type identifiers used when storing in persistent memory so they can be |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 .AddExtension(PersistentMemoryAllocator::kFileExtension); | 830 .AddExtension(PersistentMemoryAllocator::kFileExtension); |
| 830 } | 831 } |
| 831 if (out_spare_path) { | 832 if (out_spare_path) { |
| 832 *out_spare_path = | 833 *out_spare_path = |
| 833 dir.AppendASCII(name.as_string() + std::string("-spare")) | 834 dir.AppendASCII(name.as_string() + std::string("-spare")) |
| 834 .AddExtension(PersistentMemoryAllocator::kFileExtension); | 835 .AddExtension(PersistentMemoryAllocator::kFileExtension); |
| 835 } | 836 } |
| 836 } | 837 } |
| 837 | 838 |
| 838 // static | 839 // static |
| 840 void GlobalHistogramAllocator::ConstructFilePathsForUploadDir( | |
| 841 const FilePath& active_dir, | |
| 842 const FilePath& upload_dir, | |
| 843 const std::string& name, | |
| 844 FilePath* out_upload_path, | |
| 845 FilePath* out_active_path, | |
| 846 FilePath* out_spare_path) { | |
| 847 if (out_upload_path) { | |
| 848 std::string name_stamp = | |
| 849 StringPrintf("%s-%X", name.c_str(), | |
| 850 static_cast<unsigned int>(Time::Now().ToTimeT())); | |
| 851 *out_upload_path = | |
| 852 upload_dir.AppendASCII(name_stamp) | |
| 853 .AddExtension(PersistentMemoryAllocator::kFileExtension); | |
|
Alexei Svitkine (slow)
2017/06/28 17:30:35
Nit: Given this pattern is used a lot, make a help
bcwhite
2017/06/28 18:52:08
Done.
| |
| 854 } | |
| 855 if (out_active_path) { | |
| 856 *out_active_path = | |
| 857 active_dir.AppendASCII(name + std::string("-active")) | |
| 858 .AddExtension(PersistentMemoryAllocator::kFileExtension); | |
| 859 } | |
| 860 if (out_spare_path) { | |
| 861 *out_spare_path = | |
| 862 active_dir.AppendASCII(name + std::string("-spare")) | |
| 863 .AddExtension(PersistentMemoryAllocator::kFileExtension); | |
| 864 } | |
| 865 } | |
| 866 | |
| 867 // static | |
| 839 bool GlobalHistogramAllocator::CreateSpareFile(const FilePath& spare_path, | 868 bool GlobalHistogramAllocator::CreateSpareFile(const FilePath& spare_path, |
| 840 size_t size) { | 869 size_t size) { |
| 841 FilePath temp_spare_path = spare_path.AddExtension(FILE_PATH_LITERAL(".tmp")); | 870 FilePath temp_spare_path = spare_path.AddExtension(FILE_PATH_LITERAL(".tmp")); |
| 842 bool success = true; | 871 bool success = true; |
| 843 { | 872 { |
| 844 File spare_file(temp_spare_path, File::FLAG_CREATE_ALWAYS | | 873 File spare_file(temp_spare_path, File::FLAG_CREATE_ALWAYS | |
| 845 File::FLAG_READ | File::FLAG_WRITE); | 874 File::FLAG_READ | File::FLAG_WRITE); |
| 846 if (!spare_file.IsValid()) | 875 if (!spare_file.IsValid()) |
| 847 return false; | 876 return false; |
| 848 | 877 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1015 while (true) { | 1044 while (true) { |
| 1016 std::unique_ptr<HistogramBase> histogram = | 1045 std::unique_ptr<HistogramBase> histogram = |
| 1017 import_iterator_.GetNextWithIgnore(record_to_ignore); | 1046 import_iterator_.GetNextWithIgnore(record_to_ignore); |
| 1018 if (!histogram) | 1047 if (!histogram) |
| 1019 break; | 1048 break; |
| 1020 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); | 1049 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); |
| 1021 } | 1050 } |
| 1022 } | 1051 } |
| 1023 | 1052 |
| 1024 } // namespace base | 1053 } // namespace base |
| OLD | NEW |