tf::ObserverInterface
tf::ChromeObserver
tf::TFProfObserver
taskflow/core/observer.hpp
virtual tf::ObserverInterface::~ObserverInterface
()=default
~ObserverInterface

virtual destructor

void virtual void tf::ObserverInterface::set_up (size_t num_workers)=0 set_up set_up set_up size_t num_workers

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

num_workers

the number of the worker threads in the executor

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

method to call before a worker thread executes a closure

wv

an immutable view of this worker thread

task_view

a constant wrapper object to the task

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

method to call after a worker thread executed a closure

wv

an immutable view of this worker thread

task_view

a constant wrapper object to the task

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:

    structMyObserver:publictf::ObserverInterface{

    MyObserver(conststd::string&name){
    std::cout<<"constructingobserver"<<name<<'\n';
    }

    voidset_up(size_tnum_workers)overridefinal{
    std::cout<<"settingupobserverwith"<<num_workers<<"workers\n";
    }

    voidon_entry(WorkerVieww,tf::TaskViewtv)overridefinal{
    std::ostringstreamoss;
    oss<<"worker"<<w.id()<<"readytorun"<<tv.name()<<'\n';
    std::cout<<oss.str();
    }

    voidon_exit(WorkerVieww,tf::TaskViewtv)overridefinal{
    std::ostringstreamoss;
    oss<<"worker"<<w.id()<<"finishedrunning"<<tv.name()<<'\n';
    std::cout<<oss.str();
    }
    };

    tf::Taskflowtaskflow;
    tf::Executorexecutor;

    //inserttasksintotaskflow
    //...

    //createacustomobserver
    std::shared_ptr<MyObserver>observer=executor.make_observer<MyObserver>("MyObserver");

    //runthetaskflow
    executor.run(taskflow).wait();

tf::ObserverInterface
tf::ChromeObserver
tf::TFProfObserver
- tf::ObserverInterface
  on_entry
- tf::ObserverInterface
  on_exit
- tf::ObserverInterface
  set_up
- tf::ObserverInterface
  ~ObserverInterface