51 virtual void set_up(
unsigned num_workers) = 0;
92 task_view {tv}, beg {b} {
100 task_view {tv}, beg {b}, end {e} {
133 inline size_t num_tasks()
const;
137 inline void set_up(
unsigned num_workers)
override final;
138 inline void on_entry(
unsigned worker_id,
TaskView task_view)
override final;
139 inline void on_exit(
unsigned worker_id,
TaskView task_view)
override final;
145 inline void ExecutorObserver::set_up(
unsigned num_workers) {
147 _timeline.executions.resize(num_workers);
149 for(
unsigned w=0; w<num_workers; ++w) {
150 _timeline.executions[w].reserve(1024);
157 inline void ExecutorObserver::on_entry(
unsigned w,
TaskView tv) {
162 inline void ExecutorObserver::on_exit(
unsigned w,
TaskView tv) {
163 static_cast<void>(tv);
164 assert(_timeline.executions[w].size() > 0);
170 for(
size_t w=0; w<_timeline.executions.size(); ++w) {
171 _timeline.executions[w].clear();
180 for(first = 0; first<_timeline.executions.size(); ++first) {
181 if(_timeline.executions[first].size() > 0) {
188 for(
size_t w=first; w<_timeline.executions.size(); w++) {
190 if(w != first && _timeline.executions[w].size() > 0) {
194 for(
size_t i=0; i<_timeline.executions[w].size(); i++) {
197 <<
"\"cat\":\"ExecutorObserver\"," 198 <<
"\"name\":\"" << _timeline.executions[w][i].task_view.name() <<
"\"," 201 <<
"\"tid\":" << w <<
',' 203 _timeline.executions[w][i].beg - _timeline.origin
206 _timeline.executions[w][i].end - _timeline.executions[w][i].beg
209 if(i != _timeline.executions[w].size() - 1) {
230 _timeline.executions.begin(), _timeline.executions.end(),
size_t{0},
231 [](
size_t sum,
const auto& exe){
232 return sum + exe.size();
virtual void on_entry(unsigned worker_id, TaskView task_view)=0
method to call before a worker thread executes a closure
virtual void set_up(unsigned num_workers)=0
constructor-like method to call when the executor observer is fully created
Default executor observer to dump the execution timelines.
Definition: observer.hpp:76
virtual ~ExecutorObserverInterface()=default
virtual destructor
size_t num_tasks() const
get the number of total tasks in the observer
Definition: observer.hpp:228
T duration_cast(T... args)
Definition: taskflow.hpp:5
an immutable accessor class to a task node, mainly used in the tf::ExecutorObserver interface...
Definition: task.hpp:396
virtual void on_exit(unsigned worker_id, TaskView task_view)=0
method to call after a worker thread executed a closure
void clear()
clear the timeline data
Definition: observer.hpp:169
std::string dump() const
dump the timelines in JSON to a std::string
Definition: observer.hpp:221
The executor class to run a taskflow graph.
Definition: executor.hpp:33
The interface class for creating an executor observer.
Definition: observer.hpp:38