Skip to content

Commit

Permalink
Only enable heap tracking under --enable-heap-profiling=task-profiler.
Browse files Browse the repository at this point in the history
BUG=692045

Review-Url: https://codereview.chromium.org/2695013005
Cr-Commit-Position: refs/heads/master@{#450984}
  • Loading branch information
sigurasg authored and Commit bot committed Feb 16, 2017
1 parent 6ac59c8 commit 014a801
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
6 changes: 6 additions & 0 deletions base/base_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const char kEnableHeapProfiling[] = "enable-heap-profiling";
// derived from trace events are reported.
const char kEnableHeapProfilingModeNative[] = "native";

// Report per-task heap usage and churn in the task profiler.
// Does not keep track of individual allocations unlike the default and native
// mode. Keeps only track of summarized churn stats in the task profiler
// (chrome://profiler).
const char kEnableHeapProfilingTaskProfiler[] = "task-profiler";

// Generates full memory crash dump.
const char kFullMemoryCrashReport[] = "full-memory-crash-report";

Expand Down
1 change: 1 addition & 0 deletions base/base_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern const char kDisableLowEndDeviceMode[];
extern const char kEnableCrashReporter[];
extern const char kEnableHeapProfiling[];
extern const char kEnableHeapProfilingModeNative[];
extern const char kEnableHeapProfilingTaskProfiler[];
extern const char kEnableLowEndDeviceMode[];
extern const char kForceFieldTrials[];
extern const char kFullMemoryCrashReport[];
Expand Down
15 changes: 9 additions & 6 deletions base/trace_event/memory_dump_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "base/compiler_specific.h"
#include "base/debug/debugging_flags.h"
#include "base/debug/stack_trace.h"
#include "base/debug/thread_heap_usage_tracker.h"
#include "base/memory/ptr_util.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -186,18 +187,20 @@ void MemoryDumpManager::EnableHeapProfilingIfNeeded() {
if (profiling_mode == "") {
AllocationContextTracker::SetCaptureMode(
AllocationContextTracker::CaptureMode::PSEUDO_STACK);
}
else if (profiling_mode == switches::kEnableHeapProfilingModeNative) {
#if HAVE_TRACE_STACK_FRAME_POINTERS && \
(BUILDFLAG(ENABLE_PROFILING) || !defined(NDEBUG))
} else if (profiling_mode == switches::kEnableHeapProfilingModeNative) {
// We need frame pointers for native tracing to work, and they are
// enabled in profiling and debug builds.
AllocationContextTracker::SetCaptureMode(
AllocationContextTracker::CaptureMode::NATIVE_STACK);
#else
CHECK(false) << "'" << profiling_mode << "' mode for "
<< switches::kEnableHeapProfiling << " flag is not supported "
<< "for this platform / build type.";
#endif
#if BUILDFLAG(ENABLE_MEMORY_TASK_PROFILER)
} else if (profiling_mode == switches::kEnableHeapProfilingTaskProfiler) {
// Enable heap tracking, which in turn enables capture of heap usage
// tracking in tracked_objects.cc.
if (!base::debug::ThreadHeapUsageTracker::IsHeapTrackingEnabled())
base::debug::ThreadHeapUsageTracker::EnableHeapTracking();
#endif
} else {
CHECK(false) << "Invalid mode '" << profiling_mode << "' for "
Expand Down
15 changes: 1 addition & 14 deletions base/tracked_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -783,14 +783,6 @@ void ThreadData::EnsureTlsInitialization() {
// we get the lock earlier in this method.
base::subtle::Release_Store(&status_, kInitialStartupState);
DCHECK(base::subtle::NoBarrier_Load(&status_) != UNINITIALIZED);

#if BUILDFLAG(ENABLE_MEMORY_TASK_PROFILER)
// Make sure heap tracking is enabled ASAP if the default state is active.
if (kInitialStartupState == PROFILING_ACTIVE &&
!base::debug::ThreadHeapUsageTracker::IsHeapTrackingEnabled()) {
base::debug::ThreadHeapUsageTracker::EnableHeapTracking();
}
#endif // BUILDFLAG(ENABLE_MEMORY_TASK_PROFILER)
}

// static
Expand All @@ -800,14 +792,9 @@ void ThreadData::InitializeAndSetTrackingStatus(Status status) {

EnsureTlsInitialization(); // No-op if already initialized.

if (status > DEACTIVATED) {
if (status > DEACTIVATED)
status = PROFILING_ACTIVE;

#if BUILDFLAG(ENABLE_MEMORY_TASK_PROFILER)
if (!base::debug::ThreadHeapUsageTracker::IsHeapTrackingEnabled())
base::debug::ThreadHeapUsageTracker::EnableHeapTracking();
#endif // BUILDFLAG(ENABLE_MEMORY_TASK_PROFILER)
}
base::subtle::Release_Store(&status_, status);
}

Expand Down

0 comments on commit 014a801

Please sign in to comment.