chromium/components/heap_profiling/in_process/heap_profiler_parameters.cc

// Copyright 2022 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/heap_profiling/in_process/heap_profiler_parameters.h"

#include <string>
#include <string_view>

#include "base/check.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/json/json_reader.h"
#include "base/json/json_value_converter.h"
#include "base/metrics/field_trial_params.h"
#include "base/profiler/process_type.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/variations/variations_switches.h"

namespace heap_profiling {

namespace {

// Platform-specific parameter defaults.

#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
// Average 1M bytes per sample.
constexpr int kDefaultSamplingRateBytes = 1'000'000;

// Default on iOS is equal to mean value of process uptime. Android is
// more similar to iOS than to Desktop.
constexpr base::TimeDelta kDefaultCollectionInterval = base::Minutes(30);
#else
// Average 10M bytes per sample.
constexpr int kDefaultSamplingRateBytes =;

// Default on desktop is once per day.
constexpr base::TimeDelta kDefaultCollectionInterval =;
#endif

// The chance that this client will report heap samples through a metrics
// provider if it's on the stable channel.
#if BUILDFLAG(IS_ANDROID)
// With stable-probability 0.01 we get about 4x as many records as before
// https://crrev.com/c/3309878 landed in 98.0.4742.0, even with ARM64
// disabled. This is too high a volume to process.
constexpr double kDefaultStableProbability = 0.0025;
#else
constexpr double kDefaultStableProbability =;
#endif

// The chance that this client will report heap samples through a metrics
// provider if it's on a non-stable channel.
constexpr double kDefaultNonStableProbability =;

constexpr HeapProfilerParameters kDefaultHeapProfilerParameters{};

// Feature parameters.

// JSON-encoded parameter map that will set the default parameters for the
// heap profiler unless overridden by the process-specific parameters below.
constexpr base::FeatureParam<std::string> kDefaultParameters{};

// JSON-encoded parameter map that will override the default parameters for the
// browser process.
constexpr base::FeatureParam<std::string> kBrowserProcessParameters{};

// JSON-encoded parameter map that will override the default parameters for
// renderer processes.
constexpr base::FeatureParam<std::string> kRendererProcessParameters{};

// JSON-encoded parameter map that will override the default parameters for the
// GPU process.
constexpr base::FeatureParam<std::string> kGPUProcessParameters{};

// JSON-encoded parameter map that will override the default parameters for
// utility processes.
constexpr base::FeatureParam<std::string> kUtilityProcessParameters{};

// JSON-encoded parameter map that will override the default parameters for the
// network process.
constexpr base::FeatureParam<std::string> kNetworkProcessParameters{};

// Interprets `value` as a positive number of minutes, and writes the converted
// value to `result`. If `value` contains anything other than a positive
// integer, returns false to indicate a conversion failure.
bool ConvertCollectionInterval(const base::Value* value,
                               base::TimeDelta* result) {}

}  // namespace

BASE_FEATURE();

BASE_FEATURE();

const base::FeatureParam<int> kGpuSnapshotProbability{};

const base::FeatureParam<int> kNetworkSnapshotProbability{};

// Sample 10% of renderer processes by default, because last time this was
// evaluated (2024-08) the 50th %ile of renderer process count
// (Memory.RenderProcessHost.Count.All) ranged from 8 on Windows to 18 on Mac.
// 10% is an easy default between 1/18 and 1/8.
const base::FeatureParam<int> kRendererSnapshotProbability{};

// Sample 50% of utility processes by default, because last time this was
// evaluated (2024-08) the profiler collected 1.8x as many snapshots on Mac and
// 2.4x as many snapshots on Windows for each browser process snapshot.
const base::FeatureParam<int> kUtilitySnapshotProbability{};

// static
void HeapProfilerParameters::RegisterJSONConverter(
    base::JSONValueConverter<HeapProfilerParameters>* converter) {}

bool HeapProfilerParameters::UpdateFromJSON(std::string_view json_string) {}

HeapProfilerParameters GetDefaultHeapProfilerParameters() {}

HeapProfilerParameters GetHeapProfilerParametersForProcess(
    base::ProfilerProcessType process_type) {}

}  // namespace heap_profiling