Commit c5072ad9 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

[heap profiler] Add conditional recording of sampling heap profiles.

The recording depends on the Finch experiment setting. The sampling
rate can be controlled with a parameter.

BUG=972231

Change-Id: I560de9328b561ef11b474af6a1261534104f56c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1650138Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667358}
parent 221dcd9e
......@@ -7,6 +7,8 @@
#include <cmath>
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/rand_util.h"
#include "base/sampling_heap_profiler/module_cache.h"
#include "base/sampling_heap_profiler/sampling_heap_profiler.h"
......@@ -15,6 +17,13 @@
namespace {
// Enables reporting of sampling heap profiles over UMA.
const base::Feature kHeapProfilerReporting{"HeapProfilerReporting",
base::FEATURE_DISABLED_BY_DEFAULT};
// Sets sampling interval in bytes.
const char kHeapProfilerSamplingRate[] = "sampling-rate";
constexpr base::TimeDelta kHeapCollectionInterval =
base::TimeDelta::FromHours(24);
......@@ -33,7 +42,19 @@ HeapProfilerController::~HeapProfilerController() {
stopped_->data.Set();
}
// static
bool HeapProfilerController::IsReportingEnabled() {
return base::FeatureList::IsEnabled(kHeapProfilerReporting);
}
void HeapProfilerController::Start() {
if (IsReportingEnabled()) {
int sampling_rate = base::GetFieldTrialParamByFeatureAsInt(
kHeapProfilerReporting, kHeapProfilerSamplingRate, 0);
if (sampling_rate > 0)
base::SamplingHeapProfiler::Get()->SetSamplingInterval(sampling_rate);
base::SamplingHeapProfiler::Get()->Start();
}
ScheduleNextSnapshot(task_runner_ ? std::move(task_runner_)
: base::CreateTaskRunnerWithTraits(
{base::TaskPriority::BEST_EFFORT}),
......
......@@ -27,6 +27,8 @@ class HeapProfilerController {
task_runner_ = std::move(task_runner);
}
static bool IsReportingEnabled();
private:
using StoppedFlag = base::RefCountedData<base::AtomicFlag>;
......
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