Back to Taskflow

tf::ObserverInterface class

docs/classtf_1_1ObserverInterface.html

4.0.03.8 KB
Original Source

tf::ObserverInterface class

class to derive an executor observer

The tf::ObserverInterface class allows users to define custom methods to monitor the behaviors of an executor. This is particularly useful when you want to inspect the performance of an executor and visualize when each thread participates in the execution of a task. To prevent users from direct access to the internal threads and tasks, tf::ObserverInterface provides immutable wrappers, tf::WorkerView and tf::TaskView, over workers and tasks.

Please refer to tf::WorkerView and tf::TaskView for details.

Example usage:

struct MyObserver : public tf::ObserverInterface {MyObserver(const std::string& name) {std::cout \<\< "constructing observer " \<\< name \<\< '\n';}void set\_up(size\_t num\_workers) override final {std::cout \<\< "setting up observer with " \<\< num\_workers \<\< " workers\n";}void on\_entry(WorkerView w, tf::TaskView tv) override final {std::ostringstream oss;oss \<\< "worker " \<\< w.id() \<\< " ready to run " \<\< tv.name() \<\< '\n';std::cout \<\< oss.str();}void on\_exit(WorkerView w, tf::TaskView tv) override final {std::ostringstream oss;oss \<\< "worker " \<\< w.id() \<\< " finished running " \<\< tv.name() \<\< '\n';std::cout \<\< oss.str();}};tf::Taskflow taskflow;tf::Executor executor;// insert tasks into taskflow// ...// create a custom observerstd::shared\_ptr\<MyObserver\> observer = executor.make\_observer\<MyObserver\>("MyObserver");// run the taskflowexecutor.run(taskflow).wait();

Derived classes

class ChromeObserverclass to create an observer based on Chrome tracing format class TFProfObserverclass to create an observer based on the built-in taskflow profiler format

Constructors, destructors, conversion operators

~ObserverInterface() defaulted virtualvirtual destructor

Public functions

void set_up(size_t num_workers) pure virtualconstructor-like method to call when the executor observer is fully createdvoid on_entry(WorkerView wv, TaskView task_view) pure virtualmethod to call before a worker thread executes a closurevoid on_exit(WorkerView wv, TaskView task_view) pure virtualmethod to call after a worker thread executed a closure

Function documentation

void tf::ObserverInterface::set_up(size_t num_workers) pure virtual

constructor-like method to call when the executor observer is fully created

Parameters
num_workers

void tf::ObserverInterface::on_entry(WorkerView wv, TaskView task_view) pure virtual

method to call before a worker thread executes a closure

Parameters
wv
task_view

void tf::ObserverInterface::on_exit(WorkerView wv, TaskView task_view) pure virtual

method to call after a worker thread executed a closure

Parameters
wv
task_view