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" |
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
778 } | 778 } |
779 if (out_active_path) { | 779 if (out_active_path) { |
780 *out_active_path = | 780 *out_active_path = |
781 dir.AppendASCII(name.as_string() + std::string("-active")) | 781 dir.AppendASCII(name.as_string() + std::string("-active")) |
782 .AddExtension(PersistentMemoryAllocator::kFileExtension); | 782 .AddExtension(PersistentMemoryAllocator::kFileExtension); |
783 } | 783 } |
784 } | 784 } |
785 #endif // !defined(OS_NACL) | 785 #endif // !defined(OS_NACL) |
786 | 786 |
787 // static | 787 // static |
788 void GlobalHistogramAllocator::CreateWithSharedMemory( | 788 void GlobalHistogramAllocator::CreateWithSharedMemory( |
Ilya Sherman
2017/03/06 19:03:19
If you really want to keep this method around, cou
| |
789 std::unique_ptr<SharedMemory> memory, | 789 std::unique_ptr<SharedMemory> memory, |
790 size_t size, | 790 size_t size, |
791 uint64_t id, | 791 uint64_t id, |
792 StringPiece name) { | 792 StringPiece name) { |
793 if ((!memory->memory() && !memory->Map(size)) || | 793 if ((!memory->memory() && !memory->Map(size)) || |
794 !SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable(*memory)) { | 794 !SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable(*memory)) { |
795 NOTREACHED(); | 795 NOTREACHED(); |
796 return; | 796 return; |
797 } | 797 } |
798 | 798 |
799 DCHECK_LE(memory->mapped_size(), size); | 799 DCHECK_LE(memory->mapped_size(), size); |
800 Set(WrapUnique( | 800 Set(WrapUnique( |
801 new GlobalHistogramAllocator(MakeUnique<SharedPersistentMemoryAllocator>( | 801 new GlobalHistogramAllocator(MakeUnique<SharedPersistentMemoryAllocator>( |
802 std::move(memory), 0, StringPiece(), /*readonly=*/false)))); | 802 std::move(memory), id, name, /*readonly=*/false)))); |
803 } | 803 } |
804 | 804 |
805 // static | 805 // static |
806 void GlobalHistogramAllocator::CreateWithSharedMemoryHandle( | 806 void GlobalHistogramAllocator::CreateWithSharedMemoryHandle( |
807 const SharedMemoryHandle& handle, | 807 const SharedMemoryHandle& handle, |
808 size_t size) { | 808 size_t size) { |
809 std::unique_ptr<SharedMemory> shm( | 809 std::unique_ptr<SharedMemory> shm( |
810 new SharedMemory(handle, /*readonly=*/false)); | 810 new SharedMemory(handle, /*readonly=*/false)); |
811 if (!shm->Map(size) || | 811 CreateWithSharedMemory(std::move(shm), size, 0, StringPiece()); |
812 !SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable(*shm)) { | |
813 NOTREACHED(); | |
814 return; | |
815 } | |
816 | |
817 Set(WrapUnique( | |
818 new GlobalHistogramAllocator(MakeUnique<SharedPersistentMemoryAllocator>( | |
819 std::move(shm), 0, StringPiece(), /*readonly=*/false)))); | |
820 } | 812 } |
821 | 813 |
822 // static | 814 // static |
823 void GlobalHistogramAllocator::Set( | 815 void GlobalHistogramAllocator::Set( |
824 std::unique_ptr<GlobalHistogramAllocator> allocator) { | 816 std::unique_ptr<GlobalHistogramAllocator> allocator) { |
825 // Releasing or changing an allocator is extremely dangerous because it | 817 // Releasing or changing an allocator is extremely dangerous because it |
826 // likely has histograms stored within it. If the backing memory is also | 818 // likely has histograms stored within it. If the backing memory is also |
827 // also released, future accesses to those histograms will seg-fault. | 819 // also released, future accesses to those histograms will seg-fault. |
828 CHECK(!subtle::NoBarrier_Load(&g_allocator)); | 820 CHECK(!subtle::NoBarrier_Load(&g_allocator)); |
829 subtle::Release_Store(&g_allocator, | 821 subtle::Release_Store(&g_allocator, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 while (true) { | 936 while (true) { |
945 std::unique_ptr<HistogramBase> histogram = | 937 std::unique_ptr<HistogramBase> histogram = |
946 import_iterator_.GetNextWithIgnore(record_to_ignore); | 938 import_iterator_.GetNextWithIgnore(record_to_ignore); |
947 if (!histogram) | 939 if (!histogram) |
948 break; | 940 break; |
949 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); | 941 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); |
950 } | 942 } |
951 } | 943 } |
952 | 944 |
953 } // namespace base | 945 } // namespace base |
OLD | NEW |