52 virtual void set_up(
unsigned num_workers) = 0;
93 task_view {tv}, beg {b} {
101 task_view {tv}, beg {b}, end {e} {
134 inline size_t num_tasks()
const;
138 inline void set_up(
unsigned num_workers)
override final;
139 inline void on_entry(
unsigned worker_id,
TaskView task_view)
override final;
140 inline void on_exit(
unsigned worker_id,
TaskView task_view)
override final;
146 inline void ExecutorObserver::set_up(
unsigned num_workers) {
148 _timeline.executions.resize(num_workers);
150 for(
unsigned w=0; w<num_workers; ++w) {
151 _timeline.executions[w].reserve(1024);
158 inline void ExecutorObserver::on_entry(
unsigned w,
TaskView tv) {
163 inline void ExecutorObserver::on_exit(
unsigned w,
TaskView tv) {
164 static_cast<void>(tv);
165 assert(_timeline.executions[w].size() > 0);
171 for(
size_t w=0; w<_timeline.executions.size(); ++w) {
172 _timeline.executions[w].clear();
181 for(first = 0; first<_timeline.executions.size(); ++first) {
182 if(_timeline.executions[first].size() > 0) {
189 for(
size_t w=first; w<_timeline.executions.size(); w++) {
191 if(w != first && _timeline.executions[w].size() > 0) {
195 for(
size_t i=0; i<_timeline.executions[w].size(); i++) {
198 <<
"\"cat\":\"ExecutorObserver\"," 199 <<
"\"name\":\"" << _timeline.executions[w][i].task_view.name() <<
"\"," 202 <<
"\"tid\":" << w <<
',' 204 _timeline.executions[w][i].beg - _timeline.origin
207 _timeline.executions[w][i].end - _timeline.executions[w][i].beg
210 if(i != _timeline.executions[w].size() - 1) {
230 return std::accumulate(
231 _timeline.executions.begin(), _timeline.executions.end(),
size_t{0},
232 [](
size_t sum,
const auto& exe){
233 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:77
virtual ~ExecutorObserverInterface()=default
virtual destructor
size_t num_tasks() const
get the number of total tasks in the observer
Definition: observer.hpp:229
T duration_cast(T... args)
Definition: taskflow.hpp:5
A constant wrapper class to a task node, mainly used in the tf::ExecutorObserver interface.
Definition: task.hpp:370
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:170
std::string dump() const
dump the timelines in JSON to a std::string
Definition: observer.hpp:222
The executor class to run a taskflow graph.
Definition: executor.hpp:88
The interface class for creating an executor observer.
Definition: observer.hpp:39