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...
 
 ~SamplingProfiler ()
 
void Start ()
 Starts the SamplingProfiler by triggering SampleRepeatedly. More...
 
void Stop ()
 

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 82 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) {}

◆ ~SamplingProfiler()

flutter::SamplingProfiler::~SamplingProfiler ( )

Definition at line 19 of file sampling_profiler.cc.

References Stop().

19  {
20  if (is_running_) {
21  Stop();
22  }
23 }

Member Function Documentation

◆ Start()

void flutter::SamplingProfiler::Start ( )

Starts the SamplingProfiler by triggering SampleRepeatedly.

Definition at line 25 of file sampling_profiler.cc.

References FML_CHECK, and fml::TimeDelta::FromSecondsF().

Referenced by flutter::TEST().

25  {
26  if (!profiler_task_runner_) {
27  return;
28  }
29  FML_CHECK(num_samples_per_sec_ > 0)
30  << "number of samples must be a positive integer, got: "
31  << num_samples_per_sec_;
32  double delay_between_samples = 1.0 / num_samples_per_sec_;
33  auto task_delay = fml::TimeDelta::FromSecondsF(delay_between_samples);
34  UpdateObservatoryThreadName();
35  is_running_ = true;
36  SampleRepeatedly(task_delay);
37 }
static constexpr TimeDelta FromSecondsF(double seconds)
Definition: time_delta.h:53
#define FML_CHECK(condition)
Definition: logging.h:68

◆ Stop()

void flutter::SamplingProfiler::Stop ( )

Definition at line 39 of file sampling_profiler.cc.

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

Referenced by ~SamplingProfiler().

39  {
40  FML_DCHECK(is_running_);
41  auto latch = std::make_unique<fml::AutoResetWaitableEvent>();
42  shutdown_latch_.store(latch.get());
43  latch->Wait();
44  shutdown_latch_.store(nullptr);
45  is_running_ = false;
46 }
#define FML_DCHECK(condition)
Definition: logging.h:86

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