1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
// Copyright 2018 The Chromium Authors
// 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/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"
#include "partition_alloc/buildflags.h"
namespace heap_profiling {
Mode GetModeForStartup() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
#if PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
if (cmdline->HasSwitch("enable-heap-profiling")) {
LOG(ERROR) << "--enable-heap-profiling is no longer supported. Use "
"--memlog instead. See documentation at "
"docs/memory/debugging_memory_issues.md";
return Mode::kNone;
}
if (cmdline->HasSwitch(kMemlogMode)) {
std::string mode = cmdline->GetSwitchValueASCII(kMemlogMode);
return ConvertStringToMode(mode);
}
return Mode::kNone;
#else
LOG_IF(ERROR, cmdline->HasSwitch(kMemlogMode))
<< "--" << kMemlogMode
<< " 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;
if (mode == kMemlogModeUtilitySampling)
return Mode::kUtilitySampling;
if (mode == kMemlogModeUtilityAndBrowser)
return Mode::kUtilityAndBrowser;
DLOG(ERROR) << "Unsupported value: \"" << mode << "\" passed to --"
<< kMemlogMode;
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 = kMemlogStackModeNative;
}
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;
DLOG(ERROR) << "Unsupported value: \"" << input << "\" passed to --"
<< kMemlogStackMode;
return mojom::StackMode::NATIVE_WITHOUT_THREAD_NAMES;
}
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 1000000;
}
} // namespace heap_profiling
|