Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Unified Diff: base/allocator/allocator_interception_mac.mm

Issue 2713553002: mac: Periodically shim new malloc zones immediately after startup. (Closed)
Patch Set: Rebase. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698