Flutter Engine
flutter::SamplingProfiler Class Reference

a Sampling Profiler that runs peridically and calls the Sampler which servers as a value function to gather various profiling metrics as represented by ProfileSample. These profiling metrics are then posted to the observatory timeline. More...

#include <sampling_profiler.h>

Public Member Functions

 SamplingProfiler (const char *thread_label, fml::RefPtr< fml::TaskRunner > profiler_task_runner, Sampler sampler, int num_samples_per_sec)
 Construct a new Sampling Profiler object. More...
 
void Start () const
 Starts the SamplingProfiler by triggering SampleRepeatedly. More...
 

Detailed Description

a Sampling Profiler that runs peridically and calls the Sampler which servers as a value function to gather various profiling metrics as represented by ProfileSample. These profiling metrics are then posted to the observatory timeline.

Definition at line 81 of file sampling_profiler.h.

Constructor & Destructor Documentation

◆ SamplingProfiler()

flutter::SamplingProfiler::SamplingProfiler ( const char *  thread_label,
fml::RefPtr< fml::TaskRunner profiler_task_runner,
Sampler  sampler,
int  num_samples_per_sec 
)

Construct a new Sampling Profiler object.

Parameters
thread_labelobservatory prefix to be set for the profiling task runner.
profiler_task_runnerthe task runner to service sampling requests.
samplerthe value function to collect the profiling metrics.
num_samples_per_secnumber of times you wish to run the sampler per second.
See also
fml::TaskRunner

Definition at line 9 of file sampling_profiler.cc.

14  : thread_label_(thread_label),
15  profiler_task_runner_(profiler_task_runner),
16  sampler_(std::move(sampler)),
17  num_samples_per_sec_(num_samples_per_sec) {}

Member Function Documentation

◆ Start()

void flutter::SamplingProfiler::Start ( ) const

Starts the SamplingProfiler by triggering SampleRepeatedly.

Definition at line 19 of file sampling_profiler.cc.

References flutter::ProfileSample::cpu_usage, FML_CHECK, fml::TimeDelta::FromSecondsF(), flutter::ProfileSample::gpu_usage, flutter::ProfileSample::memory_usage, fml::TaskRunner::PostDelayedTask(), fml::TaskRunner::PostTask(), TRACE_EVENT_INSTANT1, and TRACE_EVENT_INSTANT2.

19  {
20  if (!profiler_task_runner_) {
21  return;
22  }
23  FML_CHECK(num_samples_per_sec_ > 0)
24  << "number of samples must be a positive integer, got: "
25  << num_samples_per_sec_;
26  double delay_between_samples = 1.0 / num_samples_per_sec_;
27  auto task_delay = fml::TimeDelta::FromSecondsF(delay_between_samples);
28  UpdateObservatoryThreadName();
29  SampleRepeatedly(task_delay);
30 }
static constexpr TimeDelta FromSecondsF(double seconds)
Definition: time_delta.h:53
#define FML_CHECK(condition)
Definition: logging.h:68

The documentation for this class was generated from the following files: