Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
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 Dart VM Service 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.
 
 ~SamplingProfiler ()
 
void Start ()
 Starts the SamplingProfiler by triggering SampleRepeatedly.
 
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 Dart VM Service 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_labelDart VM Service 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 11 of file sampling_profiler.cc.

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

◆ ~SamplingProfiler()

flutter::SamplingProfiler::~SamplingProfiler ( )

Definition at line 21 of file sampling_profiler.cc.

21 {
22 if (is_running_) {
23 Stop();
24 }
25}

Member Function Documentation

◆ Start()

void flutter::SamplingProfiler::Start ( )

Starts the SamplingProfiler by triggering SampleRepeatedly.

Definition at line 27 of file sampling_profiler.cc.

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

◆ Stop()

void flutter::SamplingProfiler::Stop ( )

Definition at line 41 of file sampling_profiler.cc.

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

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