Skip to content

Commit

Permalink
[tracing] Allow enabling heap profiling from chrome://flags
Browse files Browse the repository at this point in the history
BUG=684839

Review-Url: https://codereview.chromium.org/2847823004
Cr-Commit-Position: refs/heads/master@{#468462}
  • Loading branch information
dskiba authored and Commit bot committed May 1, 2017
1 parent 54d7621 commit c6376a6
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
4 changes: 4 additions & 0 deletions base/base_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const char kEnableCrashReporter[] = "enable-crash-reporter";
// the memory-infra category is enabled.
const char kEnableHeapProfiling[] = "enable-heap-profiling";

// Report pseudo allocation traces. Pseudo traces are derived from currently
// active trace events.
const char kEnableHeapProfilingModePseudo[] = "";

// Report native (walk the stack) allocation traces. By default pseudo stacks
// derived from trace events are reported.
const char kEnableHeapProfilingModeNative[] = "native";
Expand Down
1 change: 1 addition & 0 deletions base/base_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern const char kDisableBreakpad[];
extern const char kDisableLowEndDeviceMode[];
extern const char kEnableCrashReporter[];
extern const char kEnableHeapProfiling[];
extern const char kEnableHeapProfilingModePseudo[];
extern const char kEnableHeapProfilingModeNative[];
extern const char kEnableHeapProfilingTaskProfiler[];
extern const char kEnableLowEndDeviceMode[];
Expand Down
2 changes: 1 addition & 1 deletion base/trace_event/memory_dump_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void MemoryDumpManager::EnableHeapProfilingIfNeeded() {

std::string profiling_mode = CommandLine::ForCurrentProcess()
->GetSwitchValueASCII(switches::kEnableHeapProfiling);
if (profiling_mode == "") {
if (profiling_mode == switches::kEnableHeapProfilingModePseudo) {
AllocationContextTracker::SetCaptureMode(
AllocationContextTracker::CaptureMode::PSEUDO_STACK);
#if !defined(OS_NACL)
Expand Down
14 changes: 14 additions & 0 deletions chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,16 @@ const FeatureEntry::FeatureVariation kDataReductionMainMenuFeatureVariations[] =
arraysize(kPersistentMenuItemEnabled), nullptr}};
#endif // OS_ANDROID

const FeatureEntry::Choice kEnableHeapProfilingChoices[] = {
{flags_ui::kGenericExperimentChoiceDisabled, "", ""},
{flag_descriptions::kEnableHeapProfilingModePseudo,
switches::kEnableHeapProfiling, switches::kEnableHeapProfilingModePseudo},
{flag_descriptions::kEnableHeapProfilingModeNative,
switches::kEnableHeapProfiling, switches::kEnableHeapProfilingModeNative},
{flag_descriptions::kEnableHeapProfilingTaskProfiler,
switches::kEnableHeapProfiling,
switches::kEnableHeapProfilingTaskProfiler}};

// RECORDING USER METRICS FOR FLAGS:
// -----------------------------------------------------------------------------
// The first line of the entry is the internal name.
Expand Down Expand Up @@ -2759,6 +2769,10 @@ const FeatureEntry kFeatureEntries[] = {
flag_descriptions::kAutoplayPolicyDescription, kOsAll,
MULTI_VALUE_TYPE(kAutoplayPolicyChoices)},

{"enable-heap-profiling", flag_descriptions::kEnableHeapProfilingName,
flag_descriptions::kEnableHeapProfilingDescription, kOsAll,
MULTI_VALUE_TYPE(kEnableHeapProfilingChoices)},

// NOTE: Adding new command-line switches requires adding corresponding
// entries to enum "LoginCustomFlags" in histograms.xml. See note in
// histograms.xml and don't forget to run AboutFlagsHistogramTest unit test.
Expand Down
10 changes: 10 additions & 0 deletions chrome/browser/flag_descriptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3058,4 +3058,14 @@ const char kOmniboxDisplayTitleForCurrentUrlDescription[] =
"the current page is provided as the first suggestion without a title. "
"Enabling this flag causes the title to be displayed.";

const char kEnableHeapProfilingName[] = "Heap profiling";

const char kEnableHeapProfilingDescription[] = "Enables heap profiling.";

const char kEnableHeapProfilingModePseudo[] = "Enabled (pseudo mode)";

const char kEnableHeapProfilingModeNative[] = "Enabled (native mode)";

const char kEnableHeapProfilingTaskProfiler[] = "Enabled (task mode)";

} // namespace flag_descriptions
9 changes: 9 additions & 0 deletions chrome/browser/flag_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -3323,6 +3323,15 @@ extern const char kOmniboxDisplayTitleForCurrentUrlName[];
// for current URL.
extern const char kOmniboxDisplayTitleForCurrentUrlDescription[];

// Name & description for the heap profiling flag.
extern const char kEnableHeapProfilingName[];
extern const char kEnableHeapProfilingDescription[];

// Descriptions of the different heap profiling modes.
extern const char kEnableHeapProfilingModePseudo[];
extern const char kEnableHeapProfilingModeNative[];
extern const char kEnableHeapProfilingTaskProfiler[];

} // namespace flag_descriptions

#endif // CHROME_BROWSER_FLAG_DESCRIPTIONS_H_
1 change: 1 addition & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103655,6 +103655,7 @@ from previous Chrome versions.
<int value="-891856063" label="MidiManagerAndroid:enabled"/>
<int value="-885601782" label="enable-contextual-search"/>
<int value="-884864731" label="WebPaymentsSingleAppUiSkip:enabled"/>
<int value="-881854123" label="enable-heap-profiling"/>
<int value="-881054479" label="WebAssemblyStreaming:disabled"/>
<int value="-876148583" label="ArcBootCompletedBroadcast:disabled"/>
<int value="-867087281" label="enable-virtual-keyboard"/>
Expand Down

0 comments on commit c6376a6

Please sign in to comment.