Commit 6192373e authored by erikchen's avatar erikchen Committed by Commit Bot

Move heap_profiling settings out of ProfilingProcessHost.

This CL is a refactor with no intended behavior change.

By moving the settings into components/services/heap_profiling, they will be
usable by Android Webview, which does not compile chrome/

Bug: 827545
Change-Id: I8b217344fcbc259499b5f7622cbfc9b8d21e3e83
Reviewed-on: https://chromium-review.googlesource.com/998017
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548758}
parent 6876ba12
...@@ -18,6 +18,7 @@ if (!is_android) { ...@@ -18,6 +18,7 @@ if (!is_android) {
"//base", "//base",
"//base/allocator:buildflags", "//base/allocator:buildflags",
"//chrome/test:test_support_ui", "//chrome/test:test_support_ui",
"//components/services/heap_profiling/public/cpp",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
] ]
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/profiling_host/profiling_process_host.h" #include "chrome/browser/profiling_host/profiling_process_host.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "components/services/heap_profiling/public/cpp/settings.h"
ChromeBrowserMainExtraPartsProfiling::ChromeBrowserMainExtraPartsProfiling() = ChromeBrowserMainExtraPartsProfiling::ChromeBrowserMainExtraPartsProfiling() =
default; default;
...@@ -22,14 +23,12 @@ void ChromeBrowserMainExtraPartsProfiling::ServiceManagerConnectionStarted( ...@@ -22,14 +23,12 @@ void ChromeBrowserMainExtraPartsProfiling::ServiceManagerConnectionStarted(
// memlog and memory sanitizers are compatible and can run at the same time. // memlog and memory sanitizers are compatible and can run at the same time.
(void)connection; // Unused variable. (void)connection; // Unused variable.
#else #else
heap_profiling::ProfilingProcessHost::Mode mode = heap_profiling::Mode mode = heap_profiling::GetModeForStartup();
heap_profiling::ProfilingProcessHost::GetModeForStartup(); if (mode != heap_profiling::Mode::kNone) {
if (mode != heap_profiling::ProfilingProcessHost::Mode::kNone) {
heap_profiling::ProfilingProcessHost::Start( heap_profiling::ProfilingProcessHost::Start(
connection, mode, connection, mode, heap_profiling::GetStackModeForStartup(),
heap_profiling::ProfilingProcessHost::GetStackModeForStartup(), heap_profiling::GetShouldSampleForStartup(),
heap_profiling::ProfilingProcessHost::GetShouldSampleForStartup(), heap_profiling::GetSamplingRateForStartup());
heap_profiling::ProfilingProcessHost::GetSamplingRateForStartup());
} }
#endif #endif
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/services/heap_profiling/public/cpp/settings.h"
#include "components/services/heap_profiling/public/cpp/switches.h" #include "components/services/heap_profiling/public/cpp/switches.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
...@@ -31,7 +32,7 @@ ...@@ -31,7 +32,7 @@
namespace heap_profiling { namespace heap_profiling {
struct TestParam { struct TestParam {
ProfilingProcessHost::Mode mode; Mode mode;
mojom::StackMode stack_mode; mojom::StackMode stack_mode;
bool start_profiling_with_command_line_flag; bool start_profiling_with_command_line_flag;
bool should_sample; bool should_sample;
...@@ -43,10 +44,10 @@ class MemlogBrowserTest : public InProcessBrowserTest, ...@@ -43,10 +44,10 @@ class MemlogBrowserTest : public InProcessBrowserTest,
void SetUpDefaultCommandLine(base::CommandLine* command_line) override { void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
InProcessBrowserTest::SetUpDefaultCommandLine(command_line); InProcessBrowserTest::SetUpDefaultCommandLine(command_line);
if (GetParam().start_profiling_with_command_line_flag) { if (GetParam().start_profiling_with_command_line_flag) {
if (GetParam().mode == ProfilingProcessHost::Mode::kAllRenderers) { if (GetParam().mode == Mode::kAllRenderers) {
command_line->AppendSwitchASCII( command_line->AppendSwitchASCII(
heap_profiling::kMemlog, heap_profiling::kMemlogModeAllRenderers); heap_profiling::kMemlog, heap_profiling::kMemlogModeAllRenderers);
} else if (GetParam().mode == ProfilingProcessHost::Mode::kAll) { } else if (GetParam().mode == Mode::kAll) {
command_line->AppendSwitchASCII(heap_profiling::kMemlog, command_line->AppendSwitchASCII(heap_profiling::kMemlog,
heap_profiling::kMemlogModeAll); heap_profiling::kMemlogModeAll);
} else { } else {
...@@ -99,11 +100,11 @@ IN_PROC_BROWSER_TEST_P(MemlogBrowserTest, EndToEnd) { ...@@ -99,11 +100,11 @@ IN_PROC_BROWSER_TEST_P(MemlogBrowserTest, EndToEnd) {
std::vector<TestParam> GetParams() { std::vector<TestParam> GetParams() {
std::vector<TestParam> params; std::vector<TestParam> params;
std::vector<ProfilingProcessHost::Mode> dynamic_start_modes; std::vector<Mode> dynamic_start_modes;
dynamic_start_modes.push_back(ProfilingProcessHost::Mode::kNone); dynamic_start_modes.push_back(Mode::kNone);
dynamic_start_modes.push_back(ProfilingProcessHost::Mode::kMinimal); dynamic_start_modes.push_back(Mode::kMinimal);
dynamic_start_modes.push_back(ProfilingProcessHost::Mode::kBrowser); dynamic_start_modes.push_back(Mode::kBrowser);
dynamic_start_modes.push_back(ProfilingProcessHost::Mode::kGpu); dynamic_start_modes.push_back(Mode::kGpu);
std::vector<mojom::StackMode> stack_modes; std::vector<mojom::StackMode> stack_modes;
stack_modes.push_back(mojom::StackMode::MIXED); stack_modes.push_back(mojom::StackMode::MIXED);
...@@ -121,9 +122,9 @@ std::vector<TestParam> GetParams() { ...@@ -121,9 +122,9 @@ std::vector<TestParam> GetParams() {
// Non-browser processes must be profiled with a command line flag, since // Non-browser processes must be profiled with a command line flag, since
// otherwise, profiling will start after the relevant processes have been // otherwise, profiling will start after the relevant processes have been
// created, thus that process will be not be profiled. // created, thus that process will be not be profiled.
std::vector<ProfilingProcessHost::Mode> command_line_start_modes; std::vector<Mode> command_line_start_modes;
command_line_start_modes.push_back(ProfilingProcessHost::Mode::kAll); command_line_start_modes.push_back(Mode::kAll);
command_line_start_modes.push_back(ProfilingProcessHost::Mode::kAllRenderers); command_line_start_modes.push_back(Mode::kAllRenderers);
for (const auto& mode : command_line_start_modes) { for (const auto& mode : command_line_start_modes) {
for (const auto& stack_mode : stack_modes) { for (const auto& stack_mode : stack_modes) {
params.push_back( params.push_back(
...@@ -133,20 +134,18 @@ std::vector<TestParam> GetParams() { ...@@ -133,20 +134,18 @@ std::vector<TestParam> GetParams() {
} }
// Test sampling all allocations. // Test sampling all allocations.
params.push_back({ProfilingProcessHost::Mode::kBrowser, params.push_back({Mode::kBrowser, mojom::StackMode::NATIVE_WITH_THREAD_NAMES,
mojom::StackMode::NATIVE_WITH_THREAD_NAMES,
false /* start_profiling_with_command_line_flag */, false /* start_profiling_with_command_line_flag */,
true /* should_sample */, true /* sample_everything*/}); true /* should_sample */, true /* sample_everything*/});
// Test sampling some allocations. // Test sampling some allocations.
params.push_back({ProfilingProcessHost::Mode::kBrowser, params.push_back({Mode::kBrowser, mojom::StackMode::PSEUDO,
mojom::StackMode::PSEUDO,
false /* start_profiling_with_command_line_flag */, false /* start_profiling_with_command_line_flag */,
true /* should_sample */, false /* sample_everything*/}); true /* should_sample */, false /* sample_everything*/});
// Test thread names for native profiling. // Test thread names for native profiling.
params.push_back({ProfilingProcessHost::Mode::kBrowser, params.push_back(
mojom::StackMode::NATIVE_WITH_THREAD_NAMES, false}); {Mode::kBrowser, mojom::StackMode::NATIVE_WITH_THREAD_NAMES, false});
return params; return params;
} }
......
...@@ -9,17 +9,12 @@ ...@@ -9,17 +9,12 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/allocator/buildflags.h"
#include "base/base_switches.h"
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/process/process_iterator.h" #include "base/process/process_iterator.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/sys_info.h" #include "base/sys_info.h"
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
...@@ -34,6 +29,7 @@ ...@@ -34,6 +29,7 @@
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "components/services/heap_profiling/public/cpp/sender_pipe.h" #include "components/services/heap_profiling/public/cpp/sender_pipe.h"
#include "components/services/heap_profiling/public/cpp/settings.h"
#include "components/services/heap_profiling/public/cpp/switches.h" #include "components/services/heap_profiling/public/cpp/switches.h"
#include "components/services/heap_profiling/public/mojom/constants.mojom.h" #include "components/services/heap_profiling/public/mojom/constants.mojom.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
...@@ -79,16 +75,6 @@ base::trace_event::TraceConfig GetBackgroundTracingConfig(bool anonymize) { ...@@ -79,16 +75,6 @@ base::trace_event::TraceConfig GetBackgroundTracingConfig(bool anonymize) {
namespace heap_profiling { namespace heap_profiling {
const base::Feature kOOPHeapProfilingFeature{"OOPHeapProfiling",
base::FEATURE_DISABLED_BY_DEFAULT};
const char kOOPHeapProfilingFeatureMode[] = "mode";
const char kOOPHeapProfilingFeatureStackMode[] = "stack-mode";
const char kOOPHeapProfilingFeatureSampling[] = "sampling";
const char kOOPHeapProfilingFeatureSamplingRate[] = "sampling-rate";
const uint32_t kDefaultSamplingRate = 10000;
const bool kDefaultShouldSample = false;
bool ProfilingProcessHost::has_started_ = false; bool ProfilingProcessHost::has_started_ = false;
namespace { namespace {
...@@ -269,129 +255,6 @@ void ProfilingProcessHost::AddClientToProfilingService( ...@@ -269,129 +255,6 @@ void ProfilingProcessHost::AddClientToProfilingService(
process_type, std::move(params)); process_type, std::move(params));
} }
// static
ProfilingProcessHost::Mode ProfilingProcessHost::GetModeForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
if (cmdline->HasSwitch(kMemlog) ||
base::FeatureList::IsEnabled(kOOPHeapProfilingFeature)) {
if (cmdline->HasSwitch(switches::kEnableHeapProfiling)) {
// PartitionAlloc doesn't support chained allocation hooks so we can't
// run both heap profilers at the same time.
LOG(ERROR) << "--" << switches::kEnableHeapProfiling
<< " specified with --" << kMemlog
<< "which are not compatible. Memlog will be disabled.";
return Mode::kNone;
}
std::string mode;
// Respect the commandline switch above the field trial.
if (cmdline->HasSwitch(kMemlog)) {
mode = cmdline->GetSwitchValueASCII(kMemlog);
} else {
mode = base::GetFieldTrialParamValueByFeature(
kOOPHeapProfilingFeature, kOOPHeapProfilingFeatureMode);
}
return ConvertStringToMode(mode);
}
return Mode::kNone;
#else
LOG_IF(ERROR, cmdline->HasSwitch(kMemlog))
<< "--" << kMemlog
<< " specified but it will have no effect because the use_allocator_shim "
<< "is not available in this build.";
return Mode::kNone;
#endif
}
// static
ProfilingProcessHost::Mode ProfilingProcessHost::ConvertStringToMode(
const std::string& mode) {
if (mode == kMemlogModeAll)
return Mode::kAll;
if (mode == kMemlogModeAllRenderers)
return Mode::kAllRenderers;
if (mode == kMemlogModeManual)
return Mode::kManual;
if (mode == kMemlogModeMinimal)
return Mode::kMinimal;
if (mode == kMemlogModeBrowser)
return Mode::kBrowser;
if (mode == kMemlogModeGpu)
return Mode::kGpu;
if (mode == kMemlogModeRendererSampling)
return Mode::kRendererSampling;
DLOG(ERROR) << "Unsupported value: \"" << mode << "\" passed to --"
<< kMemlog;
return Mode::kNone;
}
// static
mojom::StackMode ProfilingProcessHost::GetStackModeForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
std::string stack_mode;
// Respect the commandline switch above the field trial.
if (cmdline->HasSwitch(kMemlogStackMode)) {
stack_mode = cmdline->GetSwitchValueASCII(kMemlogStackMode);
} else {
stack_mode = base::GetFieldTrialParamValueByFeature(
kOOPHeapProfilingFeature, kOOPHeapProfilingFeatureStackMode);
}
return ConvertStringToStackMode(stack_mode);
}
// static
mojom::StackMode ProfilingProcessHost::ConvertStringToStackMode(
const std::string& input) {
if (input == kMemlogStackModeNative)
return mojom::StackMode::NATIVE_WITHOUT_THREAD_NAMES;
if (input == kMemlogStackModeNativeWithThreadNames)
return mojom::StackMode::NATIVE_WITH_THREAD_NAMES;
if (input == kMemlogStackModePseudo)
return mojom::StackMode::PSEUDO;
if (input == kMemlogStackModeMixed)
return mojom::StackMode::MIXED;
DLOG(ERROR) << "Unsupported value: \"" << input << "\" passed to --"
<< kMemlogStackMode;
return mojom::StackMode::NATIVE_WITHOUT_THREAD_NAMES;
}
// static
bool ProfilingProcessHost::GetShouldSampleForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
if (cmdline->HasSwitch(kMemlogSampling))
return true;
return base::GetFieldTrialParamByFeatureAsBool(
kOOPHeapProfilingFeature, kOOPHeapProfilingFeatureSampling,
kDefaultShouldSample /* default_value */);
}
// static
uint32_t ProfilingProcessHost::GetSamplingRateForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
if (cmdline->HasSwitch(kMemlogSamplingRate)) {
std::string rate_as_string =
cmdline->GetSwitchValueASCII(kMemlogSamplingRate);
int rate_as_int = 1;
if (!base::StringToInt(rate_as_string, &rate_as_int)) {
LOG(ERROR) << "Could not parse sampling rate: " << rate_as_string;
}
if (rate_as_int <= 0) {
LOG(ERROR) << "Invalid sampling rate: " << rate_as_string;
rate_as_int = 1;
}
return rate_as_int;
}
return base::GetFieldTrialParamByFeatureAsInt(
kOOPHeapProfilingFeature, kOOPHeapProfilingFeatureSamplingRate,
kDefaultSamplingRate /* default_value */);
}
// static // static
ProfilingProcessHost* ProfilingProcessHost::Start( ProfilingProcessHost* ProfilingProcessHost::Start(
content::ServiceManagerConnection* connection, content::ServiceManagerConnection* connection,
...@@ -428,7 +291,7 @@ ProfilingProcessHost* ProfilingProcessHost::GetInstance() { ...@@ -428,7 +291,7 @@ ProfilingProcessHost* ProfilingProcessHost::GetInstance() {
void ProfilingProcessHost::ConfigureBackgroundProfilingTriggers() { void ProfilingProcessHost::ConfigureBackgroundProfilingTriggers() {
// Only enable automatic uploads when the Finch experiment is enabled. // Only enable automatic uploads when the Finch experiment is enabled.
// Developers can still manually upload via chrome://memory-internals. // Developers can still manually upload via chrome://memory-internals.
if (base::FeatureList::IsEnabled(kOOPHeapProfilingFeature)) if (IsBackgroundHeapProfilingEnabled())
background_triggers_.StartTimer(); background_triggers_.StartTimer();
} }
...@@ -688,10 +551,7 @@ void ProfilingProcessHost::LaunchAsService() { ...@@ -688,10 +551,7 @@ void ProfilingProcessHost::LaunchAsService() {
connector_->BindInterface(mojom::kServiceName, &profiling_service_); connector_->BindInterface(mojom::kServiceName, &profiling_service_);
// Set some state for heap dumps. // Set some state for heap dumps.
bool keep_small_allocations = SetKeepSmallAllocations(ShouldKeepSmallAllocations());
base::CommandLine::ForCurrentProcess()->HasSwitch(
kMemlogKeepSmallAllocations);
SetKeepSmallAllocations(keep_small_allocations);
// Grab a HeapProfiler InterfacePtr and pass that to memory instrumentation. // Grab a HeapProfiler InterfacePtr and pass that to memory instrumentation.
memory_instrumentation::mojom::HeapProfilerPtr heap_profiler; memory_instrumentation::mojom::HeapProfilerPtr heap_profiler;
......
...@@ -9,13 +9,11 @@ ...@@ -9,13 +9,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "base/feature_list.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/process/process.h" #include "base/process/process.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiling_host/background_profiling_triggers.h" #include "chrome/browser/profiling_host/background_profiling_triggers.h"
#include "chrome/common/chrome_features.h"
#include "components/services/heap_profiling/public/cpp/client.h" #include "components/services/heap_profiling/public/cpp/client.h"
#include "components/services/heap_profiling/public/mojom/heap_profiling_client.mojom.h" #include "components/services/heap_profiling/public/mojom/heap_profiling_client.mojom.h"
#include "components/services/heap_profiling/public/mojom/heap_profiling_service.mojom.h" #include "components/services/heap_profiling/public/mojom/heap_profiling_service.mojom.h"
...@@ -36,8 +34,7 @@ class RenderProcessHost; ...@@ -36,8 +34,7 @@ class RenderProcessHost;
namespace heap_profiling { namespace heap_profiling {
extern const base::Feature kOOPHeapProfilingFeature; enum class Mode;
extern const char kOOPHeapProfilingFeatureMode[];
// Represents the browser side of the profiling process (//chrome/profiling). // Represents the browser side of the profiling process (//chrome/profiling).
// //
...@@ -59,37 +56,6 @@ extern const char kOOPHeapProfilingFeatureMode[]; ...@@ -59,37 +56,6 @@ extern const char kOOPHeapProfilingFeatureMode[];
class ProfilingProcessHost : public content::BrowserChildProcessObserver, class ProfilingProcessHost : public content::BrowserChildProcessObserver,
content::NotificationObserver { content::NotificationObserver {
public: public:
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class Mode {
// No profiling enabled.
kNone = 0,
// Only profile the browser and GPU processes.
kMinimal = 1,
// Profile all processes.
kAll = 2,
// Profile only the browser process.
kBrowser = 3,
// Profile only the gpu process.
kGpu = 4,
// Profile a sampled number of renderer processes.
kRendererSampling = 5,
// Profile all renderer processes.
kAllRenderers = 6,
// By default, profile no processes. User may choose to start profiling for
// processes via chrome://memory-internals.
kManual = 7,
kCount
};
// Returns the mode. // Returns the mode.
Mode GetMode() { Mode GetMode() {
base::AutoLock l(mode_lock_); base::AutoLock l(mode_lock_);
...@@ -97,13 +63,6 @@ class ProfilingProcessHost : public content::BrowserChildProcessObserver, ...@@ -97,13 +63,6 @@ class ProfilingProcessHost : public content::BrowserChildProcessObserver,
} }
// Returns the mode specified by the command line or via about://flags. // Returns the mode specified by the command line or via about://flags.
static Mode GetModeForStartup();
static Mode ConvertStringToMode(const std::string& input);
static mojom::StackMode GetStackModeForStartup();
static mojom::StackMode ConvertStringToStackMode(const std::string& input);
static bool GetShouldSampleForStartup();
static uint32_t GetSamplingRateForStartup();
bool ShouldProfileNonRendererProcessType(int process_type); bool ShouldProfileNonRendererProcessType(int process_type);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/services/heap_profiling/public/cpp/settings.h"
#include "components/services/heap_profiling/public/cpp/switches.h" #include "components/services/heap_profiling/public/cpp/switches.h"
#include "content/public/test/mock_render_process_host.h" #include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
...@@ -24,10 +25,10 @@ TEST(ProfilingProcessHost, ShouldProfileNewRenderer) { ...@@ -24,10 +25,10 @@ TEST(ProfilingProcessHost, ShouldProfileNewRenderer) {
TestingProfile testing_profile; TestingProfile testing_profile;
content::MockRenderProcessHost rph(&testing_profile); content::MockRenderProcessHost rph(&testing_profile);
pph.SetMode(ProfilingProcessHost::Mode::kNone); pph.SetMode(Mode::kNone);
EXPECT_FALSE(pph.ShouldProfileNewRenderer(&rph)); EXPECT_FALSE(pph.ShouldProfileNewRenderer(&rph));
pph.SetMode(ProfilingProcessHost::Mode::kAll); pph.SetMode(Mode::kAll);
EXPECT_TRUE(pph.ShouldProfileNewRenderer(&rph)); EXPECT_TRUE(pph.ShouldProfileNewRenderer(&rph));
Profile* incognito_profile = testing_profile.GetOffTheRecordProfile(); Profile* incognito_profile = testing_profile.GetOffTheRecordProfile();
...@@ -38,70 +39,61 @@ TEST(ProfilingProcessHost, ShouldProfileNewRenderer) { ...@@ -38,70 +39,61 @@ TEST(ProfilingProcessHost, ShouldProfileNewRenderer) {
#if BUILDFLAG(USE_ALLOCATOR_SHIM) #if BUILDFLAG(USE_ALLOCATOR_SHIM)
TEST(ProfilingProcessHost, GetModeForStartup_Default) { TEST(ProfilingProcessHost, GetModeForStartup_Default) {
EXPECT_EQ(ProfilingProcessHost::Mode::kNone, EXPECT_EQ(Mode::kNone, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
TEST(ProfilingProcessHost, GetModeForStartup_Commandline) { TEST(ProfilingProcessHost, GetModeForStartup_Commandline) {
{ {
base::test::ScopedCommandLine scoped_command_line; base::test::ScopedCommandLine scoped_command_line;
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog, ""); base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog, "");
EXPECT_EQ(ProfilingProcessHost::Mode::kNone, EXPECT_EQ(Mode::kNone, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
base::test::ScopedCommandLine scoped_command_line; base::test::ScopedCommandLine scoped_command_line;
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog, base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog,
"invalid"); "invalid");
EXPECT_EQ(ProfilingProcessHost::Mode::kNone, EXPECT_EQ(Mode::kNone, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
base::test::ScopedCommandLine scoped_command_line; base::test::ScopedCommandLine scoped_command_line;
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog, base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog,
kMemlogModeAll); kMemlogModeAll);
EXPECT_EQ(ProfilingProcessHost::Mode::kAll, EXPECT_EQ(Mode::kAll, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
base::test::ScopedCommandLine scoped_command_line; base::test::ScopedCommandLine scoped_command_line;
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
kMemlog, kMemlogModeBrowser); kMemlog, kMemlogModeBrowser);
EXPECT_EQ(ProfilingProcessHost::Mode::kBrowser, EXPECT_EQ(Mode::kBrowser, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
base::test::ScopedCommandLine scoped_command_line; base::test::ScopedCommandLine scoped_command_line;
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
kMemlog, kMemlogModeMinimal); kMemlog, kMemlogModeMinimal);
EXPECT_EQ(ProfilingProcessHost::Mode::kMinimal, EXPECT_EQ(Mode::kMinimal, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
base::test::ScopedCommandLine scoped_command_line; base::test::ScopedCommandLine scoped_command_line;
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog, base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog,
kMemlogModeGpu); kMemlogModeGpu);
EXPECT_EQ(ProfilingProcessHost::Mode::kGpu, EXPECT_EQ(Mode::kGpu, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
base::test::ScopedCommandLine scoped_command_line; base::test::ScopedCommandLine scoped_command_line;
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
kMemlog, kMemlogModeRendererSampling); kMemlog, kMemlogModeRendererSampling);
EXPECT_EQ(ProfilingProcessHost::Mode::kRendererSampling, EXPECT_EQ(Mode::kRendererSampling, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
} }
TEST(ProfilingProcessHost, GetModeForStartup_Finch) { TEST(ProfilingProcessHost, GetModeForStartup_Finch) {
EXPECT_EQ(ProfilingProcessHost::Mode::kNone, EXPECT_EQ(Mode::kNone, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
std::map<std::string, std::string> parameters; std::map<std::string, std::string> parameters;
{ {
...@@ -110,8 +102,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) { ...@@ -110,8 +102,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) {
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kNone, EXPECT_EQ(Mode::kNone, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
...@@ -119,8 +110,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) { ...@@ -119,8 +110,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) {
parameters[kOOPHeapProfilingFeatureMode] = "invalid"; parameters[kOOPHeapProfilingFeatureMode] = "invalid";
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kNone, EXPECT_EQ(Mode::kNone, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
...@@ -128,8 +118,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) { ...@@ -128,8 +118,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) {
parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeAll; parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeAll;
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kAll, EXPECT_EQ(Mode::kAll, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
...@@ -137,8 +126,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) { ...@@ -137,8 +126,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) {
parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeBrowser; parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeBrowser;
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kBrowser, EXPECT_EQ(Mode::kBrowser, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
...@@ -146,8 +134,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) { ...@@ -146,8 +134,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) {
parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeMinimal; parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeMinimal;
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kMinimal, EXPECT_EQ(Mode::kMinimal, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
...@@ -155,8 +142,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) { ...@@ -155,8 +142,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) {
parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeGpu; parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeGpu;
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kGpu, EXPECT_EQ(Mode::kGpu, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
...@@ -164,8 +150,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) { ...@@ -164,8 +150,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_Finch) {
parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeRendererSampling; parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeRendererSampling;
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kRendererSampling, EXPECT_EQ(Mode::kRendererSampling, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
} }
...@@ -181,8 +166,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_CommandLinePrecedence) { ...@@ -181,8 +166,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_CommandLinePrecedence) {
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kAll, EXPECT_EQ(Mode::kAll, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
#else #else
...@@ -192,8 +176,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_NoModeWithoutShim) { ...@@ -192,8 +176,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_NoModeWithoutShim) {
base::test::ScopedCommandLine scoped_command_line; base::test::ScopedCommandLine scoped_command_line;
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog, base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(kMemlog,
kMemlogModeAll); kMemlogModeAll);
EXPECT_EQ(ProfilingProcessHost::Mode::kNone, EXPECT_EQ(Mode::kNone, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
{ {
...@@ -202,8 +185,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_NoModeWithoutShim) { ...@@ -202,8 +185,7 @@ TEST(ProfilingProcessHost, GetModeForStartup_NoModeWithoutShim) {
parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeMinimal; parameters[kOOPHeapProfilingFeatureMode] = kMemlogModeMinimal;
scoped_feature_list.InitAndEnableFeatureWithParameters( scoped_feature_list.InitAndEnableFeatureWithParameters(
kOOPHeapProfilingFeature, parameters); kOOPHeapProfilingFeature, parameters);
EXPECT_EQ(ProfilingProcessHost::Mode::kNone, EXPECT_EQ(Mode::kNone, GetModeForStartup());
ProfilingProcessHost::GetModeForStartup());
} }
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/values.h" #include "base/values.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/services/heap_profiling/public/cpp/allocator_shim.h" #include "components/services/heap_profiling/public/cpp/allocator_shim.h"
#include "components/services/heap_profiling/public/cpp/settings.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/tracing_controller.h" #include "content/public/browser/tracing_controller.h"
...@@ -538,7 +539,7 @@ bool ProfilingTestDriver::RunTest(const Options& options) { ...@@ -538,7 +539,7 @@ bool ProfilingTestDriver::RunTest(const Options& options) {
content::BrowserThread::CurrentlyOn(content::BrowserThread::UI); content::BrowserThread::CurrentlyOn(content::BrowserThread::UI);
// The only thing to test for Mode::kNone is that profiling hasn't started. // The only thing to test for Mode::kNone is that profiling hasn't started.
if (options_.mode == ProfilingProcessHost::Mode::kNone) { if (options_.mode == Mode::kNone) {
if (ProfilingProcessHost::has_started()) { if (ProfilingProcessHost::has_started()) {
LOG(ERROR) << "Profiling should not have started"; LOG(ERROR) << "Profiling should not have started";
return false; return false;
...@@ -756,9 +757,8 @@ bool ProfilingTestDriver::ValidateBrowserAllocations(base::Value* dump_json) { ...@@ -756,9 +757,8 @@ bool ProfilingTestDriver::ValidateBrowserAllocations(base::Value* dump_json) {
base::Value* heaps_v2 = base::Value* heaps_v2 =
FindArgDump(base::Process::Current().Pid(), dump_json, "heaps_v2"); FindArgDump(base::Process::Current().Pid(), dump_json, "heaps_v2");
if (options_.mode != ProfilingProcessHost::Mode::kAll && if (options_.mode != Mode::kAll && options_.mode != Mode::kBrowser &&
options_.mode != ProfilingProcessHost::Mode::kBrowser && options_.mode != Mode::kMinimal) {
options_.mode != ProfilingProcessHost::Mode::kMinimal) {
if (heaps_v2) { if (heaps_v2) {
LOG(ERROR) << "There should be no heap dump for the browser."; LOG(ERROR) << "There should be no heap dump for the browser.";
return false; return false;
...@@ -881,7 +881,7 @@ bool ProfilingTestDriver::ValidateRendererAllocations(base::Value* dump_json) { ...@@ -881,7 +881,7 @@ bool ProfilingTestDriver::ValidateRendererAllocations(base::Value* dump_json) {
} }
} }
if (options_.mode == ProfilingProcessHost::Mode::kAllRenderers) { if (options_.mode == Mode::kAllRenderers) {
if (NumProcessesWithName(dump_json, "Renderer", nullptr) == 0) { if (NumProcessesWithName(dump_json, "Renderer", nullptr) == 0) {
LOG(ERROR) << "There should be at least 1 renderer dump"; LOG(ERROR) << "There should be at least 1 renderer dump";
return false; return false;
...@@ -897,14 +897,12 @@ bool ProfilingTestDriver::ValidateRendererAllocations(base::Value* dump_json) { ...@@ -897,14 +897,12 @@ bool ProfilingTestDriver::ValidateRendererAllocations(base::Value* dump_json) {
} }
bool ProfilingTestDriver::ShouldProfileBrowser() { bool ProfilingTestDriver::ShouldProfileBrowser() {
return options_.mode == ProfilingProcessHost::Mode::kAll || return options_.mode == Mode::kAll || options_.mode == Mode::kBrowser ||
options_.mode == ProfilingProcessHost::Mode::kBrowser || options_.mode == Mode::kMinimal;
options_.mode == ProfilingProcessHost::Mode::kMinimal;
} }
bool ProfilingTestDriver::ShouldProfileRenderer() { bool ProfilingTestDriver::ShouldProfileRenderer() {
return options_.mode == ProfilingProcessHost::Mode::kAll || return options_.mode == Mode::kAll || options_.mode == Mode::kAllRenderers;
options_.mode == ProfilingProcessHost::Mode::kAllRenderers;
} }
bool ProfilingTestDriver::ShouldIncludeNativeThreadNames() { bool ProfilingTestDriver::ShouldIncludeNativeThreadNames() {
......
...@@ -41,7 +41,7 @@ class ProfilingTestDriver { ...@@ -41,7 +41,7 @@ class ProfilingTestDriver {
public: public:
struct Options { struct Options {
// The profiling mode to test. // The profiling mode to test.
ProfilingProcessHost::Mode mode; Mode mode;
// The stack profiling mode to test. // The stack profiling mode to test.
mojom::StackMode stack_mode; mojom::StackMode stack_mode;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "chrome/browser/profiling_host/profiling_process_host.h" #include "chrome/browser/profiling_host/profiling_process_host.h"
#include "chrome/browser/profiling_host/profiling_test_driver.h" #include "chrome/browser/profiling_host/profiling_test_driver.h"
#include "components/services/heap_profiling/public/cpp/settings.h"
#include "jni/TestAndroidShim_jni.h" #include "jni/TestAndroidShim_jni.h"
using base::android::JavaParamRef; using base::android::JavaParamRef;
...@@ -36,11 +37,10 @@ jboolean TestAndroidShim::RunTestForMode( ...@@ -36,11 +37,10 @@ jboolean TestAndroidShim::RunTestForMode(
jboolean sample_everything) { jboolean sample_everything) {
heap_profiling::ProfilingTestDriver driver; heap_profiling::ProfilingTestDriver driver;
heap_profiling::ProfilingTestDriver::Options options; heap_profiling::ProfilingTestDriver::Options options;
options.mode = heap_profiling::ProfilingProcessHost::ConvertStringToMode( options.mode = heap_profiling::ConvertStringToMode(
base::android::ConvertJavaStringToUTF8(mode)); base::android::ConvertJavaStringToUTF8(mode));
options.stack_mode = options.stack_mode = heap_profiling::ConvertStringToStackMode(
heap_profiling::ProfilingProcessHost::ConvertStringToStackMode( base::android::ConvertJavaStringToUTF8(stack_mode));
base::android::ConvertJavaStringToUTF8(stack_mode));
options.profiling_already_started = !dynamically_start_profiling; options.profiling_already_started = !dynamically_start_profiling;
options.should_sample = should_sample; options.should_sample = should_sample;
options.sample_everything = sample_everything; options.sample_everything = sample_everything;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "components/services/heap_profiling/public/cpp/settings.h"
#include "content/public/browser/browser_child_process_host_iterator.h" #include "content/public/browser/browser_child_process_host_iterator.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h" #include "content/public/browser/child_process_data.h"
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
#include "ui/shell_dialogs/select_file_dialog.h" #include "ui/shell_dialogs/select_file_dialog.h"
#include "ui/shell_dialogs/select_file_policy.h" #include "ui/shell_dialogs/select_file_policy.h"
using heap_profiling::Mode;
using heap_profiling::ProfilingProcessHost; using heap_profiling::ProfilingProcessHost;
namespace { namespace {
...@@ -48,30 +50,30 @@ namespace { ...@@ -48,30 +50,30 @@ namespace {
std::string GetMessageString() { std::string GetMessageString() {
#if BUILDFLAG(USE_ALLOCATOR_SHIM) #if BUILDFLAG(USE_ALLOCATOR_SHIM)
switch (ProfilingProcessHost::GetInstance()->GetMode()) { switch (ProfilingProcessHost::GetInstance()->GetMode()) {
case ProfilingProcessHost::Mode::kAll: case Mode::kAll:
return std::string("Memory logging is enabled for all processes."); return std::string("Memory logging is enabled for all processes.");
case ProfilingProcessHost::Mode::kAllRenderers: case Mode::kAllRenderers:
return std::string("Memory logging is enabled for all renderers."); return std::string("Memory logging is enabled for all renderers.");
case ProfilingProcessHost::Mode::kBrowser: case Mode::kBrowser:
return std::string( return std::string(
"Memory logging is enabled for just the browser process."); "Memory logging is enabled for just the browser process.");
case ProfilingProcessHost::Mode::kGpu: case Mode::kGpu:
return std::string("Memory logging is enabled for just the gpu process."); return std::string("Memory logging is enabled for just the gpu process.");
case ProfilingProcessHost::Mode::kMinimal: case Mode::kMinimal:
return std::string( return std::string(
"Memory logging is enabled for the browser and GPU processes."); "Memory logging is enabled for the browser and GPU processes.");
case ProfilingProcessHost::Mode::kRendererSampling: case Mode::kRendererSampling:
return std::string( return std::string(
"Memory logging is enabled for an automatic sample of renderer " "Memory logging is enabled for an automatic sample of renderer "
"processes. This UI is disabled."); "processes. This UI is disabled.");
case ProfilingProcessHost::Mode::kNone: case Mode::kNone:
case ProfilingProcessHost::Mode::kManual: case Mode::kManual:
default: default:
return std::string( return std::string(
"Memory logging must be manually enabled for each process via " "Memory logging must be manually enabled for each process via "
......
...@@ -11,6 +11,8 @@ static_library("cpp") { ...@@ -11,6 +11,8 @@ static_library("cpp") {
"sender_pipe.h", "sender_pipe.h",
"sender_pipe_posix.cc", "sender_pipe_posix.cc",
"sender_pipe_win.cc", "sender_pipe_win.cc",
"settings.cc",
"settings.h",
"stream.h", "stream.h",
"switches.cc", "switches.cc",
"switches.h", "switches.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/services/heap_profiling/public/cpp/settings.h"
#include "base/allocator/buildflags.h"
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "components/services/heap_profiling/public/cpp/switches.h"
namespace heap_profiling {
const base::Feature kOOPHeapProfilingFeature{"OOPHeapProfiling",
base::FEATURE_DISABLED_BY_DEFAULT};
const char kOOPHeapProfilingFeatureMode[] = "mode";
namespace {
const char kOOPHeapProfilingFeatureStackMode[] = "stack-mode";
const char kOOPHeapProfilingFeatureSampling[] = "sampling";
const char kOOPHeapProfilingFeatureSamplingRate[] = "sampling-rate";
const uint32_t kDefaultSamplingRate = 10000;
const bool kDefaultShouldSample = false;
} // namespace
Mode GetModeForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
#if BUILDFLAG(USE_ALLOCATOR_SHIM)
if (cmdline->HasSwitch(kMemlog) ||
base::FeatureList::IsEnabled(kOOPHeapProfilingFeature)) {
if (cmdline->HasSwitch(switches::kEnableHeapProfiling)) {
// PartitionAlloc doesn't support chained allocation hooks so we can't
// run both heap profilers at the same time.
LOG(ERROR) << "--" << switches::kEnableHeapProfiling
<< " specified with --" << kMemlog
<< "which are not compatible. Memlog will be disabled.";
return Mode::kNone;
}
std::string mode;
// Respect the commandline switch above the field trial.
if (cmdline->HasSwitch(kMemlog)) {
mode = cmdline->GetSwitchValueASCII(kMemlog);
} else {
mode = base::GetFieldTrialParamValueByFeature(
kOOPHeapProfilingFeature, kOOPHeapProfilingFeatureMode);
}
return ConvertStringToMode(mode);
}
return Mode::kNone;
#else
LOG_IF(ERROR, cmdline->HasSwitch(kMemlog))
<< "--" << kMemlog
<< " specified but it will have no effect because the use_allocator_shim "
<< "is not available in this build.";
return Mode::kNone;
#endif
}
Mode ConvertStringToMode(const std::string& mode) {
if (mode == kMemlogModeAll)
return Mode::kAll;
if (mode == kMemlogModeAllRenderers)
return Mode::kAllRenderers;
if (mode == kMemlogModeManual)
return Mode::kManual;
if (mode == kMemlogModeMinimal)
return Mode::kMinimal;
if (mode == kMemlogModeBrowser)
return Mode::kBrowser;
if (mode == kMemlogModeGpu)
return Mode::kGpu;
if (mode == kMemlogModeRendererSampling)
return Mode::kRendererSampling;
DLOG(ERROR) << "Unsupported value: \"" << mode << "\" passed to --"
<< kMemlog;
return Mode::kNone;
}
mojom::StackMode GetStackModeForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
std::string stack_mode;
// Respect the commandline switch above the field trial.
if (cmdline->HasSwitch(kMemlogStackMode)) {
stack_mode = cmdline->GetSwitchValueASCII(kMemlogStackMode);
} else {
stack_mode = base::GetFieldTrialParamValueByFeature(
kOOPHeapProfilingFeature, kOOPHeapProfilingFeatureStackMode);
}
return ConvertStringToStackMode(stack_mode);
}
mojom::StackMode ConvertStringToStackMode(const std::string& input) {
if (input == kMemlogStackModeNative)
return mojom::StackMode::NATIVE_WITHOUT_THREAD_NAMES;
if (input == kMemlogStackModeNativeWithThreadNames)
return mojom::StackMode::NATIVE_WITH_THREAD_NAMES;
if (input == kMemlogStackModePseudo)
return mojom::StackMode::PSEUDO;
if (input == kMemlogStackModeMixed)
return mojom::StackMode::MIXED;
DLOG(ERROR) << "Unsupported value: \"" << input << "\" passed to --"
<< kMemlogStackMode;
return mojom::StackMode::NATIVE_WITHOUT_THREAD_NAMES;
}
bool GetShouldSampleForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
if (cmdline->HasSwitch(kMemlogSampling))
return true;
return base::GetFieldTrialParamByFeatureAsBool(
kOOPHeapProfilingFeature, kOOPHeapProfilingFeatureSampling,
kDefaultShouldSample /* default_value */);
}
uint32_t GetSamplingRateForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
if (cmdline->HasSwitch(kMemlogSamplingRate)) {
std::string rate_as_string =
cmdline->GetSwitchValueASCII(kMemlogSamplingRate);
int rate_as_int = 1;
if (!base::StringToInt(rate_as_string, &rate_as_int)) {
LOG(ERROR) << "Could not parse sampling rate: " << rate_as_string;
}
if (rate_as_int <= 0) {
LOG(ERROR) << "Invalid sampling rate: " << rate_as_string;
rate_as_int = 1;
}
return rate_as_int;
}
return base::GetFieldTrialParamByFeatureAsInt(
kOOPHeapProfilingFeature, kOOPHeapProfilingFeatureSamplingRate,
kDefaultSamplingRate /* default_value */);
}
bool IsBackgroundHeapProfilingEnabled() {
return base::FeatureList::IsEnabled(kOOPHeapProfilingFeature);
}
bool ShouldKeepSmallAllocations() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
kMemlogKeepSmallAllocations);
}
} // namespace heap_profiling
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SERVICES_HEAP_PROFILING_PUBLIC_CPP_SETTINGS_H_
#define COMPONENTS_SERVICES_HEAP_PROFILING_PUBLIC_CPP_SETTINGS_H_
#include "base/feature_list.h"
#include "components/services/heap_profiling/public/mojom/heap_profiling_client.mojom.h"
// These helper functions parse the command line and FeatureList settings to
// return coherent settings to use for the heap profiler at startup.
namespace heap_profiling {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class Mode {
// No profiling enabled.
kNone = 0,
// Only profile the browser and GPU processes.
kMinimal = 1,
// Profile all processes.
kAll = 2,
// Profile only the browser process.
kBrowser = 3,
// Profile only the gpu process.
kGpu = 4,
// Profile a sampled number of renderer processes.
kRendererSampling = 5,
// Profile all renderer processes.
kAllRenderers = 6,
// By default, profile no processes. User may choose to start profiling for
// processes via chrome://memory-internals.
kManual = 7,
kCount
};
Mode GetModeForStartup();
Mode ConvertStringToMode(const std::string& input);
mojom::StackMode GetStackModeForStartup();
mojom::StackMode ConvertStringToStackMode(const std::string& input);
bool GetShouldSampleForStartup();
uint32_t GetSamplingRateForStartup();
bool IsBackgroundHeapProfilingEnabled();
bool ShouldKeepSmallAllocations();
// Exposed for testing.
extern const base::Feature kOOPHeapProfilingFeature;
extern const char kOOPHeapProfilingFeatureMode[];
} // namespace heap_profiling
#endif // COMPONENTS_SERVICES_HEAP_PROFILING_PUBLIC_CPP_SETTINGS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment