diff options
-rw-r--r-- | base/memory/shared_memory.h | 4 | ||||
-rw-r--r-- | base/memory/shared_memory_handle.h | 3 | ||||
-rw-r--r-- | base/memory/shared_memory_mac.cc | 53 | ||||
-rw-r--r-- | content/browser/loader/resource_buffer.cc | 4 | ||||
-rw-r--r-- | tools/metrics/histograms/histograms.xml | 18 |
5 files changed, 82 insertions, 0 deletions
diff --git a/base/memory/shared_memory.h b/base/memory/shared_memory.h index 18416c0..5cdcb0d 100644 --- a/base/memory/shared_memory.h +++ b/base/memory/shared_memory.h @@ -140,6 +140,10 @@ class BASE_EXPORT SharedMemory { // http://crbug.com/466437. bool CreateAndMapAnonymousPosix(size_t size); bool CreateAnonymousPosix(size_t size); + + // This method is an analog of CreateAndMapAnonymous that forces the + // underlying OS primitive to be a Mach memory object. + bool CreateAndMapAnonymousMach(size_t size); #endif // defined(OS_MACOSX) && !defined(OS_IOS) // Creates an anonymous shared memory segment of size size. diff --git a/base/memory/shared_memory_handle.h b/base/memory/shared_memory_handle.h index b3dfc8f..49398a4 100644 --- a/base/memory/shared_memory_handle.h +++ b/base/memory/shared_memory_handle.h @@ -75,12 +75,15 @@ class BASE_EXPORT SharedMemoryHandle { #else class BASE_EXPORT SharedMemoryHandle { public: + // The values of these enums must not change, as they are used by the + // histogram OSX.SharedMemory.Mechanism. enum Type { // The SharedMemoryHandle is backed by a POSIX fd. POSIX, // The SharedMemoryHandle is backed by the Mach primitive "memory object". MACH, }; + static const int TypeMax = 2; // The format that should be used to transmit |Type| over the wire. typedef int TypeWireFormat; diff --git a/base/memory/shared_memory_mac.cc b/base/memory/shared_memory_mac.cc index 799b8e3..8f198dc 100644 --- a/base/memory/shared_memory_mac.cc +++ b/base/memory/shared_memory_mac.cc @@ -13,7 +13,10 @@ #include "base/files/file_util.h" #include "base/files/scoped_file.h" #include "base/logging.h" +#include "base/mac/mac_util.h" #include "base/mac/scoped_mach_vm.h" +#include "base/metrics/field_trial.h" +#include "base/metrics/histogram_macros.h" #include "base/posix/eintr_wrapper.h" #include "base/posix/safe_strerror.h" #include "base/process/process_metrics.h" @@ -29,6 +32,38 @@ namespace base { namespace { +const char kTrialName[] = "MacMemoryMechanism"; +const char kTrialMach[] = "Mach"; +const char kTrialPosix[] = "Posix"; + +SharedMemoryHandle::Type GetABTestMechanism() { + static bool found_group = false; + static SharedMemoryHandle::Type group = SharedMemoryHandle::MACH; + + if (found_group) + return group; + + const std::string group_name = + base::FieldTrialList::FindFullName(kTrialName); + if (group_name == kTrialMach) { + group = SharedMemoryHandle::MACH; + found_group = true; + } else if (group_name == kTrialPosix) { + group = SharedMemoryHandle::POSIX; + found_group = true; + } else { + group = SharedMemoryHandle::MACH; + } + + return group; +} + +// Emits a histogram entry indicating which type of SharedMemory was created. +void EmitMechanism(SharedMemoryHandle::Type type) { + UMA_HISTOGRAM_ENUMERATION("OSX.SharedMemory.Mechanism", type, + SharedMemoryHandle::TypeMax); +} + // Returns whether the operation succeeded. // |new_handle| is an output variable, populated on success. The caller takes // ownership of the underlying memory object. @@ -227,6 +262,22 @@ bool SharedMemory::CreateAnonymousPosix(size_t size) { return Create(options); } +bool SharedMemory::CreateAndMapAnonymousMach(size_t size) { + SharedMemoryCreateOptions options; + + if (mac::IsOSLionOrLater()) { + // A/B test the mechanism. Once the experiment is over, this will always be + // set to SharedMemoryHandle::MACH. + // http://crbug.com/547261 + options.type = GetABTestMechanism(); + } else { + // Mach shared memory isn't supported on OSX 10.6 or older. + options.type = SharedMemoryHandle::POSIX; + } + options.size = size; + return Create(options) && Map(size); +} + // static bool SharedMemory::GetSizeFromSharedMemoryHandle( const SharedMemoryHandle& handle, @@ -248,6 +299,8 @@ bool SharedMemory::Create(const SharedMemoryCreateOptions& options) { if (options.size > static_cast<size_t>(std::numeric_limits<int>::max())) return false; + EmitMechanism(options.type); + if (options.type == SharedMemoryHandle::MACH) { shm_ = SharedMemoryHandle(options.size); requested_size_ = options.size; diff --git a/content/browser/loader/resource_buffer.cc b/content/browser/loader/resource_buffer.cc index 9dc63d6..58839db 100644 --- a/content/browser/loader/resource_buffer.cc +++ b/content/browser/loader/resource_buffer.cc @@ -54,7 +54,11 @@ bool ResourceBuffer::Initialize(int buffer_size, min_alloc_size_ = min_allocation_size; max_alloc_size_ = max_allocation_size; +#if defined(OS_MACOSX) && !defined(OS_IOS) + return shared_mem_.CreateAndMapAnonymousMach(buf_size_); +#else return shared_mem_.CreateAndMapAnonymous(buf_size_); +#endif // defined(OS_MACOSX) && !defined(OS_IOS) } bool ResourceBuffer::IsInitialized() const { diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index c22de87..07469d1 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -30101,6 +30101,15 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. </summary> </histogram> +<histogram name="OSX.SharedMemory.Mechanism" enum="OSXSharedMemoryMechanism"> + <owner>erikchen@chromium.org</owner> + <summary> + A histogram entry is emitted each time a base::SharedMemory object is + constructed. The value of the entry indicates the mechanism used to back the + shared memory region. + </summary> +</histogram> + <histogram name="OSX.SystemHotkeyMap.LoadSuccess" enum="BooleanSuccess"> <owner>erikchen@chromium.org</owner> <summary> @@ -68207,6 +68216,15 @@ To add a new entry, add it with any value and run test to compute valid value. </int> </enum> +<enum name="OSXSharedMemoryMechanism" type="int"> + <int value="0" label="POSIX"> + The shared memory region is backed by a POSIX fd. + </int> + <int value="1" label="MACH"> + The shared memory region is backed by a Mach memory object. + </int> +</enum> + <enum name="OtherPossibleUsernamesUsage" type="int"> <int value="0" label="Nothing to Autofill"/> <int value="1" label="No other possible usernames"/> |