| Index: base/allocator/allocator_interception_mac.mm
|
| diff --git a/base/allocator/allocator_interception_mac.mm b/base/allocator/allocator_interception_mac.mm
|
| index 87c882a19cb8e5214610857237c50f8a6db41659..e155b971d1cbd9914c4f0ece970d7c0244c248a2 100644
|
| --- a/base/allocator/allocator_interception_mac.mm
|
| +++ b/base/allocator/allocator_interception_mac.mm
|
| @@ -30,11 +30,15 @@
|
| #include "base/allocator/allocator_shim.h"
|
| #include "base/allocator/features.h"
|
| #include "base/allocator/malloc_zone_functions_mac.h"
|
| +#include "base/base_switches.h"
|
| +#include "base/bind.h"
|
| +#include "base/command_line.h"
|
| #include "base/logging.h"
|
| #include "base/mac/mac_util.h"
|
| #include "base/mac/mach_logging.h"
|
| #include "base/process/memory.h"
|
| #include "base/scoped_clear_errno.h"
|
| +#include "base/threading/sequenced_task_runner_handle.h"
|
| #include "build/build_config.h"
|
| #include "third_party/apple_apsl/CFBase.h"
|
|
|
| @@ -498,5 +502,41 @@ void InterceptAllocationsMac() {
|
| reinterpret_cast<IMP>(oom_killer_allocWithZone));
|
| }
|
|
|
| +namespace {
|
| +
|
| +void ShimNewMallocZones(base::Time end_time, base::TimeDelta delay) {
|
| + StoreFunctionsForAllZones();
|
| +
|
| + // Use the functions for the default zone as a template to replace those
|
| + // new zones.
|
| + ChromeMallocZone* default_zone =
|
| + reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
|
| + DCHECK(IsMallocZoneAlreadyStored(default_zone));
|
| +
|
| + MallocZoneFunctions new_functions;
|
| + StoreZoneFunctions(default_zone, &new_functions);
|
| + ReplaceFunctionsForStoredZones(&new_functions);
|
| +
|
| + if (base::Time::Now() > end_time)
|
| + return;
|
| +
|
| + base::TimeDelta next_delay = delay * 2;
|
| + SequencedTaskRunnerHandle::Get()->PostDelayedTask(
|
| + FROM_HERE, base::Bind(&ShimNewMallocZones, end_time, next_delay), delay);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +void PeriodicallyShimNewMallocZones() {
|
| + if (!CommandLine::InitializedForCurrentProcess() ||
|
| + !CommandLine::ForCurrentProcess()->HasSwitch(
|
| + switches::kEnableHeapProfiling)) {
|
| + return;
|
| + }
|
| + base::Time end_time = base::Time::Now() + base::TimeDelta::FromMinutes(1);
|
| + base::TimeDelta initial_delay = base::TimeDelta::FromSeconds(1);
|
| + ShimNewMallocZones(end_time, initial_delay);
|
| +}
|
| +
|
| } // namespace allocator
|
| } // namespace base
|
|
|